diff --git a/src/main.rs b/src/main.rs index 006ba3a..119691e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -100,12 +100,12 @@ impl From<&str> for IO { } } -struct Ws { - cons: Option>, +struct Websocket { + cons: Option>, hb: Instant, } -impl Actor for Ws { +impl Actor for Websocket { type Context = ws::WebsocketContext; fn started(&mut self, ctx: &mut Self::Context) { @@ -113,7 +113,7 @@ impl Actor for Ws { self.hb(ctx); // Start PTY - self.cons = Some(Cons::new(ctx.address()).start()); + self.cons = Some(Terminal::new(ctx.address()).start()); trace!("Started WebSocket"); } @@ -129,20 +129,20 @@ impl Actor for Ws { } } -impl Handler for Ws { +impl Handler for Websocket { type Result = (); fn handle(&mut self, msg: IO, ctx: &mut ::Context) { - trace!("Ws <- Cons : {:?}", msg); + trace!("Websocket <- Terminal : {:?}", msg); ctx.binary(msg); } } -impl Handler for Ws { +impl Handler for Websocket { type Result = (); fn handle(&mut self, msg: TerminadoMessage, ctx: &mut ::Context) { - trace!("Ws <- Cons : {:?}", msg); + trace!("Websocket <- Terminal : {:?}", msg); match msg { TerminadoMessage::Stdout(_) => { let json = serde_json::to_string(&msg); @@ -156,7 +156,7 @@ impl Handler for Ws { } } -impl Ws { +impl Websocket { pub fn new() -> Self { Self { hb: Instant::now(), @@ -181,12 +181,12 @@ fn index(_req: &HttpRequest) -> Result { Ok(NamedFile::open("static/term.html")?) } -impl StreamHandler for Ws { +impl StreamHandler for Websocket { fn handle(&mut self, msg: ws::Message, ctx: &mut Self::Context) { - let cons: &mut Addr = match self.cons { + let cons: &mut Addr = match self.cons { Some(ref mut c) => c, None => { - error!("Console died, closing websocket."); + error!("Terminalole died, closing websocket."); ctx.stop(); return; } @@ -213,14 +213,14 @@ impl StreamHandler for Ws { } } -struct Cons { +struct Terminal { pty_write: Option, child: Option, - ws: Addr, + ws: Addr, } -impl Cons { - pub fn new(ws: Addr) -> Self { +impl Terminal { + pub fn new(ws: Addr) -> Self { Self { pty_write: None, child: None, @@ -229,17 +229,17 @@ impl Cons { } } -impl StreamHandler<::Item, ::Error> for Cons { +impl StreamHandler<::Item, ::Error> for Terminal { fn handle(&mut self, msg: ::Item, _ctx: &mut Self::Context) { self.ws.do_send(TerminadoMessage::Stdout(IO(msg))); } } -impl Actor for Cons { +impl Actor for Terminal { type Context = Context; fn started(&mut self, ctx: &mut Self::Context) { - info!("Started Cons"); + info!("Started Terminal"); let pty = match AsyncPtyMaster::open() { Err(e) => { error!("Unable to open PTY: {:?}", e); @@ -269,7 +269,7 @@ impl Actor for Cons { } fn stopping(&mut self, _ctx: &mut Self::Context) -> Running { - info!("Stopping Cons"); + info!("Stopping Terminal"); let child = self.child.take(); @@ -292,18 +292,18 @@ impl Actor for Cons { } fn stopped(&mut self, _ctx: &mut Self::Context) { - info!("Stopped Cons"); + info!("Stopped Terminal"); } } -impl Handler for Cons { +impl Handler for Terminal { type Result = (); fn handle(&mut self, msg: IO, ctx: &mut ::Context) { let pty = match self.pty_write { Some(ref mut p) => p, None => { - error!("Write half of PTY died, stopping Cons."); + error!("Write half of PTY died, stopping Terminal."); ctx.stop(); return; } @@ -314,7 +314,7 @@ impl Handler for Cons { ctx.stop(); } - trace!("Ws -> Cons : {:?}", msg); + trace!("Websocket -> Terminal : {:?}", msg); } } @@ -333,20 +333,20 @@ impl Future for Resize { } } -impl Handler for Cons { +impl Handler for Terminal { type Result = (); fn handle(&mut self, msg: TerminadoMessage, ctx: &mut ::Context) { let pty = match self.pty_write { Some(ref mut p) => p, None => { - error!("Write half of PTY died, stopping Cons."); + error!("Write half of PTY died, stopping Terminal."); ctx.stop(); return; } }; - trace!("Ws -> Cons : {:?}", msg); + trace!("Websocket -> Terminal : {:?}", msg); match msg { TerminadoMessage::Stdin(io) => { if let Err(e) = pty.write(io.as_ref()) { @@ -379,7 +379,7 @@ fn main() { .unwrap() .show_files_listing(), ) - .resource("/websocket", |r| r.f(|req| ws::start(req, Ws::new()))) + .resource("/websocket", |r| r.f(|req| ws::start(req, Websocket::new()))) .resource("/", |r| r.f(index)) }) .bind("127.0.0.1:8080")