From 46fa862e04bc43311ba79ef3db70abf9014b9104 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Sun, 3 Feb 2019 05:45:35 -0600 Subject: bringing to 2018 --- src/client/engines.rs | 38 +++++++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 11 deletions(-) (limited to 'src/client/engines.rs') diff --git a/src/client/engines.rs b/src/client/engines.rs index 9b2d314..8f83998 100644 --- a/src/client/engines.rs +++ b/src/client/engines.rs @@ -1,15 +1,15 @@ -extern crate termion; extern crate serde_json; +extern crate termion; -use std::thread::sleep; -use std::time::Duration; -use std::net::TcpStream; use self::termion::async_stdin; -use std::io::{BufRead, BufReader}; -use std::io::{Read, Write, stdout}; use self::termion::raw::IntoRawMode; +use std::io::{stdout, Read, Write}; +use std::io::{BufRead, BufReader}; +use std::net::TcpStream; +use std::thread::sleep; +use std::time::Duration; -pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader) { +pub fn client_engines(mut stream: TcpStream, mut buff_r: BufReader) { let stdout = stdout(); let mut stdout = stdout.lock().into_raw_mode().unwrap(); let mut stdin = async_stdin().bytes(); @@ -19,15 +19,31 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader) buff_r.read_line(&mut recv).unwrap(); let has_target = serde_json::from_str(&recv.replace("\n", "")).unwrap(); - write!(stdout, "{}{}use numpad to freely move\n", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap(); + writeln!( + stdout, + "{}{}use numpad to freely move", + termion::clear::All, + termion::cursor::Goto(1, 1) + ) + .unwrap(); write!(stdout, "{}+ : speedup", termion::cursor::Goto(1, 2)).unwrap(); write!(stdout, "{}- : slowdown", termion::cursor::Goto(1, 3)).unwrap(); write!(stdout, "{}s : stop", termion::cursor::Goto(1, 4)).unwrap(); write!(stdout, "{}q : quit", termion::cursor::Goto(1, 5)).unwrap(); if has_target { - write!(stdout, "{}c : mimic targets velocity vector", termion::cursor::Goto(1, 6)).unwrap(); - write!(stdout, "{}t : accelerate torwards target", termion::cursor::Goto(1, 7)).unwrap(); + write!( + stdout, + "{}c : mimic targets velocity vector", + termion::cursor::Goto(1, 6) + ) + .unwrap(); + write!( + stdout, + "{}t : accelerate torwards target", + termion::cursor::Goto(1, 7) + ) + .unwrap(); } if let Some(c) = stdin.next() { @@ -38,7 +54,7 @@ pub fn client_engines(mut stream : TcpStream, mut buff_r : BufReader) break; } send.push_str("\n"); - stream.write(send.as_bytes()).unwrap(); + stream.write_all(send.as_bytes()).unwrap(); } stdout.flush().unwrap(); -- cgit v1.2.3