summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgahag <gabriel.s.b@live.com>2020-10-07 14:50:44 -0300
committerDavid Peter <sharkdp@users.noreply.github.com>2020-10-08 18:51:42 +0200
commit53f5a37f01c0c354a552c50aa87a8edf38f9b9f0 (patch)
tree285a4ebad870cf0aeb0dc0a041f185c523677d62
parentbbef2f41ec0c670dcc54a78ac5b497a084c2557b (diff)
Code review
- Replace bools with enums - Replace short flag with long flag
-rw-r--r--src/output.rs24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/output.rs b/src/output.rs
index c42fe68d..1e84e946 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -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