Fix command_bar example warnings (#204)

This commit is contained in:
Zrzka 2019-09-12 12:33:37 +02:00 committed by Timon
parent b1daeccab0
commit 1de4555ec7

View File

@ -1,16 +1,16 @@
extern crate crossterm; extern crate crossterm;
use crossterm::{ use crossterm::{
cursor, input, terminal, AlternateScreen, ClearType, Crossterm, InputEvent, KeyEvent, cursor, input, terminal, ClearType, Crossterm, InputEvent, KeyEvent, RawScreen, Terminal,
RawScreen, Terminal, TerminalCursor, TerminalCursor,
}; };
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::{thread, time}; use std::{thread, time};
fn main() { fn main() {
let screen = RawScreen::into_raw_mode(); let _screen = RawScreen::into_raw_mode();
cursor().hide(); cursor().hide().expect("Couldn't hide cursor");
let input_buf = Arc::new(Mutex::new(String::new())); let input_buf = Arc::new(Mutex::new(String::new()));
@ -37,13 +37,14 @@ fn main() {
count += 1; count += 1;
} }
}) })
.join(); .join()
.expect("Couldn't join");
for thread in threads { for thread in threads {
thread.join(); thread.join().expect("Couldn't join");
} }
cursor().show(); cursor().show().expect("Couldn't show cursor");
} }
fn log(input_buf: Arc<Mutex<String>>) -> Vec<thread::JoinHandle<()>> { fn log(input_buf: Arc<Mutex<String>>) -> Vec<thread::JoinHandle<()>> {
@ -85,8 +86,14 @@ pub fn swap_write(
cursor: &TerminalCursor, cursor: &TerminalCursor,
term_height: u16, term_height: u16,
) { ) {
cursor.goto(0, term_height); cursor.goto(0, term_height).expect("Couldn't goto");
terminal.clear(ClearType::CurrentLine); terminal
terminal.write(format!("{}\r\n", msg)); .clear(ClearType::CurrentLine)
terminal.write(format!("> {}", input_buf)); .expect("Couldn't clear current line");
terminal
.write(format!("{}\r\n", msg))
.expect("Couldn't write message");
terminal
.write(format!("> {}", input_buf))
.expect("Couldn't write prompt");
} }