on master help sign in
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.

commitbbef2f41ec0c670dcc54a78ac5b497a084c2557b authorgahag <gabriel.s.b@live.com> dateWed 7 Oct 2020, 12:28 (6 years ago) parentb6e729a
2 files changed+20−6
src/controller.rs+4−1 src/output.rs+16−5
src/controller.rs+4−1
@@ -54,7 +54,10 @@ impl<'b> Controller<'b> {
5454 paging_mode = PagingMode::Never;
5555 }
5656 }
57− output_type = OutputType::from_mode(paging_mode, self.config.pager)?;
57+
58+ let wrapping_mode = self.config.wrapping_mode;
59+
60+ output_type = OutputType::from_mode(paging_mode, wrapping_mode, self.config.pager)?;
5861 }
5962
6063 #[cfg(not(feature = "paging"))]
src/output.rs+16−5
@@ -7,6 +7,8 @@ use crate::error::*;
77use crate::less::retrieve_less_version;
88#[cfg(feature = "paging")]
99use crate::paging::PagingMode;
10+#[cfg(feature = "paging")]
11+use crate::wrapping::WrappingMode;
1012
1113#[derive(Debug)]
1214pub enum OutputType {
@@ -17,18 +19,23 @@ pub enum OutputType {
1719
1820impl OutputType {
1921 #[cfg(feature = "paging")]
20− pub fn from_mode(mode: PagingMode, pager: Option<&str>) -> Result<Self> {
22+ pub fn from_mode(paging_mode: PagingMode, wrapping_mode: WrappingMode, pager: Option<&str>) -> Result<Self> {
2123 use self::PagingMode::*;
22− Ok(match mode {
23− Always => OutputType::try_pager(false, pager)?,
24− QuitIfOneScreen => OutputType::try_pager(true, pager)?,
24+ use self::WrappingMode::*;
25+ Ok(match paging_mode {
26+ Always => OutputType::try_pager(false, wrapping_mode == Character, pager)?,
27+ QuitIfOneScreen => OutputType::try_pager(true, wrapping_mode == Character, pager)?,
2528 _ => OutputType::stdout(),
2629 })
2730 }
2831
2932 /// Try to launch the pager. Fall back to stdout in case of errors.
3033 #[cfg(feature = "paging")]
31− fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> {
34+ fn try_pager(
35+ quit_if_one_screen: bool,
36+ line_wrap: bool,
37+ pager_from_config: Option<&str>
38+ ) -> Result<Self> {
3239 use std::env;
3340 use std::ffi::OsString;
3441 use std::path::PathBuf;
@@ -82,6 +89,10 @@ impl OutputType {
8289 p.arg("--quit-if-one-screen");
8390 }
8491
92+ if !line_wrap {
93+ p.arg("-S");
94+ }
95+
8596 // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older
8697 // versions of 'less'. Unfortunately, it also breaks mouse-wheel support.
8798 //