Skip to content

Commit a4de701

Browse files
author
Stephan Dilly
committed
move input into app so start/stop polling is less awkward
1 parent fb6cdb9 commit a4de701

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/app.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{
77
InspectCommitComponent, MsgComponent, ResetComponent,
88
StashMsgComponent,
99
},
10-
input::{InputEvent, InputState},
10+
input::{Input, InputEvent, InputState},
1111
keys,
1212
queue::{Action, InternalEvent, NeedsUpdate, Queue},
1313
strings::{self, commands, order},
@@ -45,21 +45,25 @@ pub struct App {
4545
stashlist_tab: StashList,
4646
queue: Queue,
4747
theme: SharedTheme,
48+
input: Input,
4849

4950
// "Flags"
5051
requires_redraw: Cell<bool>,
51-
set_polling: bool,
5252
}
5353

5454
// public interface
5555
impl App {
5656
///
57-
pub fn new(sender: &Sender<AsyncNotification>) -> Self {
57+
pub fn new(
58+
sender: &Sender<AsyncNotification>,
59+
input: Input,
60+
) -> Self {
5861
let queue = Queue::default();
5962

6063
let theme = Rc::new(Theme::init());
6164

6265
Self {
66+
input,
6367
reset: ResetComponent::new(queue.clone(), theme.clone()),
6468
commit: CommitComponent::new(
6569
queue.clone(),
@@ -90,7 +94,6 @@ impl App {
9094
queue,
9195
theme,
9296
requires_redraw: Cell::new(false),
93-
set_polling: true,
9497
}
9598
}
9699

@@ -197,7 +200,7 @@ impl App {
197200
self.msg.show_msg(msg.as_str())?;
198201
}
199202
self.requires_redraw.set(true);
200-
self.set_polling = true;
203+
self.input.set_polling(true);
201204
}
202205
}
203206

@@ -249,6 +252,7 @@ impl App {
249252
|| self.revlog.any_work_pending()
250253
|| self.stashing_tab.anything_pending()
251254
|| self.inspect_commit_popup.any_work_pending()
255+
|| self.input.is_state_changing()
252256
}
253257

254258
///
@@ -260,12 +264,6 @@ impl App {
260264
false
261265
}
262266
}
263-
264-
///
265-
//TODO: rename
266-
pub const fn set_polling(&self) -> bool {
267-
self.set_polling
268-
}
269267
}
270268

271269
// private impls
@@ -407,7 +405,7 @@ impl App {
407405
flags.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS)
408406
}
409407
InternalEvent::SuspendPolling => {
410-
self.set_polling = false;
408+
self.input.set_polling(false);
411409
}
412410
};
413411

src/main.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,14 @@ fn main() -> Result<()> {
9090

9191
let (tx_git, rx_git) = unbounded();
9292

93-
let mut app = App::new(&tx_git);
93+
let input = Input::new();
9494

95-
let mut input = Input::new();
9695
let rx_input = input.receiver();
9796
let ticker = tick(TICK_INTERVAL);
9897
let spinner_ticker = tick(SPINNER_INTERVAL);
9998

99+
let mut app = App::new(&tx_git, input);
100+
100101
let mut spinner = Spinner::default();
101102
let mut first_update = true;
102103

@@ -129,13 +130,9 @@ fn main() -> Result<()> {
129130
QueueEvent::SpinnerUpdate => unreachable!(),
130131
}
131132

132-
input.set_polling(app.set_polling());
133-
134133
draw(&mut terminal, &app)?;
135134

136-
spinner.set_state(
137-
app.any_work_pending() || input.is_state_changing(),
138-
);
135+
spinner.set_state(app.any_work_pending());
139136
spinner.draw(&mut terminal)?;
140137

141138
if app.is_quit() {

0 commit comments

Comments
 (0)