on master help sign in
Code review
53f5a37gahag
src/output.rs+16−8
@@ -10,6 +10,15 @@ use crate::paging::PagingMode;
10#[cfg(feature = "paging")]
10#[cfg(feature = "paging")]
11use crate::wrapping::WrappingMode;
11use crate::wrapping::WrappingMode;
12
12
13+
14+#[cfg(feature = "paging")]
15+#[derive(Debug)]
16+enum SingleScreenAction {
17+ Quit,
18+ Nothing,
19+}
20+
21+
13#[derive(Debug)]
22#[derive(Debug)]
14pub enum OutputType {
23pub enum OutputType {
15 #[cfg(feature = "paging")]
24 #[cfg(feature = "paging")]
@@ -21,10 +30,9 @@ impl OutputType {
21 #[cfg(feature = "paging")]
30 #[cfg(feature = "paging")]
22 pub fn from_mode(paging_mode: PagingMode, wrapping_mode: WrappingMode, pager: Option<&str>) -> Result<Self> {
31 pub fn from_mode(paging_mode: PagingMode, wrapping_mode: WrappingMode, pager: Option<&str>) -> Result<Self> {
23 use self::PagingMode::*;
32 use self::PagingMode::*;
24− use self::WrappingMode::*;
25 Ok(match paging_mode {
33 Ok(match paging_mode {
26− Always => OutputType::try_pager(false, wrapping_mode == Character, pager)?,
34+ Always => OutputType::try_pager(SingleScreenAction::Nothing, wrapping_mode, pager)?,
27− QuitIfOneScreen => OutputType::try_pager(true, wrapping_mode == Character, pager)?,
35+ QuitIfOneScreen => OutputType::try_pager(SingleScreenAction::Quit, wrapping_mode, pager)?,
28 _ => OutputType::stdout(),
36 _ => OutputType::stdout(),
29 })
37 })
30 }
38 }
@@ -32,8 +40,8 @@ impl OutputType {
32 /// Try to launch the pager. Fall back to stdout in case of errors.
40 /// Try to launch the pager. Fall back to stdout in case of errors.
33 #[cfg(feature = "paging")]
41 #[cfg(feature = "paging")]
34 fn try_pager(
42 fn try_pager(
35− quit_if_one_screen: bool,
43+ single_screen_action: SingleScreenAction,
36− line_wrap: bool,
44+ wrapping_mode: WrappingMode,
37 pager_from_config: Option<&str>
45 pager_from_config: Option<&str>
38 ) -> Result<Self> {
46 ) -> Result<Self> {
39 use std::env;
47 use std::env;
@@ -85,12 +93,12 @@ impl OutputType {
85 let mut p = Command::new(&pager_path);
93 let mut p = Command::new(&pager_path);
86 if args.is_empty() || replace_arguments_to_less {
94 if args.is_empty() || replace_arguments_to_less {
87 p.arg("--RAW-CONTROL-CHARS");
95 p.arg("--RAW-CONTROL-CHARS");
88− if quit_if_one_screen {
96+ if let SingleScreenAction::Quit = single_screen_action {
89 p.arg("--quit-if-one-screen");
97 p.arg("--quit-if-one-screen");
90 }
98 }
91
99
92− if !line_wrap {
100+ if let WrappingMode::NoWrapping = wrapping_mode {
93− p.arg("-S");
101+ p.arg("--chop-long-lines");
94 }
102 }
95
103
96 // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older
104 // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older