Skip to content

Commit 75c44a1

Browse files
committed
Fix pager spawn under QEMU user-mode emulation
1 parent ad60801 commit 75c44a1

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Improve native man pages and command help syntax highlighting by stripping overstriking, see #3517 (@akirk)
88

99
## Bugfixes
10+
- Fix pager spawn detection under QEMU user-mode emulation. See #3531 (@OctopusET)
1011
- `--help` now correctly honors `--pager=builtin`. See #3516 (@keith-hall)
1112
- `--help` now correctly honors custom themes. See #3524 (@keith-hall)
1213

src/output.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ impl OutputType {
113113
let args = pager.args;
114114

115115
if pager.kind == PagerKind::Less {
116+
if retrieve_less_version(&pager.bin).is_none() {
117+
return Ok(OutputType::stdout());
118+
}
119+
116120
// less needs to be called with the '-R' option in order to properly interpret the
117121
// ANSI color sequences printed by bat. If someone has set PAGER="less -F", we
118122
// therefore need to overwrite the arguments and add '-R'.
@@ -166,10 +170,13 @@ impl OutputType {
166170
p.args(args);
167171
};
168172

169-
Ok(p.stdin(Stdio::piped())
170-
.spawn()
171-
.map(OutputType::Pager)
172-
.unwrap_or_else(|_| OutputType::stdout()))
173+
Ok(match p.stdin(Stdio::piped()).spawn() {
174+
Ok(mut child) => match child.try_wait() {
175+
Ok(Some(status)) if !status.success() => OutputType::stdout(),
176+
_ => OutputType::Pager(child),
177+
},
178+
Err(_) => OutputType::stdout(),
179+
})
173180
}
174181

175182
pub(crate) fn stdout() -> Self {

0 commit comments

Comments
 (0)