summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKlara Modin <klarasmodin@gmail.com>2022-06-20 20:14:25 +0200
committerKlara Modin <klarasmodin@gmail.com>2022-06-20 20:24:54 +0200
commit55239cb09d27bc77553dc0f243f655896b64b03a (patch)
tree5c41ad9be268226e65cdc5ea7b15d09f7fff2b1c
parent9b0d10dc4ad544b406a2258bdb7f9c3aef13c33e (diff)
elminate some unnecessary muts
-rw-r--r--src/ui.rs31
1 files changed, 14 insertions, 17 deletions
diff --git a/src/ui.rs b/src/ui.rs
index 4c470b5..458b3d8 100644
--- a/src/ui.rs
+++ b/src/ui.rs
@@ -40,11 +40,15 @@ impl UI {
endwin();
}
+ fn getmaxyx_tup() -> (i32, i32) {
+ let (mut y, mut x) = (0, 0);
+ getmaxyx(stdscr(), &mut y, &mut x);
+ (y, x)
+ }
+
pub fn nick(&mut self, nick: &str) {
self.nick = format!("[{}] ", nick);
- let mut max_x = 0;
- let mut max_y = 0;
- getmaxyx(stdscr(), &mut max_y, &mut max_x);
+ let (max_y, max_x) = UI::getmaxyx_tup();
mv(max_y-1, 0);
deleteln();
printw(&self.nick);
@@ -69,9 +73,7 @@ impl UI {
}
pub fn put_str(&mut self, text: &str) {
- let mut max_x = 0;
- let mut max_y = 0;
- getmaxyx(stdscr(), &mut max_y, &mut max_x);
+ let (max_y, max_x) = UI::getmaxyx_tup();
if self.output_y >= max_y-1 {
self.scroll(1);
@@ -94,9 +96,7 @@ impl UI {
}
pub fn read_line(&mut self) -> Option<String> {
- let mut max_x = 0;
- let mut max_y = 0;
- getmaxyx(stdscr(), &mut max_y, &mut max_x);
+ let (max_y, max_x) = UI::getmaxyx_tup();
mv(max_y-1, 0);
deleteln();
printw(&self.nick);
@@ -110,16 +110,13 @@ impl UI {
printw(chars.as_str());
}
if let Some(line) = self.getstr_unblocking() {
- let mut save = false;
- if line != "" {
+ let save = if line != "" {
if let Some(prev) = self.history.last() {
if prev != &line {
- save = true;
- }
- } else {
- save = true;
- }
- }
+ true
+ } else { false }
+ } else { true }
+ } else { false };
if save {
self.history.push(line.clone());
self.history_place = -1;