Skip to content

Commit

Permalink
config: add refresh_on_file_change bool to en/disable file watcher
Browse files Browse the repository at this point in the history
  • Loading branch information
sbillig authored and altsem committed Jan 16, 2025
1 parent 4973c64 commit e7d1146
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub(crate) struct Config {
pub struct GeneralConfig {
pub always_show_help: BoolConfigEntry,
pub confirm_quit: BoolConfigEntry,
pub refresh_on_file_change: BoolConfigEntry,
pub collapsed_sections: Vec<String>,
}

Expand Down
1 change: 1 addition & 0 deletions src/default_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ confirm_quit.enabled = false
# Sets initially collapsed sections in the editor. e.g.:
# collapsed_sections = ["untracked", "recent_commits", "branch_status"]
collapsed_sections = []
refresh_on_file_change.enabled = true

[style]
# fg / bg can be either of:
Expand Down
13 changes: 9 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> {
repo.set_workdir(&dir, false)?;

log::debug!("Initializing config");
let config = config::init_config()?;
let config = Rc::new(config::init_config()?);

log::debug!("Creating initial state");
let mut state = state::State::create(Rc::new(repo), term.size()?, args, Rc::new(config), true)?;
let mut state = state::State::create(Rc::new(repo), term.size()?, args, config.clone(), true)?;

log::debug!("Initial update");
state.update(term, &[GituEvent::Term(Event::FocusGained)])?;
Expand All @@ -106,7 +106,12 @@ pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> {
handle_initial_send_keys(&keys, &mut state, term)?;
}

let watcher = FileWatcher::new(&dir)?;
let watcher = config
.general
.refresh_on_file_change
.enabled
.then(|| FileWatcher::new(&dir))
.transpose()?;

while !state.quit {
let mut events = if event::poll(Duration::from_millis(100))? {
Expand All @@ -115,7 +120,7 @@ pub fn run(args: &cli::Args, term: &mut Term) -> Res<()> {
vec![]
};

if watcher.pending_updates() {
if watcher.as_ref().is_some_and(|w| w.pending_updates()) {
events.push(GituEvent::FileUpdate);
}
state.update(term, &events)?;
Expand Down

0 comments on commit e7d1146

Please sign in to comment.