aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2019-10-08 12:23:23 -0400
committerJesse Luehrs <doy@tozt.net>2019-10-08 12:23:23 -0400
commitd0eb3fde4d93e9ebe6b0a416d1c2ec0848e0dcbd (patch)
tree0d4a85e9d3cc3bc6d02f8f9b1b4774ace1e76f9b
parent4a0fe969983d60070e3ef499f99c39fb7d60e32e (diff)
downloadteleterm-d0eb3fde4d93e9ebe6b0a416d1c2ec0848e0dcbd.tar.gz
teleterm-d0eb3fde4d93e9ebe6b0a416d1c2ec0848e0dcbd.zip
display a basic loading message while disconnected, and make q work
-rw-r--r--src/cmd/watch.rs84
1 files changed, 50 insertions, 34 deletions
diff --git a/src/cmd/watch.rs b/src/cmd/watch.rs
index fc8df6d..a4a5301 100644
--- a/src/cmd/watch.rs
+++ b/src/cmd/watch.rs
@@ -209,13 +209,30 @@ impl WatchSession {
list_client,
state: State::new(),
raw_screen: None,
- needs_redraw: false,
+ needs_redraw: true,
})
}
fn reconnect(&mut self) {
self.state.logging_in();
self.list_client.reconnect();
+ self.needs_redraw = true;
+ }
+
+ fn loading_keypress(
+ &mut self,
+ e: &crossterm::InputEvent,
+ ) -> Result<bool> {
+ #[allow(clippy::single_match)]
+ match e {
+ crossterm::InputEvent::Keyboard(crossterm::KeyEvent::Char(
+ 'q',
+ )) => {
+ return Ok(true);
+ }
+ _ => {}
+ }
+ Ok(false)
}
fn list_server_message(
@@ -332,7 +349,7 @@ impl WatchSession {
Ok(())
}
- fn watch_keypress(&mut self, e: &crossterm::InputEvent) -> Result<()> {
+ fn watch_keypress(&mut self, e: &crossterm::InputEvent) -> Result<bool> {
#[allow(clippy::single_match)]
match e {
crossterm::InputEvent::Keyboard(crossterm::KeyEvent::Char(
@@ -342,7 +359,7 @@ impl WatchSession {
}
_ => {}
}
- Ok(())
+ Ok(false)
}
fn resize(&mut self) -> Result<()> {
@@ -355,7 +372,9 @@ impl WatchSession {
fn redraw(&self) -> Result<()> {
match &self.state {
State::Temporary => unreachable!(),
- State::LoggingIn { .. } => {}
+ State::LoggingIn { .. } => {
+ self.display_loading_message()?;
+ }
State::Choosing { sessions, .. } => {
sessions.print().context(SessionList)?;
}
@@ -363,6 +382,18 @@ impl WatchSession {
}
Ok(())
}
+
+ fn display_loading_message(&self) -> Result<()> {
+ crossterm::terminal()
+ .clear(crossterm::ClearType::All)
+ .context(WriteTerminalCrossterm)?;
+ let data = b"loading...\r\n(q to quit)";
+ let stdout = std::io::stdout();
+ let mut stdout = stdout.lock();
+ stdout.write(data).context(WriteTerminal)?;
+ stdout.flush().context(FlushTerminal)?;
+ Ok(())
+ }
}
impl WatchSession {
@@ -377,38 +408,23 @@ impl WatchSession {
];
fn poll_input(&mut self) -> Result<crate::component_future::Poll<()>> {
- match &mut self.state {
- State::Temporary => unreachable!(),
- State::LoggingIn { .. } => {
- Ok(crate::component_future::Poll::NothingToDo)
- }
- State::Choosing { .. } => {
- match self.key_reader.poll().context(ReadKey)? {
- futures::Async::Ready(Some(e)) => {
- let quit = self.list_keypress(&e)?;
- if quit {
- Ok(crate::component_future::Poll::Event(()))
- } else {
- Ok(crate::component_future::Poll::DidWork)
- }
- }
- futures::Async::Ready(None) => unreachable!(),
- futures::Async::NotReady => {
- Ok(crate::component_future::Poll::NotReady)
- }
+ match self.key_reader.poll().context(ReadKey)? {
+ futures::Async::Ready(Some(e)) => {
+ let quit = match &mut self.state {
+ State::Temporary => unreachable!(),
+ State::LoggingIn { .. } => self.loading_keypress(&e)?,
+ State::Choosing { .. } => self.list_keypress(&e)?,
+ State::Watching { .. } => self.watch_keypress(&e)?,
+ };
+ if quit {
+ Ok(crate::component_future::Poll::Event(()))
+ } else {
+ Ok(crate::component_future::Poll::DidWork)
}
}
- State::Watching { .. } => {
- match self.key_reader.poll().context(ReadKey)? {
- futures::Async::Ready(Some(e)) => {
- self.watch_keypress(&e)?;
- Ok(crate::component_future::Poll::DidWork)
- }
- futures::Async::Ready(None) => unreachable!(),
- futures::Async::NotReady => {
- Ok(crate::component_future::Poll::NotReady)
- }
- }
+ futures::Async::Ready(None) => unreachable!(),
+ futures::Async::NotReady => {
+ Ok(crate::component_future::Poll::NotReady)
}
}
}