Code review
Replace bools with enums
Replace short flag with long flag
@@ -10,6 +10,15 @@ use crate::paging::PagingMode;
#[cfg(feature = "paging")]
use crate::wrapping::WrappingMode;
+
+#[cfg(feature = "paging")]
+#[derive(Debug)]
+enum SingleScreenAction {
+ Quit,
+ Nothing,
+}
+
+
#[derive(Debug)]
pub enum OutputType {
#[cfg(feature = "paging")]
@@ -21,10 +30,9 @@ impl OutputType {
#[cfg(feature = "paging")]
pub fn from_mode(paging_mode: PagingMode, wrapping_mode: WrappingMode, pager: Option<&str>) -> Result<Self> {
use self::PagingMode::*;
- use self::WrappingMode::*;
Ok(match paging_mode {
- Always => OutputType::try_pager(false, wrapping_mode == Character, pager)?,
- QuitIfOneScreen => OutputType::try_pager(true, wrapping_mode == Character, pager)?,
+ Always => OutputType::try_pager(SingleScreenAction::Nothing, wrapping_mode, pager)?,
+ QuitIfOneScreen => OutputType::try_pager(SingleScreenAction::Quit, wrapping_mode, pager)?,
_ => OutputType::stdout(),
})
}
@@ -32,8 +40,8 @@ impl OutputType {
/// Try to launch the pager. Fall back to stdout in case of errors.
#[cfg(feature = "paging")]
fn try_pager(
- quit_if_one_screen: bool,
- line_wrap: bool,
+ single_screen_action: SingleScreenAction,
+ wrapping_mode: WrappingMode,
pager_from_config: Option<&str>
) -> Result<Self> {
use std::env;
@@ -85,12 +93,12 @@ impl OutputType {
let mut p = Command::new(&pager_path);
if args.is_empty() || replace_arguments_to_less {
p.arg("--RAW-CONTROL-CHARS");
- if quit_if_one_screen {
+ if let SingleScreenAction::Quit = single_screen_action {
p.arg("--quit-if-one-screen");
}
- if !line_wrap {
- p.arg("-S");
+ if let WrappingMode::NoWrapping = wrapping_mode {
+ p.arg("--chop-long-lines");
}
// Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older
