ui: move UiOutput definition close to stdout/stderr wrappers

UiStdout/Stderr wrappers are declared at top because they have macro. Let's
move UiOutput closer as it is quite similar to these wrappers.
This commit is contained in:
Yuya Nishihara 2023-10-11 02:57:13 +09:00
parent 0e22a42a41
commit 98bf0836bf

View file

@ -23,6 +23,32 @@ use crate::cli_util::CommandError;
use crate::config::CommandNameAndArgs;
use crate::formatter::{Formatter, FormatterFactory, LabeledWriter};
enum UiOutput {
Terminal {
stdout: Stdout,
stderr: Stderr,
},
Paged {
child: Child,
child_stdin: ChildStdin,
},
}
impl UiOutput {
fn new_terminal() -> UiOutput {
UiOutput::Terminal {
stdout: io::stdout(),
stderr: io::stderr(),
}
}
fn new_paged(pager_cmd: &CommandNameAndArgs) -> io::Result<UiOutput> {
let mut child = pager_cmd.to_command().stdin(Stdio::piped()).spawn()?;
let child_stdin = child.stdin.take().unwrap();
Ok(UiOutput::Paged { child, child_stdin })
}
}
#[derive(Debug)]
pub enum UiStdout<'a> {
Terminal(StdoutLock<'static>),
@ -347,32 +373,6 @@ impl Ui {
}
}
enum UiOutput {
Terminal {
stdout: Stdout,
stderr: Stderr,
},
Paged {
child: Child,
child_stdin: ChildStdin,
},
}
impl UiOutput {
fn new_terminal() -> UiOutput {
UiOutput::Terminal {
stdout: io::stdout(),
stderr: io::stderr(),
}
}
fn new_paged(pager_cmd: &CommandNameAndArgs) -> io::Result<UiOutput> {
let mut child = pager_cmd.to_command().stdin(Stdio::piped()).spawn()?;
let child_stdin = child.stdin.take().unwrap();
Ok(UiOutput::Paged { child, child_stdin })
}
}
#[derive(Debug)]
pub struct ProgressOutput {
output: Stderr,