From 31280abff63d3a5e4ea7f0e580b1301ce89c2fa4 Mon Sep 17 00:00:00 2001 From: Vinzenz Schroeter Date: Wed, 12 Feb 2025 20:46:34 +0100 Subject: [PATCH] improve cli --- Cargo.toml | 2 +- README.md | 64 +++++++++++++++++++++++++++++++++++++++++++- src/cli.rs | 24 +++++++++++------ src/execute.rs | 8 +++--- src/stream_window.rs | 13 ++++----- 5 files changed, 90 insertions(+), 21 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3aefe3c..7d16ac6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "servicepoint-cli" description = "A command line interface for the ServicePoint display." version = "0.1.0" edition = "2021" -rust-version = "1.78.0" +rust-version = "1.80.0" publish = true resolver = "2" readme = "README.md" diff --git a/README.md b/README.md index f16d4ab..6737862 100644 --- a/README.md +++ b/README.md @@ -31,13 +31,75 @@ cd servicepoint-cli cargo run -- ``` +## Usage + +``` +Usage: servicepoint-cli [OPTIONS] + +Commands: + reset-everything [aliases: r] + pixels [aliases: p] + brightness [aliases: b] + stream [aliases: s] + help Print this message or the help of the given subcommand(s) + +Options: + -d, --destination ip:port of the servicepoint display [default: 127.0.0.1:2342] + -t, --transport protocol to use for communication with display [default: udp] [possible values: udp, web-socket, fake] + -v, --verbose verbose logging + -h, --help Print help + -V, --version Print version +``` + +### Stream + +``` +Usage: servicepoint-cli stream + +Commands: + stdin + screen + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help +``` + +### Brightness + +``` +Usage: servicepoint-cli brightness + +Commands: + reset [aliases: r] + set [aliases: s] + min + max + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help +``` + +Pixels subcommands: +``` +Usage: servicepoint-cli pixels + +Commands: + reset [aliases: r] + help Print this message or the help of the given subcommand(s) + +Options: + -h, --help Print help +``` + ## Contributing If you have ideas on how to improve the code, add features or improve documentation feel free to open a pull request. You think you found a bug? Please open an issue. -Submissions on Forgejo are preferred, but you can also use GitHub. +Submissions on [Forgejo](https://git.berlin.ccc.de/servicepoint/servicepoint-cli) are preferred, but you can also use [GitHub](https://github.com/kaesaecracker/servicepoint-cli). All creatures welcome. diff --git a/src/cli.rs b/src/cli.rs index 2d0bd39..afa61f1 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -38,14 +38,11 @@ pub enum Mode { #[clap(subcommand)] brightness_command: BrightnessCommand, }, - StreamStdin { - #[arg(long, short, default_value_t = false)] - slow: bool, - }, - StreamScreen { - #[command(flatten)] - options: StreamScreenOptions, - }, + #[command(visible_alias = "s")] + Stream { + #[clap(subcommand)] + stream_command: StreamCommand, + } } #[derive(clap::Parser, std::fmt::Debug)] @@ -73,3 +70,14 @@ pub enum Protocol { Fake, } +#[derive(clap::Parser, std::fmt::Debug)] +pub enum StreamCommand { + Stdin { + #[arg(long, short, default_value_t = false)] + slow: bool, + }, + Screen { + #[command(flatten)] + options: StreamScreenOptions, + }, +} diff --git a/src/execute.rs b/src/execute.rs index 90500f1..74f7db4 100644 --- a/src/execute.rs +++ b/src/execute.rs @@ -1,4 +1,4 @@ -use crate::cli::{BrightnessCommand, Mode, PixelCommand}; +use crate::cli::{BrightnessCommand, Mode, PixelCommand, StreamCommand}; use crate::stream_stdin::stream_stdin; use crate::stream_window::stream_window; use log::info; @@ -12,8 +12,10 @@ pub fn execute_mode(mode: Mode, connection: Connection) { } Mode::Pixels { pixel_command } => pixels(&connection, pixel_command), Mode::Brightness { brightness_command } => brightness(&connection, brightness_command), - Mode::StreamStdin { slow } => stream_stdin(&connection, slow), - Mode::StreamScreen { options } => stream_window(&connection, options), + Mode::Stream { stream_command } => match stream_command { + StreamCommand::Stdin { slow } => stream_stdin(&connection, slow), + StreamCommand::Screen { options } => stream_window(&connection, options), + }, } } diff --git a/src/stream_window.rs b/src/stream_window.rs index f109c90..a528281 100644 --- a/src/stream_window.rs +++ b/src/stream_window.rs @@ -2,7 +2,7 @@ use image::{ imageops::{dither, resize, BiLevel, FilterType}, DynamicImage, ImageBuffer, Rgb, Rgba, }; -use log::{debug, error, warn}; +use log::{error, warn}; use scap::{ capturer::{Capturer, Options}, frame::convert_bgra_to_rgb, @@ -11,13 +11,12 @@ use scap::{ use servicepoint::{ Bitmap, Command, CompressionCode, Connection, Origin, FRAME_PACING, PIXEL_HEIGHT, PIXEL_WIDTH, }; -use std::ops::Div; use std::time::Duration; #[derive(clap::Parser, std::fmt::Debug, Clone)] pub struct StreamScreenOptions { - #[arg(long, short, default_value_t = true)] - pub dither: bool, + #[arg(long, short, default_value_t = false)] + pub no_dither: bool, } pub fn stream_window(connection: &Connection, options: StreamScreenOptions) { @@ -38,7 +37,7 @@ pub fn stream_window(connection: &Connection, options: StreamScreenOptions) { FilterType::Nearest, ); - if options.dither { + if !options.no_dither { dither(&mut frame, &BiLevel); } @@ -71,9 +70,7 @@ fn start_capture() -> Option { } let mut capturer = Capturer::build(Options { - fps: FRAME_PACING - .div_duration_f32(Duration::from_secs(1)) - .div(2f32) as u32, + fps: FRAME_PACING.div_duration_f32(Duration::from_secs(1)) as u32, target: None, show_cursor: true, show_highlight: true,