From 98bf0836bf85aee66da69f509c3825aba090e354 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Wed, 11 Oct 2023 02:57:13 +0900 Subject: [PATCH] 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. --- cli/src/ui.rs | 52 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/cli/src/ui.rs b/cli/src/ui.rs index 83120d717..92e9418bb 100644 --- a/cli/src/ui.rs +++ b/cli/src/ui.rs @@ -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 { + 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 { - 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,