mirror of https://github.com/bobwen-dev/hunter
Merge pull request #60 from petrusboniatus/master
Added configurable refresh rate
This commit is contained in:
commit
19be163b3c
|
@ -79,6 +79,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,
|
||||
|
@ -101,6 +102,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(),
|
||||
|
@ -126,6 +128,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,
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue