This commit is contained in:
TimonPost 2018-08-24 18:49:25 +02:00
parent 308cc743d1
commit 9102108b3a
3 changed files with 4 additions and 8 deletions

View File

@ -20,7 +20,6 @@ fn main() {
let threads = log(input_buf.clone(),&screen); let threads = log(input_buf.clone(),&screen);
let mut count = 0; let mut count = 0;
thread::spawn(move || { thread::spawn(move || {
@ -35,13 +34,9 @@ fn main() {
Some(Ok(13)) => Some(Ok(13)) =>
{ {
input_buf.lock().unwrap().clear(); input_buf.lock().unwrap().clear();
// need to start receiving again because if pressed enter then async reading will stop
// stdin = input.read_async().bytes();
} }
Some(Ok(val)) => Some(Ok(val)) =>
{ {
// println!("{:?}",a);
input_buf.lock().unwrap().push(a.unwrap().unwrap() as char); input_buf.lock().unwrap().push(a.unwrap().unwrap() as char);
} }
_ => {} _ => {}
@ -72,7 +67,7 @@ fn log(input_buf: Arc<Mutex<String>>, screen: &Screen) -> Vec<thread::JoinHandle
let input_buffer = input_buf.clone(); let input_buffer = input_buf.clone();
let clone_stdout = screen.stdout.clone(); let clone_stdout = screen.stdout.clone();
let crossterm = Crossterm::new(screen.stdout.clone()); let crossterm = Crossterm::from(screen.stdout.clone());
let join = thread::spawn( move || { let join = thread::spawn( move || {
let cursor = crossterm.cursor(); let cursor = crossterm.cursor();

View File

@ -51,7 +51,7 @@ fn main() {
map.spawn_food(&free_positions, &screen); map.spawn_food(&free_positions, &screen);
loop { loop {
thread::sleep(time::Duration::from_millis(500)); thread::sleep(time::Duration::from_millis(200));
let pressed_key = stdin.next(); let pressed_key = stdin.next();
if let Some(Ok(key)) = pressed_key { if let Some(Ok(key)) = pressed_key {
@ -96,6 +96,7 @@ fn title_screen() -> Size
println!("Enter map width:"); println!("Enter map width:");
cursor.goto(17, 15); cursor.goto(17, 15);
let width = crossterm.input().read_line().unwrap(); let width = crossterm.input().read_line().unwrap();
cursor.goto(0, 16);
println!("Enter map height:"); println!("Enter map height:");
cursor.goto(17, 16); cursor.goto(17, 16);
let height = crossterm.input().read_line().unwrap(); let height = crossterm.input().read_line().unwrap();

View File

@ -79,7 +79,7 @@ impl RawModeCommand
{ {
pub fn new() -> Self { pub fn new() -> Self {
RawModeCommand { RawModeCommand {
mask: ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT, mask: ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT | ENABLE_ECHO_INPUT | ENABLE_PROCESSED_OUTPUT ,
} }
} }
} }