summaryrefslogtreecommitdiff
path: root/src/ui.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui.rs')
-rw-r--r--src/ui.rs47
1 files changed, 33 insertions, 14 deletions
diff --git a/src/ui.rs b/src/ui.rs
index e189ff0..b7ac5a9 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -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;
},
}
}