From a4de7014155a347ca63d926cdc5b0ae6ad54acaa Mon Sep 17 00:00:00 2001 From: Stephan Dilly Date: Mon, 29 Jun 2020 20:00:47 +0200 Subject: [PATCH] move input into app so start/stop polling is less awkward --- src/app.rs | 22 ++++++++++------------ src/main.rs | 11 ++++------- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/src/app.rs b/src/app.rs index 2d55b68d..920d6e9b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -7,7 +7,7 @@ use crate::{ InspectCommitComponent, MsgComponent, ResetComponent, StashMsgComponent, }, - input::{InputEvent, InputState}, + input::{Input, InputEvent, InputState}, keys, queue::{Action, InternalEvent, NeedsUpdate, Queue}, strings::{self, commands, order}, @@ -45,21 +45,25 @@ pub struct App { stashlist_tab: StashList, queue: Queue, theme: SharedTheme, + input: Input, // "Flags" requires_redraw: Cell, - set_polling: bool, } // public interface impl App { /// - pub fn new(sender: &Sender) -> Self { + pub fn new( + sender: &Sender, + input: Input, + ) -> Self { let queue = Queue::default(); let theme = Rc::new(Theme::init()); Self { + input, reset: ResetComponent::new(queue.clone(), theme.clone()), commit: CommitComponent::new( queue.clone(), @@ -90,7 +94,6 @@ impl App { queue, theme, requires_redraw: Cell::new(false), - set_polling: true, } } @@ -197,7 +200,7 @@ impl App { self.msg.show_msg(msg.as_str())?; } self.requires_redraw.set(true); - self.set_polling = true; + self.input.set_polling(true); } } @@ -249,6 +252,7 @@ impl App { || self.revlog.any_work_pending() || self.stashing_tab.anything_pending() || self.inspect_commit_popup.any_work_pending() + || self.input.is_state_changing() } /// @@ -260,12 +264,6 @@ impl App { false } } - - /// - //TODO: rename - pub const fn set_polling(&self) -> bool { - self.set_polling - } } // private impls @@ -407,7 +405,7 @@ impl App { flags.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS) } InternalEvent::SuspendPolling => { - self.set_polling = false; + self.input.set_polling(false); } }; diff --git a/src/main.rs b/src/main.rs index 9d7314e1..56821df0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -90,13 +90,14 @@ fn main() -> Result<()> { let (tx_git, rx_git) = unbounded(); - let mut app = App::new(&tx_git); + let input = Input::new(); - let mut input = Input::new(); let rx_input = input.receiver(); let ticker = tick(TICK_INTERVAL); let spinner_ticker = tick(SPINNER_INTERVAL); + let mut app = App::new(&tx_git, input); + let mut spinner = Spinner::default(); let mut first_update = true; @@ -129,13 +130,9 @@ fn main() -> Result<()> { QueueEvent::SpinnerUpdate => unreachable!(), } - input.set_polling(app.set_polling()); - draw(&mut terminal, &app)?; - spinner.set_state( - app.any_work_pending() || input.is_state_changing(), - ); + spinner.set_state(app.any_work_pending()); spinner.draw(&mut terminal)?; if app.is_quit() {