diff --git a/src/lib.rs b/src/lib.rs index 0f802e0..1b669e7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,7 +27,7 @@ pub const LISTENING_SOCKET_ADDR: SocketAddrV4 = type ShutdownSender = mpsc::Sender<()>; -/// Contains the main network and application state for an application session. +/// Contains the main network and backend state for an application session. #[derive(Clone)] pub struct JoecalState { pub device: Device, @@ -48,11 +48,11 @@ impl JoecalState { Ok(Self { device, + client: reqwest::Client::new(), + socket: socket.into(), peers: Default::default(), sessions: Default::default(), running_state: Default::default(), - socket: socket.into(), - client: reqwest::Client::new(), stop_tx: Default::default(), }) } diff --git a/src/main.rs b/src/main.rs index 8f9ccd6..36fbf7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,6 +59,14 @@ async fn main() -> error::Result<()> { struct App { state: JoecalState, rstate: RunningState, + screen: CurrentScreen, +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum CurrentScreen { + Main, + Sending, + Receiving, } impl App { @@ -66,6 +74,7 @@ impl App { App { state: state.clone(), rstate: *state.running_state.lock().await, + screen: CurrentScreen::Main, } } @@ -101,8 +110,8 @@ impl App { async fn handle_key_event(&mut self, key_event: KeyEvent) { match key_event.code { KeyCode::Char('q') => self.exit().await, - KeyCode::Char('s') => {} - KeyCode::Char('r') => {} + KeyCode::Char('s') => self.send().await, + KeyCode::Char('r') => self.recv().await, KeyCode::Char('d') => {} _ => {} } @@ -111,6 +120,14 @@ impl App { async fn exit(&self) { self.state.stop().await; } + + async fn send(&mut self) { + self.screen = CurrentScreen::Sending; + } + + async fn recv(&mut self) { + self.screen = CurrentScreen::Receiving; + } } impl Widget for &App { @@ -131,7 +148,7 @@ impl Widget for &App { .title_bottom(instructions.centered()) .border_set(border::THICK); - let rs = format!("{:?}", self.rstate); + let rs = format!("{:?}", self.screen); let state_text = Text::from(vec![Line::from(vec!["runstate: ".into(), rs.yellow()])]); Paragraph::new(state_text)