From 85bf3dcdd1656d17767d5e2d84374a34821cc6fe Mon Sep 17 00:00:00 2001 From: dvkt Date: Tue, 17 Dec 2019 01:03:20 -0800 Subject: [PATCH] show cursor on exit --- src/ui.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/ui.rs b/src/ui.rs index a0fa34b..d69c919 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -14,6 +14,7 @@ pub struct UI { pages: Vec>, page: usize, dirty: bool, // redraw? + running: bool, } #[derive(Debug)] @@ -40,11 +41,12 @@ impl UI { pages: vec![], page: 0, dirty: true, + running: true, } } pub fn run(&mut self) { - loop { + while self.running { self.draw(); self.update(); } @@ -52,8 +54,8 @@ impl UI { pub fn draw(&mut self) { if self.dirty { - let prefix = ""; // debug - let prefix = "\x1b[2J\x1b[H"; // clear the screen + // let prefix = ""; // debug + let prefix = "\x1b[2J\x1b[H\x1b[?25l"; // clear screen + hide cursor print!("{}{}", prefix, self.render()); self.dirty = false; } @@ -61,7 +63,7 @@ impl UI { pub fn update(&mut self) { match self.process_input() { - Action::Quit => std::process::exit(1), + Action::Quit => self.running = false, _ => {} } } @@ -81,7 +83,7 @@ impl UI { let (typ, host, port, sel) = gopher::parse_url(url); let response = gopher::fetch(host, port, sel) .map_err(|e| { - eprintln!("\x1B[91merror loading \x1b[93m{}: \x1B[0m{}", url, e); + eprintln!("\x1B[91merror loading \x1b[93m{}: \x1B[0m{}[?25h", url, e); // TODO std::process::exit(1); }) .unwrap(); @@ -161,6 +163,12 @@ impl UI { } } +impl Drop for UI { + fn drop(&mut self) { + print!("\x1b[?25h"); // show cursor + } +} + fn copy_to_clipboard(data: &str) { let mut child = spawn_os_clipboard(); let child_stdin = child.stdin.as_mut().unwrap();