From db7ec0a00096a0ba70cb630a7852bf6751e3ce4c Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 9 Dec 2021 16:58:28 -0500 Subject: clean up the drawing code a bit --- src/history.rs | 28 ++++++++++------------------ src/readline.rs | 6 +++--- src/state.rs | 2 +- 3 files changed, 14 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/history.rs b/src/history.rs index 7e8a836..6c31b10 100644 --- a/src/history.rs +++ b/src/history.rs @@ -59,11 +59,7 @@ impl History { } if let Some((pos, hide)) = cursor { out.move_to(pos.0, pos.1); - if hide { - out.write(b"\x1b[?25l"); - } else { - out.write(b"\x1b[?25h"); - } + out.hide_cursor(hide); } Ok(()) } @@ -239,22 +235,22 @@ impl HistoryEntry { out.reset_attributes(); if self.binary() { - let msg = b"This appears to be binary data. Fullscreen this entry to view anyway."; + let msg = "This appears to be binary data. Fullscreen this entry to view anyway."; let len: u16 = msg.len().try_into().unwrap(); out.move_to( out.screen().cursor_position().0 + 1, (width - len) / 2, ); out.set_fgcolor(textmode::color::RED); - out.write(msg); - out.write(b"\x1b[?25l"); + out.write_str(msg); + out.hide_cursor(true); out.reset_attributes(); } else { let last_row = self.lines(width, focused && !scrolling); if last_row > 5 { out.write(b"\r\n"); out.set_fgcolor(textmode::color::BLUE); - out.write(b"..."); + out.write_str("..."); out.reset_attributes(); } let mut out_row = out.screen().cursor_position().0 + 1; @@ -269,9 +265,9 @@ impl HistoryEntry { .skip(last_row.saturating_sub(5)) { let idx: u16 = idx.try_into().unwrap(); - out.write(b"\x1b[m"); + out.reset_attributes(); if !wrapped { - out.write(format!("\x1b[{}H", out_row + 1).as_bytes()); + out.move_to(out_row, 0); } out.write(&row); wrapped = screen.row_wrapped(idx); @@ -282,14 +278,10 @@ impl HistoryEntry { } if focused && !scrolling { if let Some(row) = cursor_found { - if screen.hide_cursor() { - out.write(b"\x1b[?25l"); - } else { - out.write(b"\x1b[?25h"); - out.move_to(row, pos.1); - } + out.hide_cursor(screen.hide_cursor()); + out.move_to(row, pos.1); } else { - out.write(b"\x1b[?25l"); + out.hide_cursor(true); } } } diff --git a/src/readline.rs b/src/readline.rs index aef817a..38c1e51 100644 --- a/src/readline.rs +++ b/src/readline.rs @@ -83,9 +83,9 @@ impl Readline { out.move_to(self.size.0 - 2, 0); out.set_bgcolor(textmode::Color::Rgb(32, 32, 64)); out.write(b"\x1b[K"); - out.write(b" ("); + out.write_str(" ("); out.write_str(&pwd); - out.write(b")"); + out.write_str(")"); out.move_to(self.size.0 - 2, self.size.1 - 4 - idlen - timelen); out.write_str(&id); out.write_str(" ["); @@ -107,7 +107,7 @@ impl Readline { out.reset_attributes(); out.move_to(self.size.0 - 1, self.prompt_width() + self.pos_width()); if focus { - out.write(b"\x1b[?25h"); + out.hide_cursor(false); } Ok(()) } diff --git a/src/state.rs b/src/state.rs index 38c4a3c..49e8320 100644 --- a/src/state.rs +++ b/src/state.rs @@ -175,7 +175,7 @@ impl State { self.readline .render(out, idx.is_none(), self.offset) .await?; - out.write(b"\x1b[?25l"); + out.hide_cursor(true); } }, Scene::Fullscreen => { -- cgit v1.2.3-54-g00ecf