restructure cli

This commit is contained in:
Vinzenz Schroeter 2025-03-02 14:09:04 +01:00
parent 0ac6b77ed0
commit 11d9ac0bcb
6 changed files with 100 additions and 88 deletions

View file

@ -40,10 +40,10 @@ pub enum Mode {
#[clap(subcommand)]
brightness_command: BrightnessCommand,
},
#[command(visible_alias = "s")]
Stream {
#[command(visible_alias = "t")]
Text {
#[clap(subcommand)]
stream_command: StreamCommand,
text_command: TextCommand,
},
}
@ -71,6 +71,18 @@ pub enum PixelCommand {
#[command(flatten)]
image_processing_options: ImageProcessingOptions,
},
#[command(
visible_alias = "s",
about = "Stream the default screen capture source to the display. \
On Linux Wayland, this pops up a screen or window chooser, \
but it also may directly start streaming your main screen."
)]
Screen {
#[command(flatten)]
stream_options: StreamScreenOptions,
#[command(flatten)]
image_processing: ImageProcessingOptions,
},
}
#[derive(clap::Parser, std::fmt::Debug)]
@ -99,8 +111,8 @@ pub enum Protocol {
}
#[derive(clap::Parser, std::fmt::Debug)]
#[clap(about = "Continuously send data to the display")]
pub enum StreamCommand {
#[clap(about = "Commands for sending text to the screen")]
pub enum TextCommand {
#[command(
about = "Pipe text to the display, example: `journalctl | servicepoint-cli stream stdin`"
)]
@ -113,15 +125,6 @@ pub enum StreamCommand {
)]
slow: bool,
},
#[command(about = "Stream the default source to the display. \
On Linux Wayland, this pops up a screen or window chooser, \
but it also may directly start streaming your main screen.")]
Screen {
#[command(flatten)]
stream_options: StreamScreenOptions,
#[command(flatten)]
image_processing: ImageProcessingOptions,
},
}
#[derive(clap::Parser, std::fmt::Debug, Clone)]

View file

@ -1,9 +1,8 @@
use crate::{
brightness::{brightness, brightness_set},
cli::{Cli, Mode, Protocol, StreamCommand},
cli::{Cli, Mode, Protocol},
pixels::{pixels, pixels_off},
stream_stdin::stream_stdin,
stream_window::stream_window,
text::text
};
use clap::Parser;
use log::debug;
@ -16,6 +15,7 @@ mod ledwand_dither;
mod pixels;
mod stream_stdin;
mod stream_window;
mod text;
fn main() {
let cli = Cli::parse();
@ -36,13 +36,7 @@ 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::Stream { stream_command } => match stream_command {
StreamCommand::Stdin { slow } => stream_stdin(connection, slow),
StreamCommand::Screen {
stream_options,
image_processing,
} => stream_window(&connection, stream_options, image_processing),
},
Mode::Text { text_command} => text(&connection, text_command),
}
}

View file

@ -1,5 +1,8 @@
use crate::cli::{ImageProcessingOptions, PixelCommand, SendImageOptions};
use crate::image_processing::ImageProcessingPipeline;
use crate::{
image_processing::ImageProcessingPipeline,
cli::{ImageProcessingOptions, PixelCommand, SendImageOptions},
stream_window::stream_window
};
use log::info;
use servicepoint::{BitVec, Command, CompressionCode, Connection, Origin, PIXEL_COUNT};
@ -12,6 +15,10 @@ pub(crate) fn pixels(connection: &Connection, pixel_command: PixelCommand) {
image_processing_options: processing_options,
send_image_options: image_options,
} => pixels_image(connection, image_options, processing_options),
PixelCommand::Screen {
stream_options,
image_processing,
} => stream_window(connection, stream_options, image_processing),
}
}

View file

@ -2,7 +2,7 @@ use log::warn;
use servicepoint::*;
use std::thread::sleep;
pub(crate) fn stream_stdin(connection: Connection, slow: bool) {
pub(crate) fn stream_stdin(connection: &Connection, slow: bool) {
warn!("This mode will break when using multi-byte characters and does not support ANSI escape sequences yet.");
let mut app = App {
connection,
@ -13,14 +13,14 @@ pub(crate) fn stream_stdin(connection: Connection, slow: bool) {
app.run()
}
struct App {
connection: Connection,
struct App<'t> {
connection: &'t Connection,
mirror: CharGrid,
y: usize,
slow: bool,
}
impl App {
impl App<'_> {
fn run(&mut self) {
self.connection
.send(Command::Clear)

7
src/text.rs Normal file
View file

@ -0,0 +1,7 @@
use servicepoint::Connection;
use crate::cli::TextCommand;
use crate::stream_stdin::stream_stdin;
pub fn text(connection: &Connection, command: TextCommand) {
match command { TextCommand::Stdin { slow } => stream_stdin(connection, slow), }
}