From 859d25a139f3f4679a2ff7596ecd0569435249d6 Mon Sep 17 00:00:00 2001 From: Chris Yealy Date: Fri, 1 Jan 2021 20:19:24 -0500 Subject: [PATCH 1/2] Add framerate cli option --- README.md | 12 +++++++----- src/cli.rs | 10 ++++++++++ src/main.rs | 7 +++++-- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 818de71..babf4aa 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Blazingly fast terminal recorder that generates animated gif images for the web ![demo](./docs/demo.gif) ## Features -- Screenshotting your terminal with 4 frames per second (every 250ms) +- Screenshotting your terminal with 4 frames per second (every 250ms, but this is configurable) - Generates high quality small sized animated gif images - **Build-In idle frames detection and optimization** (for super fluid presentations) - Applies (can be disabled) border decor effects like drop shadow @@ -89,10 +89,12 @@ FLAGS: -v, --verbose Enable verbose insights for the curious. OPTIONS: - -b, --bg Background color when decors are used [default: white] [possible values: white, black, - transparent] - -d, --decor Decorates the animation with certain, mostly border effects. [default: shadow] [possible - values: shadow, none] + -b, --bg Background color when decors are used [default: white] [possible values: white, black, + transparent] + -f, --framerate If you want to capture at a different framerate you can pass it here. For example + '10' [default: 4] + -d, --decor Decorates the animation with certain, mostly border effects. [default: shadow] [possible + values: shadow, none] ARGS: If you want to start a different program than $SHELL you can pass it here. For diff --git a/src/cli.rs b/src/cli.rs index 95af31c..baef64a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -43,6 +43,16 @@ pub fn launch<'a>() -> ArgMatches<'a> { .long("natural") .help("If you want a very natural typing experience and disable the idle detection and sampling optimization") ) + .arg( + Arg::with_name("capture-framerate") + .value_name("framerate") + .takes_value(true) + .required(false) + .short("f") + .long("framerate") + .default_value("4") + .help("If you want to capture at a different framerate you can pass it here. For example '10'"), + ) .arg( Arg::with_name("list-windows") .value_name("list all visible windows with name and id") diff --git a/src/main.rs b/src/main.rs index 6019388..8a29eb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,6 +74,8 @@ fn main() -> Result<()> { let force_natural = args.is_present("natural-mode"); + let framerate = args.value_of("capture-framerate").unwrap().parse::().context("Invalid value for framerate")?; + check_for_imagemagick()?; // the nice thing is the cleanup on drop @@ -87,7 +89,7 @@ fn main() -> Result<()> { let time_codes = time_codes.clone(); let force_natural = force_natural; thread::spawn(move || -> Result<()> { - capture_thread(&rx, api, win_id, time_codes, tempdir, force_natural) + capture_thread(&rx, api, win_id, time_codes, tempdir, force_natural, framerate) }) }; let interact = thread::spawn(move || -> Result<()> { sub_shell_thread(&program).map(|_| ()) }); @@ -166,8 +168,9 @@ fn capture_thread( time_codes: Arc>>, tempdir: Arc>, force_natural: bool, + framerate: u32, ) -> Result<()> { - let duration = Duration::from_millis(250); + let duration = Duration::from_secs(1) / framerate; let start = Instant::now(); let mut idle_duration = Duration::from_millis(0); let mut last_frame: Option = None; From bb38ae6240a618d2dd44d065437dc702491c2c1d Mon Sep 17 00:00:00 2001 From: Chris Yealy Date: Fri, 1 Jan 2021 20:31:14 -0500 Subject: [PATCH 2/2] Run 'cargo fmt' --- src/main.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8a29eb2..c6890c2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,7 +74,11 @@ fn main() -> Result<()> { let force_natural = args.is_present("natural-mode"); - let framerate = args.value_of("capture-framerate").unwrap().parse::().context("Invalid value for framerate")?; + let framerate = args + .value_of("capture-framerate") + .unwrap() + .parse::() + .context("Invalid value for framerate")?; check_for_imagemagick()?; @@ -89,7 +93,15 @@ fn main() -> Result<()> { let time_codes = time_codes.clone(); let force_natural = force_natural; thread::spawn(move || -> Result<()> { - capture_thread(&rx, api, win_id, time_codes, tempdir, force_natural, framerate) + capture_thread( + &rx, + api, + win_id, + time_codes, + tempdir, + force_natural, + framerate, + ) }) }; let interact = thread::spawn(move || -> Result<()> { sub_shell_thread(&program).map(|_| ()) });