summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlara Modin <klarasmodin@gmail.com>2022-06-20 21:26:26 +0200
committerKlara Modin <klarasmodin@gmail.com>2022-06-20 21:26:26 +0200
commit0da2a16afb65c08c5232ef730d44ec319cecd216 (patch)
tree23a513745451e9aba10c25f9075fd0c8facf8cdd
parent6196fcf61a59127620f2d2c352a1a9b945c51ef9 (diff)
fix getsr_unblocking being blocking...
-rw-r--r--src/ui.rs99
1 files changed, 49 insertions, 50 deletions
diff --git a/src/ui.rs b/src/ui.rs
index 0a0b254..26e7dcd 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -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) {