summaryrefslogtreecommitdiff
path: root/src/client
diff options
context:
space:
mode:
authortom barrett <spalf0@gmail.com>2018-06-07 08:30:35 -0500
committertom barrett <spalf0@gmail.com>2018-06-07 08:30:35 -0500
commit11b51897dda7609b5a22a490bfb8cd2c269b5969 (patch)
tree2df89c71305de020e1f8a59d7fdfbf18979387a5 /src/client
parente70f4e4a41a0acf7ef812220113dff703280f75a (diff)
-added crude refinery methods
Diffstat (limited to 'src/client')
-rw-r--r--src/client/mod.rs1
-rw-r--r--src/client/refinery.rs50
2 files changed, 51 insertions, 0 deletions
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<TcpStream>) {
+ 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();
+ }
+}