Compare commits

...
This repository has been archived on 2026-09-13. You can view files and clone it, but cannot push or open issues or pull requests.

2 Commits

Author SHA1 Message Date
Dandaedre 08424817ee Working enough TUI 2024-12-09 13:03:06 +01:00
Dandaedre cbbea4dcd8 More cli work 2024-12-09 12:28:30 +01:00
8 changed files with 97 additions and 23 deletions

2
.gitignore vendored
View File

@ -25,3 +25,5 @@ tarpaulin-report.html
test/ test/
.ignore .ignore
*.json *.json
config/
vp/

View File

@ -22,6 +22,8 @@ enum-map = { version = "2.7.3", features = ["serde"] }
colog = "1.3.0" colog = "1.3.0"
env_logger = "0.11.5" env_logger = "0.11.5"
log = { version = "0.4.22", features = ["serde", "std", "release_max_level_debug", "max_level_debug"] } 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]] [[bin]]
name = "rusty_midicommander" name = "rusty_midicommander"

View File

@ -28,8 +28,8 @@ pub enum SubCommands {
Create(CreateArgs), Create(CreateArgs),
/// Launch the program as a cli /// Launch the program as a cli
Launch(CLIArgs), Launch(CLIArgs),
// /// Launch the program as a TUI /// Launch the program as a TUI
// TUI(TUIArgs), TUI(TUIArgs),
} }
/// The bulk of the cli arguments, able to be launch and reloaded from a config file. /// The bulk of the cli arguments, able to be launch and reloaded from a config file.
@ -48,9 +48,16 @@ pub struct CLIArgs {
/// Create a config file from all the given arguments /// Create a config file from all the given arguments
#[arg(short, long)] #[arg(short, long)]
pub save: Option<String>, pub save: Option<String>,
//
// /// Connect to a VP // /// Connect to a VP
// pub vp: Option<Vec<VPType>>, // #[command(subcommand)]
// pub vp: Vec<VPType>,
}
#[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 /// All arguments for creating a VP configuration
@ -58,14 +65,12 @@ pub struct CLIArgs {
pub struct CreateArgs { pub struct CreateArgs {
/// Create a projector config file of a specific type /// Create a projector config file of a specific type
#[command(subcommand)] #[command(subcommand)]
pub create: Option<VPType>, pub create: VPType,
}
// impl From<OsStr> for VPType { /// The name to save it under
// fn from(value: OsStr) -> Self { #[arg(short, long)]
// todo!() pub name: Option<String>,
// } }
// }
/// Get a parsed Args from the Cli, this function will also perform the basic (save/load) and printing needed /// Get a parsed Args from the Cli, this function will also perform the basic (save/load) and printing needed
pub fn get_arguments_from_cli() -> Result<RMCArgs, RustyMidiError> { pub fn get_arguments_from_cli() -> Result<RMCArgs, RustyMidiError> {

View File

@ -3,8 +3,19 @@
//! Contains all functionnalities the CLI expects //! Contains all functionnalities the CLI expects
use std::{ use std::{
fs::create_dir,
process::exit, process::exit,
sync::{Arc, Mutex}, 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::{ use crate::{
@ -16,24 +27,74 @@ use crate::{
/// Execute all config creation action /// Execute all config creation action
pub fn create_config(create_args: CreateArgs) -> Result<(), RustyMidiError> { pub fn create_config(create_args: CreateArgs) -> Result<(), RustyMidiError> {
create_args.create.into_iter().for_each(|vp| { let mut small_rng = SmallRng::from_entropy();
let _ = new_default_projector_of_type(&vp) let _ = create_dir("vp");
.inspect_err(|e| println!("Couldn't save the projector {:?} {}", vp, e)); let vp = create_args.create;
}); let name = create_args.name.unwrap_or(format!(
"vp/{:?}_new_{}.json",
vp,
small_rng.gen_range(255..2048),
));
let _ = new_default_projector_of_type(&vp, &name)
.inspect_err(|e| println!("Couldn't save the projector {:?} {}", vp, e));
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(()) Ok(())
} }
// TODO: Upgrade // TODO: Upgrade
/// Launch the program as a cli /// Launch the program as a cli
pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> { pub fn cli_launch(cliargs: cli::CLIArgs) -> Result<(), RustyMidiError> {
println!("{:?}", cliargs);
// TODO: Cleanup all the following // TODO: Cleanup all the following
if cliargs.midi_interface.is_none() { if cliargs.midi_interface.is_none() {
midi::print_midi_interfaces(); midi::print_midi_interfaces();
exit(1); exit(1);
} }
println!("{:?}", cliargs); #[allow(deprecated)]
let proj = Arc::new(Mutex::new(projector::panasonic::PanasonicProjector::new( let proj = Arc::new(Mutex::new(projector::panasonic::PanasonicProjector::new(
"127.0.0.1:8080", "127.0.0.1:8080",
"admin1", "admin1",

View File

@ -13,7 +13,7 @@ pub mod error;
pub mod midi; pub mod midi;
pub mod projector; pub mod projector;
pub use dispatch::{cli_launch, create_config}; pub use dispatch::{cli_launch, create_config, tui_launch};
pub use error::RustyMidiError; pub use error::RustyMidiError;
/// Basic logging setup /// Basic logging setup

View File

@ -5,7 +5,7 @@
#![warn(clippy::missing_docs_in_private_items)] #![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 std::process::exit;
use clap::Parser; use clap::Parser;
@ -30,6 +30,7 @@ fn main_dispatch(args: cli::RMCArgs) {
let _ = match args.command { let _ = match args.command {
cli::SubCommands::Create(create_args) => create_config(create_args), cli::SubCommands::Create(create_args) => create_config(create_args),
cli::SubCommands::Launch(cliargs) => cli_launch(cliargs), cli::SubCommands::Launch(cliargs) => cli_launch(cliargs),
cli::SubCommands::TUI(tuiargs) => tui_launch(tuiargs),
} }
.inspect_err(|e| { .inspect_err(|e| {
println!( println!(

View File

@ -11,16 +11,18 @@ use serde::{Deserialize, Serialize};
/// Enumerate all the VP types /// Enumerate all the VP types
#[derive(Parser, Serialize, Deserialize, Clone, Debug)] #[derive(Parser, Serialize, Deserialize, Clone, Debug)]
pub enum VPType { pub enum VPType {
/// A panasonic VideoProjector
Panasonic, Panasonic,
} }
/// Create a new empty projector of the given type /// Create a new empty projector of the given type
/// ///
/// While inelegant, this is the most straightforward way of having a generic projector /// While inelegant, this is the most straightforward way of having a generic projector
pub fn new_default_projector_of_type(vptype: &VPType) -> Result<(), crate::RustyMidiError> { pub fn new_default_projector_of_type(
vptype: &VPType,
name: &str,
) -> Result<(), crate::RustyMidiError> {
match vptype { match vptype {
VPType::Panasonic => { VPType::Panasonic => PanasonicProjector::default().create_default_config_file(name),
PanasonicProjector::default().create_default_config_file("new_panasonic.json")
}
} }
} }

View File

@ -90,6 +90,7 @@ impl PanasonicProjector {
} }
/// The request to the the osd /// The request to the the osd
#[allow(dead_code)]
fn get_osd(&self) -> Result<String, RustyMidiError> { fn get_osd(&self) -> Result<String, RustyMidiError> {
let headers = self.make_auth_header(); let headers = self.make_auth_header();
let url = format!("http://{}/cgi-bin/get_osd.cgi?lang=e", self.ip); let url = format!("http://{}/cgi-bin/get_osd.cgi?lang=e", self.ip);