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