diff --git a/Cargo.toml b/Cargo.toml index d5ea2ac..b99a329 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ colog = "1.3.0" env_logger = "0.11.5" log = { version = "0.4.22", features = ["serde", "std", "release_max_level_debug", "max_level_debug"] } rand = { version = "0.8.5", features = ["small_rng"] } +color-eyre = "0.6.3" [[bin]] name = "rusty_midicommander" diff --git a/src/cli.rs b/src/cli.rs index 07c094a..5d6eb36 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -28,8 +28,8 @@ pub enum SubCommands { Create(CreateArgs), /// Launch the program as a cli Launch(CLIArgs), - // /// Launch the program as a TUI - // TUI(TUIArgs), + /// Launch the program as a TUI + TUI(TUIArgs), } /// The bulk of the cli arguments, able to be launch and reloaded from a config file. @@ -53,6 +53,13 @@ pub struct CLIArgs { // pub vp: Vec, } +#[derive(Debug, Parser, Serialize, Deserialize, Clone)] +/// List of very important commands +pub struct TUIArgs { + #[arg(short)] + pub bob: usize, +} + /// All arguments for creating a VP configuration #[derive(Debug, Parser, Serialize, Deserialize)] pub struct CreateArgs { diff --git a/src/dispatch.rs b/src/dispatch.rs index a04e128..c67c28a 100644 --- a/src/dispatch.rs +++ b/src/dispatch.rs @@ -6,9 +6,17 @@ use std::{ fs::create_dir, process::exit, sync::{Arc, Mutex}, + time::Duration, }; use rand::{rngs::SmallRng, Rng, SeedableRng}; +use ratatui::{ + crossterm::event::{self, Event, KeyCode}, + layout::{Constraint, Layout}, + style::Color, + widgets::{Block, Paragraph}, + Frame, +}; use crate::{ cli::{self, CreateArgs}, @@ -32,6 +40,51 @@ pub fn create_config(create_args: CreateArgs) -> Result<(), RustyMidiError> { Ok(()) } +/// Launch the program as a cli +pub fn tui_launch(ruiargs: cli::TUIArgs) -> Result<(), RustyMidiError> { + let _ = ruiargs; + color_eyre::install().unwrap(); + let should_quit = Arc::new(Mutex::new(false)); + let mut terminal = ratatui::init(); + loop { + terminal.draw(|v| draw_frame(v).inspect_err(|e| panic!("{}", e)).unwrap())?; + + let timeout = Duration::from_millis(16); + if event::poll(timeout)? { + if let Event::Key(key) = event::read()? { + match key.code { + KeyCode::Char('q') | KeyCode::Esc => *should_quit.lock().unwrap() = true, + _ => (), + } + // Things happen here + }; + if *should_quit.lock().unwrap() { + break; + } + } + } + ratatui::restore(); + Ok(()) +} + +/// Draw the main frame +fn draw_frame(frame: &mut Frame) -> Result<(), RustyMidiError> { + let [_, spaced, _] = Layout::horizontal([ + Constraint::Min(7), + Constraint::Percentage(100), + Constraint::Min(7), + ]) + .areas(frame.area()); + + frame.render_widget( + Paragraph::new("bob") + .block(Block::bordered().title("eduardo")) + .style(Color::DarkGray), + spaced, + ); + Ok(()) +} + // TODO: Upgrade /// Launch the program as a cli pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> { @@ -41,6 +94,7 @@ pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> { exit(1); } + #[allow(deprecated)] let proj = Arc::new(Mutex::new(projector::panasonic::PanasonicProjector::new( "127.0.0.1:8080", "admin1", diff --git a/src/lib.rs b/src/lib.rs index ee9bc3b..074c9c8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ pub mod error; pub mod midi; pub mod projector; -pub use dispatch::{cli_launch, create_config}; +pub use dispatch::{cli_launch, create_config, tui_launch}; pub use error::RustyMidiError; /// Basic logging setup diff --git a/src/main.rs b/src/main.rs index 940e173..a91a165 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ #![warn(clippy::missing_docs_in_private_items)] -use rmc_lib::{cli_launch, create_config, init_logger}; +use rmc_lib::{cli_launch, create_config, init_logger, tui_launch}; use std::process::exit; use clap::Parser; @@ -30,6 +30,7 @@ fn main_dispatch(args: cli::RMCArgs) { let _ = match args.command { cli::SubCommands::Create(create_args) => create_config(create_args), cli::SubCommands::Launch(cliargs) => cli_launch(cliargs), + cli::SubCommands::TUI(tuiargs) => tui_launch(tuiargs), } .inspect_err(|e| { println!( diff --git a/src/projector/panasonic.rs b/src/projector/panasonic.rs index ec0c83d..5fe807a 100644 --- a/src/projector/panasonic.rs +++ b/src/projector/panasonic.rs @@ -90,6 +90,7 @@ impl PanasonicProjector { } /// The request to the the osd + #[allow(dead_code)] fn get_osd(&self) -> Result { let headers = self.make_auth_header(); let url = format!("http://{}/cgi-bin/get_osd.cgi?lang=e", self.ip);