diff options
author | Klara Modin <klarasmodin@gmail.com> | 2022-06-20 21:26:26 +0200 |
---|---|---|
committer | Klara Modin <klarasmodin@gmail.com> | 2022-06-20 21:26:26 +0200 |
commit | 0da2a16afb65c08c5232ef730d44ec319cecd216 (patch) | |
tree | 23a513745451e9aba10c25f9075fd0c8facf8cdd | |
parent | 6196fcf61a59127620f2d2c352a1a9b945c51ef9 (diff) |
fix getsr_unblocking being blocking...
-rw-r--r-- | src/ui.rs | 99 |
1 files changed, 49 insertions, 50 deletions
@@ -132,59 +132,58 @@ impl UI { } fn getstr_unblocking(&mut self) -> Option<String> { - loop { - let input = getch(); - if let Some(ch) = char::from_u32(input as u32) { - match ch { - '\n' => { - deleteln(); - mv(self.input_y, self.input_x); - let ret = self.buffer.clone(); - self.buffer.clear(); - return Some(ret); - }, - '\x7f' => { - self.buffer.pop(); - mv(self.input_y, self.input_x); - printw(&self.buffer); - let (new_y, new_x) = UI::getyx_tup(); - printw(" "); - mv(new_y, new_x); - } - _ => { - self.buffer.push(ch); - }, - } - } else { - match input { - KEY_UP => { - if self.history_place < 0 { - self.history_place = self.history.len() as i32; - } - self.history_place -= 1; - if self.history_place < 0 { - self.history_place = self.history.len() as i32; - } - if let Some(history) = self.history.get(self.history_place as usize) { - self.buffer = history.clone(); - } - }, - KEY_DOWN => { - if self.history_place < 0 { - self.history_place = self.history.len() as i32 - 1; - } - self.history_place += 1; - if self.history_place >= self.history.len() as i32 { - self.history_place = self.history.len() as i32 - 1; - } - if let Some(history) = self.history.get(self.history_place as usize) { - self.buffer = history.clone(); - } - }, - _ => {}, + let input = getch(); + if let Some(ch) = char::from_u32(input as u32) { + match ch { + '\n' => { + deleteln(); + mv(self.input_y, self.input_x); + let ret = self.buffer.clone(); + self.buffer.clear(); + return Some(ret); + }, + '\x7f' => { + self.buffer.pop(); + mv(self.input_y, self.input_x); + printw(&self.buffer); + let (new_y, new_x) = UI::getyx_tup(); + printw(" "); + mv(new_y, new_x); } + _ => { + self.buffer.push(ch); + }, + } + } else { + match input { + KEY_UP => { + if self.history_place < 0 { + self.history_place = self.history.len() as i32; + } + self.history_place -= 1; + if self.history_place < 0 { + self.history_place = self.history.len() as i32; + } + if let Some(history) = self.history.get(self.history_place as usize) { + self.buffer = history.clone(); + } + }, + KEY_DOWN => { + if self.history_place < 0 { + self.history_place = self.history.len() as i32 - 1; + } + self.history_place += 1; + if self.history_place >= self.history.len() as i32 { + self.history_place = self.history.len() as i32 - 1; + } + if let Some(history) = self.history.get(self.history_place as usize) { + self.buffer = history.clone(); + } + }, + _ => {}, } } + None } pub fn print_message(&mut self, message: &Message) { |