forked from mirrors/jj
cli: colorize pager spawn error
I've moved error handling to the call site to avoid passing &mut Ui around.
This commit is contained in:
parent
74084d026c
commit
34fe0899ca
1 changed files with 14 additions and 18 deletions
32
src/ui.rs
32
src/ui.rs
|
@ -150,12 +150,18 @@ impl Ui {
|
|||
}
|
||||
|
||||
match self.output {
|
||||
UiOutput::Paged { .. } => {}
|
||||
UiOutput::Terminal { .. } => {
|
||||
if io::stdout().is_tty() {
|
||||
self.output = UiOutput::new_paged_else_terminal(&self.settings);
|
||||
UiOutput::Terminal { .. } if io::stdout().is_tty() => {
|
||||
match UiOutput::new_paged(&self.settings) {
|
||||
Ok(new_output) => {
|
||||
self.output = new_output;
|
||||
}
|
||||
Err(e) => {
|
||||
self.write_warn(&format!("Failed to spawn pager: {}\n", e))
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
UiOutput::Terminal { .. } | UiOutput::Paged { .. } => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -342,21 +348,11 @@ impl UiOutput {
|
|||
}
|
||||
}
|
||||
|
||||
fn new_paged_else_terminal(settings: &UserSettings) -> UiOutput {
|
||||
fn new_paged(settings: &UserSettings) -> io::Result<UiOutput> {
|
||||
let pager_cmd = pager_setting(settings);
|
||||
let child_result = Command::new(pager_cmd).stdin(Stdio::piped()).spawn();
|
||||
match child_result {
|
||||
Ok(mut child) => {
|
||||
let child_stdin = child.stdin.take().unwrap();
|
||||
UiOutput::Paged { child, child_stdin }
|
||||
}
|
||||
Err(e) => {
|
||||
io::stderr()
|
||||
.write_fmt(format_args!("Failed to spawn pager: {}\n", e))
|
||||
.ok();
|
||||
UiOutput::new_terminal()
|
||||
}
|
||||
}
|
||||
let mut child = Command::new(pager_cmd).stdin(Stdio::piped()).spawn()?;
|
||||
let child_stdin = child.stdin.take().unwrap();
|
||||
Ok(UiOutput::Paged { child, child_stdin })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue