diff --git a/candid_tui/Cargo.toml b/candid_tui/Cargo.toml index 2f3d323..cd0ba2b 100644 --- a/candid_tui/Cargo.toml +++ b/candid_tui/Cargo.toml @@ -12,7 +12,7 @@ keywords = ["CAN", "SocketCAN"] publish = false [dependencies] -candid_client = "0.3" +candid_client = "0.3.2" clap = "^2.32" tui = "0.5" termion = "^1.5" diff --git a/candid_tui/src/app.rs b/candid_tui/src/app.rs index 9c12ade..b9881fa 100644 --- a/candid_tui/src/app.rs +++ b/candid_tui/src/app.rs @@ -1,6 +1,6 @@ //! Module for maintaining app state -use crate::util::ListState; +use crate::util::{FrameInfo, ListState}; use candid_client::*; @@ -16,7 +16,7 @@ pub struct AppState<'a> { pub server: CandidConnection, /// The frames that have been received from the server to this point - pub frame_history: ListState<&'a str>, + pub frame_history: ListState, } impl<'a> AppState<'a> { diff --git a/candid_tui/src/event.rs b/candid_tui/src/event.rs index d69792e..340ee1c 100644 --- a/candid_tui/src/event.rs +++ b/candid_tui/src/event.rs @@ -5,17 +5,19 @@ //! All code in this module is *heavily* inspired by [`tui-rs`'s demo //! code](https://github.com/fdehau/tui-rs/blob/master/examples/util/event.rs) -use crate::frame::Frame; +use crate::util::FrameInfo; use std::sync::mpsc; use std::{io, thread}; +use candid_client::Frame; + use termion::event::Key; use termion::input::TermRead; pub enum Event { Input(I), - Frame(Frame), + Frame(FrameInfo), } /// An event handler that wraps termion input and tick events. @@ -64,7 +66,10 @@ impl Events { let _frame_handle = { let tx = tx.clone(); thread::spawn(move || loop { - tx.send(Event::Frame(Frame { msg: "A frame" })).unwrap(); + let frame = Frame::new(0, [0 as u8; 8]); + let frame = FrameInfo(frame, format!("{:?}", frame).to_string()); + + tx.send(Event::Frame(frame)).unwrap(); thread::sleep(std::time::Duration::from_millis(1000)); }) }; diff --git a/candid_tui/src/frame.rs b/candid_tui/src/frame.rs deleted file mode 100644 index e518b20..0000000 --- a/candid_tui/src/frame.rs +++ /dev/null @@ -1,3 +0,0 @@ -pub struct Frame { - pub msg: &'static str, -} diff --git a/candid_tui/src/lib.rs b/candid_tui/src/lib.rs index 6a0e163..a188e6b 100644 --- a/candid_tui/src/lib.rs +++ b/candid_tui/src/lib.rs @@ -1,6 +1,5 @@ pub mod app; pub mod event; -pub mod frame; pub mod ui; pub mod util; diff --git a/candid_tui/src/main.rs b/candid_tui/src/main.rs index 9e17b60..fa13344 100644 --- a/candid_tui/src/main.rs +++ b/candid_tui/src/main.rs @@ -1,9 +1,3 @@ -/* -use candid_tui::app::AppState; -use candid_tui::event::{Event, Events}; -use candid_tui::ui; -*/ - use candid_tui::*; use candid_client::*; @@ -46,11 +40,6 @@ fn main() { // Initialize the app state let mut app = AppState::new("CANdid TUI", server); - app.frame_history.push("frame 1"); // Placeholder frames for now - app.frame_history.push("frame 2"); - app.frame_history.push("frame 3"); - app.frame_history.push("frame 4"); - app.frame_history.push("frame 5"); // Initialize the event aggregator let events = Events::new(); @@ -67,7 +56,7 @@ fn main() { Key::Down => app.on_down(), _ => {} }, - Event::Frame(frame) => app.frame_history.push(frame.msg), + Event::Frame(frame) => app.frame_history.push(frame), } // Exit if necessary, set in app.on_key(q) diff --git a/candid_tui/src/util.rs b/candid_tui/src/util.rs index 481e934..d549f16 100644 --- a/candid_tui/src/util.rs +++ b/candid_tui/src/util.rs @@ -1,3 +1,5 @@ +use candid_client::Frame; + /// Keeps track of the position in a list, ued for SelectableLists pub struct ListState { pub items: Vec, @@ -32,3 +34,13 @@ impl ListState { } } } + +/// Holds the Frame and its string representation +pub struct FrameInfo(pub Frame, pub String); + +impl AsRef for FrameInfo { + /// Allows the FrameInfo to be used in a SelectableList + fn as_ref(&self) -> &str { + &self.1 + } +}