Skip to content

Commit 8532042

Browse files
committed
add startup_poll_input config option
Add a `startup_poll_input` config option (default: true). If set to false, streampager will not poll input during the delayed or direct mode startup phase. This means input typed before the pager exits early for these modes will remain in the terminal input buffer (e.g. for a subsequent command passed to the shell). Note that a side-effect of this is is that we also miss SIGWINCH events, as they come from the termiz terminal on the same event stream. Fixes #39.
1 parent d89e0e7 commit 8532042

File tree

6 files changed

+24
-2
lines changed

6 files changed

+24
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ varies by platform; on Linux it is typically `~/.config`.
116116
interface_mode = "delayed"
117117
scroll_past_eof = true
118118
read_ahead_lines = 20000
119+
startup_poll_input = true
119120
wrapping_mode = "word"
120121
keymap = "mykeymap"
121122
```

src/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ pub struct Config {
164164
/// Specify how many lines to read ahead.
165165
pub read_ahead_lines: usize,
166166

167+
/// Specify whether to poll input during start-up (delayed or direct mode).
168+
pub startup_poll_input: bool,
169+
167170
/// Specify default wrapping move.
168171
pub wrapping_mode: WrappingMode,
169172

@@ -177,6 +180,7 @@ impl Default for Config {
177180
interface_mode: Default::default(),
178181
scroll_past_eof: true,
179182
read_ahead_lines: crate::file::DEFAULT_NEEDED_LINES,
183+
startup_poll_input: true,
180184
wrapping_mode: Default::default(),
181185
keymap: Default::default(),
182186
}

src/direct.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub(crate) fn direct<T: Terminal>(
6464
progress: Option<&Progress>,
6565
events: &mut EventStream,
6666
mode: InterfaceMode,
67+
poll_input: bool,
6768
) -> Result<Outcome> {
6869
if mode == InterfaceMode::FullScreen {
6970
return Ok(Outcome::RenderNothing);
@@ -138,8 +139,18 @@ pub(crate) fn direct<T: Terminal>(
138139
let mut size = term.get_screen_size().map_err(Error::Termwiz)?;
139140
let mut loaded = BitSet::with_capacity(loading.capacity());
140141
let mut remaining = output_files.len() + error_files.len();
142+
let interval = Duration::from_millis(10);
141143
while remaining > 0 {
142-
match events.get(term, Some(Duration::from_millis(10)))? {
144+
let maybe_event = if poll_input {
145+
events.get(term, Some(interval))?
146+
} else {
147+
events.try_recv()?.or_else(|| {
148+
// Sleep to avoid busy wait
149+
std::thread::sleep(interval);
150+
None
151+
})
152+
};
153+
match maybe_event {
143154
Some(Event::Loaded(i)) => {
144155
if loading.contains(i) && loaded.insert(i) {
145156
remaining -= 1;

src/display.rs

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub(crate) fn start(
185185
progress.as_ref(),
186186
&mut events,
187187
config.interface_mode,
188+
config.startup_poll_input,
188189
)?
189190
};
190191
match outcome {

src/event.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl EventStream {
104104
ActionSender::new(self.sender())
105105
}
106106

107-
fn try_recv(&self) -> Result<Option<Event>, Error> {
107+
pub(crate) fn try_recv(&self) -> Result<Option<Event>, Error> {
108108
match self.recv.try_recv() {
109109
Ok(Envelope::Normal(event)) => Ok(Some(event)),
110110
Ok(Envelope::Unique(event, unique)) => {

src/pager.rs

+5
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ impl Pager {
211211
self.config.read_ahead_lines = lines;
212212
}
213213

214+
/// Set whether to poll input during start-up (delayed or direct mode).
215+
pub fn set_startup_poll_input(&mut self, poll_input: bool) {
216+
self.config.startup_poll_input = poll_input;
217+
}
218+
214219
/// Set default wrapping mode. See [`WrappingMode`] for details.
215220
pub fn set_wrapping_mode(&mut self, value: impl Into<WrappingMode>) {
216221
self.config.wrapping_mode = value.into();

0 commit comments

Comments
 (0)