Added configurable refresh rate

This commit is contained in:
petrusboniatus 2019-07-07 19:58:26 +02:00
parent f542922176
commit 9698167285
2 changed files with 15 additions and 2 deletions

View File

@ -71,6 +71,7 @@ fn infuse_argv_config(mut config: Config) -> Config {
#[derive(Debug, Clone)]
pub struct Config {
pub animation: bool,
pub animation_refresh_frequency: usize,
pub show_hidden: bool,
pub select_cmd: String,
pub cd_cmd: String,
@ -92,6 +93,7 @@ impl Config {
pub fn default() -> Config {
Config {
animation: true,
animation_refresh_frequency: 60,
show_hidden: false,
select_cmd: "find -type f | fzf -m".to_string(),
cd_cmd: "find -type d | fzf".to_string(),
@ -116,6 +118,12 @@ impl Config {
match Config::prep_line(line) {
Ok(("animation", "on")) => { config.animation = true; },
Ok(("animation", "off")) => { config.animation = false; },
Ok(("animation_refresh_frequency", frequency)) => {
match frequency.parse::<usize>() {
Ok(parsed_freq) => config.animation_refresh_frequency = parsed_freq,
_ => HError::config_error::<Config>(line.to_string()).log()
}
}
Ok(("show_hidden", "on")) => { config.show_hidden = true; },
Ok(("show_hidden", "off")) => { config.show_hidden = false; },
Ok(("icons", "on")) => config.icons = true,

View File

@ -406,7 +406,12 @@ pub trait Widget {
let xsize = coords.xsize();
let ysize = coords.ysize();
let clear = self.get_core()?.get_clearlist()?;
let pause = std::time::Duration::from_millis(5);
let animation_hz = self.get_core()?.config().animation_refresh_frequency as u64;
let pause_millis = 1000/animation_hz;
const ANIMATION_DURATION_MILLIS: u64 = 64;
let number_of_frames= (ANIMATION_DURATION_MILLIS/pause_millis) as u16;
let pause = std::time::Duration::from_millis(pause_millis);
if let Some(ref animator) = animator {
if animator.is_stale()? {
@ -416,7 +421,7 @@ pub trait Widget {
self.get_core()?.write_to_screen(&clear).log();
for i in (0..10).rev() {
for i in (0..number_of_frames).rev() {
if let Some(ref animator) = animator {
if animator.is_stale()? {
self.set_coordinates(&coords).log();