From 11b51897dda7609b5a22a490bfb8cd2c269b5969 Mon Sep 17 00:00:00 2001 From: tom barrett Date: Thu, 7 Jun 2018 08:30:35 -0500 Subject: -added crude refinery methods --- src/client/mod.rs | 1 + src/client/refinery.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 src/client/refinery.rs (limited to 'src/client') diff --git a/src/client/mod.rs b/src/client/mod.rs index baabf96..8bb0eca 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1,4 +1,5 @@ pub mod mining; pub mod engines; +pub mod refinery; pub mod dashboard; pub mod navigation; diff --git a/src/client/refinery.rs b/src/client/refinery.rs new file mode 100644 index 0000000..4f437df --- /dev/null +++ b/src/client/refinery.rs @@ -0,0 +1,50 @@ +extern crate termion; +extern crate serde_json; + +use std::net::TcpStream; +use self::termion::async_stdin; +use std::io::{BufRead, BufReader}; +use std::io::{stdout, Read, Write}; +use self::termion::raw::IntoRawMode; + +use server::refinery::RefineryData; + +pub fn client_refinery(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(); + + loop { + let mut recv = String::new(); + buff_r.read_line(&mut recv).unwrap(); + let data : RefineryData = serde_json::from_str(&recv.replace("\n", "")).unwrap(); + + write!(stdout, "{}", termion::clear::All).unwrap(); + + let clear = termion::cursor::Goto(1,1); + + match data.has_minerals { + true => match data.status { + true => write!(stdout, "{}Press R to stop refining.", clear).unwrap(), + false => write!(stdout, "{}Press R to begin refining.", clear).unwrap(), + }, + false => write!(stdout, "{}You have no refinable minerals.", clear).unwrap(), + } + + match stdin.next() { + Some(c) => { + let c = c.unwrap(); + let mut send = String::new(); + send.push(c as char); + if send.as_bytes() == b"q" { + break; + } + send.push_str("\n"); + stream.write(send.as_bytes()).unwrap(); + } + None => () + } + + stdout.flush().unwrap(); + } +} -- cgit v1.2.3