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,
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<bool>,
set_polling: bool,
}
// public interface
impl App {
///
pub fn new(sender: &Sender<AsyncNotification>) -> Self {
pub fn new(
sender: &Sender<AsyncNotification>,
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);
}
};

View file

@ -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() {