mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-16 15:48:21 +02:00
Add -S
flag to less when --wrap=never
(closes #1255)
Prevent less from wrapping lines by setting the proper flag when `--wrap=never`. If the user set a custom value for `--pager`, no additional flag is set.
This commit is contained in:
parent
b6e729abeb
commit
bbef2f41ec
@ -54,7 +54,10 @@ impl<'b> Controller<'b> {
|
|||||||
paging_mode = PagingMode::Never;
|
paging_mode = PagingMode::Never;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output_type = OutputType::from_mode(paging_mode, self.config.pager)?;
|
|
||||||
|
let wrapping_mode = self.config.wrapping_mode;
|
||||||
|
|
||||||
|
output_type = OutputType::from_mode(paging_mode, wrapping_mode, self.config.pager)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "paging"))]
|
#[cfg(not(feature = "paging"))]
|
||||||
|
@ -7,6 +7,8 @@ use crate::error::*;
|
|||||||
use crate::less::retrieve_less_version;
|
use crate::less::retrieve_less_version;
|
||||||
#[cfg(feature = "paging")]
|
#[cfg(feature = "paging")]
|
||||||
use crate::paging::PagingMode;
|
use crate::paging::PagingMode;
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
|
use crate::wrapping::WrappingMode;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OutputType {
|
pub enum OutputType {
|
||||||
@ -17,18 +19,23 @@ pub enum OutputType {
|
|||||||
|
|
||||||
impl OutputType {
|
impl OutputType {
|
||||||
#[cfg(feature = "paging")]
|
#[cfg(feature = "paging")]
|
||||||
pub fn from_mode(mode: PagingMode, 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::*;
|
||||||
Ok(match mode {
|
use self::WrappingMode::*;
|
||||||
Always => OutputType::try_pager(false, pager)?,
|
Ok(match paging_mode {
|
||||||
QuitIfOneScreen => OutputType::try_pager(true, pager)?,
|
Always => OutputType::try_pager(false, wrapping_mode == Character, pager)?,
|
||||||
|
QuitIfOneScreen => OutputType::try_pager(true, wrapping_mode == Character, pager)?,
|
||||||
_ => OutputType::stdout(),
|
_ => OutputType::stdout(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> {
|
fn try_pager(
|
||||||
|
quit_if_one_screen: bool,
|
||||||
|
line_wrap: bool,
|
||||||
|
pager_from_config: Option<&str>
|
||||||
|
) -> Result<Self> {
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
@ -82,6 +89,10 @@ impl OutputType {
|
|||||||
p.arg("--quit-if-one-screen");
|
p.arg("--quit-if-one-screen");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !line_wrap {
|
||||||
|
p.arg("-S");
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
// versions of 'less'. Unfortunately, it also breaks mouse-wheel support.
|
// versions of 'less'. Unfortunately, it also breaks mouse-wheel support.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user