summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlara Modin <kasm@kasm.eu>2018-05-17 01:28:14 +0200
committerKlara Modin <kasm@kasm.eu>2018-05-17 01:28:14 +0200
commitaa6692ebf9d78e7663da7c730d960cb77d6aa0f2 (patch)
tree99388281b817a3a52183ca8fec6e7251b61cc8bb
parentcdb97a48f6d8e4aafcef2cc58147db9c83c78481 (diff)
implement linebreak in put_str if line gets to long
-rw-r--r--src/ui.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/ui.rs b/src/ui.rs
index b7ac5a9..730c136 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -69,14 +69,23 @@ impl UI {
let mut max_y = 0;
getmaxyx(stdscr(), &mut max_y, &mut max_x);
- if self.output_y >= max_y-1 {
- mv(1, 0);
- deleteln();
- self.output_y-=1;
- mv(self.output_y, 0);
+ let mut chars = text.chars();
+ while let Some(ch) = chars.next() {
+ if self.output_x >= max_x {
+ self.output_x = 0;
+ self.output_y += 1;
+ }
+ if self.output_y >= max_y-1 {
+ mv(1, 0);
+ deleteln();
+ self.output_y-=1;
+ mv(self.output_y, 0);
+ }
+ mv(self.output_y, self.output_x);
+ printw(&ch.to_string());
+ self.output_x += 1;
}
- printw(text);
getyx(stdscr(), &mut self.output_y, &mut self.output_x);
}
@@ -85,6 +94,7 @@ impl UI {
let mut max_y = 0;
getmaxyx(stdscr(), &mut max_y, &mut max_x);
mv(max_y-1, 0);
+ deleteln();
printw(&self.nick);
getyx(stdscr(), &mut self.input_y, &mut self.input_x);
{