Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add framerate cli option #36

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,10 +89,12 @@ FLAGS:
-v, --verbose Enable verbose insights for the curious.

OPTIONS:
-b, --bg <bg> Background color when decors are used [default: white] [possible values: white, black,
transparent]
-d, --decor <decor> Decorates the animation with certain, mostly border effects. [default: shadow] [possible
values: shadow, none]
-b, --bg <bg> Background color when decors are used [default: white] [possible values: white, black,
transparent]
-f, --framerate <framerate> If you want to capture at a different framerate you can pass it here. For example
'10' [default: 4]
-d, --decor <decor> Decorates the animation with certain, mostly border effects. [default: shadow] [possible
values: shadow, none]

ARGS:
<shell or program to launch> If you want to start a different program than $SHELL you can pass it here. For
Expand Down
10 changes: 10 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
19 changes: 17 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ fn main() -> Result<()> {

let force_natural = args.is_present("natural-mode");

let framerate = args
.value_of("capture-framerate")
.unwrap()
.parse::<u32>()
.context("Invalid value for framerate")?;

check_for_imagemagick()?;

// the nice thing is the cleanup on drop
Expand All @@ -87,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)
capture_thread(
&rx,
api,
win_id,
time_codes,
tempdir,
force_natural,
framerate,
)
})
};
let interact = thread::spawn(move || -> Result<()> { sub_shell_thread(&program).map(|_| ()) });
Expand Down Expand Up @@ -166,8 +180,9 @@ fn capture_thread(
time_codes: Arc<Mutex<Vec<u128>>>,
tempdir: Arc<Mutex<TempDir>>,
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<ImageOnHeap> = None;
Expand Down