move input into app so start/stop polling is less awkward

This commit is contained in:
Stephan Dilly 2020-06-29 20:00:47 +02:00
parent fb6cdb92ea
commit a4de701415
2 changed files with 14 additions and 19 deletions

View file

@ -7,7 +7,7 @@ use crate::{
InspectCommitComponent, MsgComponent, ResetComponent, InspectCommitComponent, MsgComponent, ResetComponent,
StashMsgComponent, StashMsgComponent,
}, },
input::{InputEvent, InputState}, input::{Input, InputEvent, InputState},
keys, keys,
queue::{Action, InternalEvent, NeedsUpdate, Queue}, queue::{Action, InternalEvent, NeedsUpdate, Queue},
strings::{self, commands, order}, strings::{self, commands, order},
@ -45,21 +45,25 @@ pub struct App {
stashlist_tab: StashList, stashlist_tab: StashList,
queue: Queue, queue: Queue,
theme: SharedTheme, theme: SharedTheme,
input: Input,
// "Flags" // "Flags"
requires_redraw: Cell<bool>, requires_redraw: Cell<bool>,
set_polling: bool,
} }
// public interface // public interface
impl App { impl App {
/// ///
pub fn new(sender: &Sender<AsyncNotification>) -> Self { pub fn new(
sender: &Sender<AsyncNotification>,
input: Input,
) -> Self {
let queue = Queue::default(); let queue = Queue::default();
let theme = Rc::new(Theme::init()); let theme = Rc::new(Theme::init());
Self { Self {
input,
reset: ResetComponent::new(queue.clone(), theme.clone()), reset: ResetComponent::new(queue.clone(), theme.clone()),
commit: CommitComponent::new( commit: CommitComponent::new(
queue.clone(), queue.clone(),
@ -90,7 +94,6 @@ impl App {
queue, queue,
theme, theme,
requires_redraw: Cell::new(false), requires_redraw: Cell::new(false),
set_polling: true,
} }
} }
@ -197,7 +200,7 @@ impl App {
self.msg.show_msg(msg.as_str())?; self.msg.show_msg(msg.as_str())?;
} }
self.requires_redraw.set(true); 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.revlog.any_work_pending()
|| self.stashing_tab.anything_pending() || self.stashing_tab.anything_pending()
|| self.inspect_commit_popup.any_work_pending() || self.inspect_commit_popup.any_work_pending()
|| self.input.is_state_changing()
} }
/// ///
@ -260,12 +264,6 @@ impl App {
false false
} }
} }
///
//TODO: rename
pub const fn set_polling(&self) -> bool {
self.set_polling
}
} }
// private impls // private impls
@ -407,7 +405,7 @@ impl App {
flags.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS) flags.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS)
} }
InternalEvent::SuspendPolling => { InternalEvent::SuspendPolling => {
self.set_polling = false; self.input.set_polling(false);
} }
}; };

View file

@ -90,13 +90,14 @@ fn main() -> Result<()> {
let (tx_git, rx_git) = unbounded(); 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 rx_input = input.receiver();
let ticker = tick(TICK_INTERVAL); let ticker = tick(TICK_INTERVAL);
let spinner_ticker = tick(SPINNER_INTERVAL); let spinner_ticker = tick(SPINNER_INTERVAL);
let mut app = App::new(&tx_git, input);
let mut spinner = Spinner::default(); let mut spinner = Spinner::default();
let mut first_update = true; let mut first_update = true;
@ -129,13 +130,9 @@ fn main() -> Result<()> {
QueueEvent::SpinnerUpdate => unreachable!(), QueueEvent::SpinnerUpdate => unreachable!(),
} }
input.set_polling(app.set_polling());
draw(&mut terminal, &app)?; draw(&mut terminal, &app)?;
spinner.set_state( spinner.set_state(app.any_work_pending());
app.any_work_pending() || input.is_state_changing(),
);
spinner.draw(&mut terminal)?; spinner.draw(&mut terminal)?;
if app.is_quit() { if app.is_quit() {