diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-11-06 15:21:41 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-11-06 15:21:41 -0500 |
commit | b143853814276e2cf6f6211bcd6e09877164aec4 (patch) | |
tree | b402794edf2d90c7eedb3f8eb5c08f188aac8606 /src | |
parent | 480b9f9324bfcae611dd01ee8e793515e57c0e26 (diff) | |
download | teleterm-b143853814276e2cf6f6211bcd6e09877164aec4.tar.gz teleterm-b143853814276e2cf6f6211bcd6e09877164aec4.zip |
default to starting the player paused
this should make the help text for the keybindings more discoverable
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd/play.rs | 14 | ||||
-rw-r--r-- | src/config.rs | 12 |
2 files changed, 23 insertions, 3 deletions
diff --git a/src/cmd/play.rs b/src/cmd/play.rs index c6fec4b..cd78f36 100644 --- a/src/cmd/play.rs +++ b/src/cmd/play.rs @@ -28,6 +28,7 @@ impl crate::config::Config for Config { { Box::new(PlaySession::new( &self.ttyrec.filename, + self.play.play_at_start, self.play.playback_ratio, self.play.max_frame_length, )) @@ -106,18 +107,20 @@ struct Player { impl Player { fn new( + play_at_start: bool, playback_ratio: f32, max_frame_length: Option<std::time::Duration>, ) -> Self { + let now = std::time::Instant::now(); Self { playback_ratio, max_frame_length, ttyrec: Ttyrec::new(), idx: 0, timer: None, - base_time: std::time::Instant::now(), + base_time: now, played_amount: std::time::Duration::default(), - paused: None, + paused: if play_at_start { None } else { Some(now) }, } } @@ -268,6 +271,7 @@ struct PlaySession { impl PlaySession { fn new( filename: &str, + play_at_start: bool, playback_ratio: f32, max_frame_length: Option<std::time::Duration>, ) -> Self { @@ -275,7 +279,11 @@ impl PlaySession { file: FileState::Closed { filename: filename.to_string(), }, - player: Player::new(playback_ratio, max_frame_length), + player: Player::new( + play_at_start, + playback_ratio, + max_frame_length, + ), raw_screen: None, alternate_screen: None, key_reader: crate::key_reader::KeyReader::new(), diff --git a/src/config.rs b/src/config.rs index 0387fa8..a33022b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,6 +17,7 @@ const LISTEN_ADDRESS_OPTION: &str = "listen-address"; const LOGIN_PLAIN_OPTION: &str = "login-plain"; const LOGIN_RECURSE_CENTER_OPTION: &str = "login-recurse-center"; const MAX_FRAME_LENGTH_OPTION: &str = "max-frame-length"; +const PLAY_AT_START_OPTION: &str = "play-at-start"; const PLAYBACK_RATIO_OPTION: &str = "playback-ratio"; const READ_TIMEOUT_OPTION: &str = "read-timeout-secs"; const TLS_IDENTITY_FILE_OPTION: &str = "tls-identity-file"; @@ -699,6 +700,9 @@ fn default_ttyrec_filename() -> String { #[derive(serde::Deserialize, Debug)] pub struct Play { + #[serde(default)] + pub play_at_start: bool, + #[serde(default = "default_playback_ratio")] pub playback_ratio: f32, @@ -708,11 +712,17 @@ pub struct Play { impl Play { pub fn cmd<'a, 'b>(app: clap::App<'a, 'b>) -> clap::App<'a, 'b> { + let play_at_start_help = "Start the player unpaused"; let playback_ratio_help = "Speed to play back the ttyrec at (defaults to 1.0)"; let max_frame_length_help = "Clamp frame duration at this number of seconds"; app.arg( + clap::Arg::with_name(PLAY_AT_START_OPTION) + .long(PLAY_AT_START_OPTION) + .help(play_at_start_help), + ) + .arg( clap::Arg::with_name(PLAYBACK_RATIO_OPTION) .long(PLAYBACK_RATIO_OPTION) .takes_value(true) @@ -732,6 +742,7 @@ impl Play { &mut self, matches: &clap::ArgMatches<'a>, ) -> Result<()> { + self.play_at_start = matches.is_present(PLAY_AT_START_OPTION); if matches.is_present(PLAYBACK_RATIO_OPTION) { self.playback_ratio = matches .value_of(PLAYBACK_RATIO_OPTION) @@ -754,6 +765,7 @@ impl Play { impl Default for Play { fn default() -> Self { Self { + play_at_start: false, playback_ratio: default_playback_ratio(), max_frame_length: None, } |