diff options
-rw-r--r-- | src/ui.rs | 47 | ||||
-rw-r--r-- | src/user_int.rs | 12 |
2 files changed, 45 insertions, 14 deletions
@@ -48,6 +48,22 @@ impl UI { getyx(stdscr(), &mut self.input_y, &mut self.input_x); } + pub fn chan(&mut self, chan: &str) { + let mut x = 0; + let mut y = 0; + getyx(stdscr(), &mut y, &mut x); + mv(0, 0); + for i in 0..self.chan.len() { + printw(" "); + } + + self.chan = chan.to_string(); + + mv(0, 0); + printw(chan); + mv(y, x); + } + pub fn put_str(&mut self, text: &str) { let mut max_x = 0; let mut max_y = 0; @@ -70,7 +86,15 @@ impl UI { getmaxyx(stdscr(), &mut max_y, &mut max_x); mv(max_y-1, 0); printw(&self.nick); - printw(&self.buffer); + getyx(stdscr(), &mut self.input_y, &mut self.input_x); + { + let mut chars = self.buffer.chars(); + while chars.as_str().len() > max_x as usize - self.nick.len() { + chars.next(); + } + mv(max_y-1, self.input_x); + printw(chars.as_str()); + } self.getstr_unblocking() } @@ -82,29 +106,24 @@ impl UI { let ch = wch as u8 as char; match ch { '\n' => { - self.input_x = new_x; - self.input_y = new_y; deleteln(); - mv(new_y, new_x); - printw(&self.nick); + mv(self.input_y, self.input_x); let ret = self.buffer.clone(); self.buffer.clear(); return Some(ret); }, '\x7f' => { self.buffer.pop(); - if self.input_x > new_x { - self.input_x -= 1; - deleteln(); - mv(new_y, 0); - printw(&self.nick); - printw(&self.buffer); - } + mv(self.input_y, self.input_x); + printw(&self.buffer); + let mut new_x = 0; + let mut new_y = 0; + getyx(stdscr(), &mut new_y, &mut new_x); + printw(" "); + mv(new_y, new_x); } _ => { self.buffer.push(ch); - //self.buffer.push_str((&format!("{:output_x}", ch as i32))); - self.input_x += 1; }, } } diff --git a/src/user_int.rs b/src/user_int.rs index 4b6f4c8..71349e9 100644 --- a/src/user_int.rs +++ b/src/user_int.rs @@ -127,15 +127,27 @@ impl Session { }, "BUFFER" => { self.chan = m.params.get(0).unwrap_or(&String::new()).clone(); + if let Some(ref ui) = self.ui { + let mut ui = ui.lock().unwrap(); + ui.chan(&self.chan); + } None }, "JOIN" => { self.chan = m.params.get(0).unwrap_or(&String::new()).clone(); + if let Some(ref ui) = self.ui { + let mut ui = ui.lock().unwrap(); + ui.chan(&self.chan); + } Some(m) }, "PART" => { m.params.push(self.chan.clone()); self.chan = String::new(); + if let Some(ref ui) = self.ui { + let mut ui = ui.lock().unwrap(); + ui.chan(&self.chan); + } Some(m) }, "QUOTE" => { |