diff --git a/src/controller.rs b/src/controller.rs index 3fe44a72..dff817cd 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -54,7 +54,10 @@ impl<'b> Controller<'b> { 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"))] diff --git a/src/output.rs b/src/output.rs index e7d59d67..c42fe68d 100644 --- a/src/output.rs +++ b/src/output.rs @@ -7,6 +7,8 @@ use crate::error::*; use crate::less::retrieve_less_version; #[cfg(feature = "paging")] use crate::paging::PagingMode; +#[cfg(feature = "paging")] +use crate::wrapping::WrappingMode; #[derive(Debug)] pub enum OutputType { @@ -17,18 +19,23 @@ pub enum OutputType { impl OutputType { #[cfg(feature = "paging")] - pub fn from_mode(mode: PagingMode, pager: Option<&str>) -> Result { + pub fn from_mode(paging_mode: PagingMode, wrapping_mode: WrappingMode, pager: Option<&str>) -> Result { use self::PagingMode::*; - Ok(match mode { - Always => OutputType::try_pager(false, pager)?, - QuitIfOneScreen => OutputType::try_pager(true, pager)?, + 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)?, _ => OutputType::stdout(), }) } /// Try to launch the pager. Fall back to stdout in case of errors. #[cfg(feature = "paging")] - fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result { + fn try_pager( + quit_if_one_screen: bool, + line_wrap: bool, + pager_from_config: Option<&str> + ) -> Result { use std::env; use std::ffi::OsString; use std::path::PathBuf; @@ -82,6 +89,10 @@ impl OutputType { 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 // versions of 'less'. Unfortunately, it also breaks mouse-wheel support. //