mirror of
https://github.com/xvxx/phetch
synced 2024-11-15 00:12:50 +00:00
show cursor on exit
This commit is contained in:
parent
7e91d35639
commit
85bf3dcdd1
18
src/ui.rs
18
src/ui.rs
@ -14,6 +14,7 @@ pub struct UI {
|
|||||||
pages: Vec<Box<dyn View>>,
|
pages: Vec<Box<dyn View>>,
|
||||||
page: usize,
|
page: usize,
|
||||||
dirty: bool, // redraw?
|
dirty: bool, // redraw?
|
||||||
|
running: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -40,11 +41,12 @@ impl UI {
|
|||||||
pages: vec![],
|
pages: vec![],
|
||||||
page: 0,
|
page: 0,
|
||||||
dirty: true,
|
dirty: true,
|
||||||
|
running: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
loop {
|
while self.running {
|
||||||
self.draw();
|
self.draw();
|
||||||
self.update();
|
self.update();
|
||||||
}
|
}
|
||||||
@ -52,8 +54,8 @@ impl UI {
|
|||||||
|
|
||||||
pub fn draw(&mut self) {
|
pub fn draw(&mut self) {
|
||||||
if self.dirty {
|
if self.dirty {
|
||||||
let prefix = ""; // debug
|
// let prefix = ""; // debug
|
||||||
let prefix = "\x1b[2J\x1b[H"; // clear the screen
|
let prefix = "\x1b[2J\x1b[H\x1b[?25l"; // clear screen + hide cursor
|
||||||
print!("{}{}", prefix, self.render());
|
print!("{}{}", prefix, self.render());
|
||||||
self.dirty = false;
|
self.dirty = false;
|
||||||
}
|
}
|
||||||
@ -61,7 +63,7 @@ impl UI {
|
|||||||
|
|
||||||
pub fn update(&mut self) {
|
pub fn update(&mut self) {
|
||||||
match self.process_input() {
|
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 (typ, host, port, sel) = gopher::parse_url(url);
|
||||||
let response = gopher::fetch(host, port, sel)
|
let response = gopher::fetch(host, port, sel)
|
||||||
.map_err(|e| {
|
.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);
|
std::process::exit(1);
|
||||||
})
|
})
|
||||||
.unwrap();
|
.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) {
|
fn copy_to_clipboard(data: &str) {
|
||||||
let mut child = spawn_os_clipboard();
|
let mut child = spawn_os_clipboard();
|
||||||
let child_stdin = child.stdin.as_mut().unwrap();
|
let child_stdin = child.stdin.as_mut().unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user