improve cli
Some checks failed
Rust / build (push) Failing after 1m11s

This commit is contained in:
Vinzenz Schroeter 2025-02-12 20:46:34 +01:00
parent ef19ab8b3f
commit 83baf7b419
5 changed files with 90 additions and 21 deletions

View file

@ -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,
},
}

View file

@ -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),
},
}
}

View file

@ -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<Capturer> {
}
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,