on master help sign in
Add `-S` flag to less when `--wrap=never` (closes #1255)
bbef2f4gahag
src/controller.rs+4−1
@@ -54,7 +54,10 @@ impl<'b> Controller<'b> {
54 paging_mode = PagingMode::Never;
54 paging_mode = PagingMode::Never;
55 }
55 }
56 }
56 }
57+
58+ let wrapping_mode = self.config.wrapping_mode;
59+
57− output_type = OutputType::from_mode(paging_mode, self.config.pager)?;
60+ output_type = OutputType::from_mode(paging_mode, wrapping_mode, self.config.pager)?;
58 }
61 }
59
62
60 #[cfg(not(feature = "paging"))]
63 #[cfg(not(feature = "paging"))]
src/output.rs+16−5
@@ -7,6 +7,8 @@ use crate::error::*;
7use crate::less::retrieve_less_version;
7use crate::less::retrieve_less_version;
8#[cfg(feature = "paging")]
8#[cfg(feature = "paging")]
9use crate::paging::PagingMode;
9use crate::paging::PagingMode;
10+#[cfg(feature = "paging")]
11+use crate::wrapping::WrappingMode;
10
12
11#[derive(Debug)]
13#[derive(Debug)]
12pub enum OutputType {
14pub enum OutputType {
@@ -17,18 +19,23 @@ pub enum OutputType {
17
19
18impl OutputType {
20impl OutputType {
19 #[cfg(feature = "paging")]
21 #[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> {
21 use self::PagingMode::*;
23 use self::PagingMode::*;
24+ use self::WrappingMode::*;
22− Ok(match mode {
25+ Ok(match paging_mode {
23− Always => OutputType::try_pager(false, pager)?,
26+ Always => OutputType::try_pager(false, wrapping_mode == Character, pager)?,
24− QuitIfOneScreen => OutputType::try_pager(true, pager)?,
27+ QuitIfOneScreen => OutputType::try_pager(true, wrapping_mode == Character, pager)?,
25 _ => OutputType::stdout(),
28 _ => OutputType::stdout(),
26 })
29 })
27 }
30 }
28
31
29 /// Try to launch the pager. Fall back to stdout in case of errors.
32 /// Try to launch the pager. Fall back to stdout in case of errors.
30 #[cfg(feature = "paging")]
33 #[cfg(feature = "paging")]
34+ fn try_pager(
35+ quit_if_one_screen: bool,
36+ line_wrap: bool,
31− fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> {
37+ pager_from_config: Option<&str>
38+ ) -> Result<Self> {
32 use std::env;
39 use std::env;
33 use std::ffi::OsString;
40 use std::ffi::OsString;
34 use std::path::PathBuf;
41 use std::path::PathBuf;
@@ -82,6 +89,10 @@ impl OutputType {
82 p.arg("--quit-if-one-screen");
89 p.arg("--quit-if-one-screen");
83 }
90 }
84
91
92+ if !line_wrap {
93+ p.arg("-S");
94+ }
95+
85 // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older
96 // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older
86 // versions of 'less'. Unfortunately, it also breaks mouse-wheel support.
97 // versions of 'less'. Unfortunately, it also breaks mouse-wheel support.
87 //
98 //