@@ -9,6 +9,7 @@ use crate::{
99 config:: { get_args_from_config_file, get_args_from_env_opts_var, get_args_from_env_vars} ,
1010} ;
1111use bat:: style:: StyleComponentList ;
12+ use bat:: BinaryBehavior ;
1213use bat:: StripAnsiMode ;
1314use clap:: ArgMatches ;
1415
@@ -97,12 +98,30 @@ impl App {
9798 pub fn config ( & self , inputs : & [ Input ] ) -> Result < Config > {
9899 let style_components = self . style_components ( ) ?;
99100
101+ let extra_plain = self . matches . get_count ( "plain" ) > 1 ;
102+ let plain_last_index = self
103+ . matches
104+ . indices_of ( "plain" )
105+ . and_then ( Iterator :: max)
106+ . unwrap_or_default ( ) ;
107+ let paging_last_index = self
108+ . matches
109+ . indices_of ( "paging" )
110+ . and_then ( Iterator :: max)
111+ . unwrap_or_default ( ) ;
112+
100113 let paging_mode = match self . matches . get_one :: < String > ( "paging" ) . map ( |s| s. as_str ( ) ) {
101- Some ( "always" ) => PagingMode :: Always ,
114+ Some ( "always" ) => {
115+ // Disable paging if the second -p (or -pp) is specified after --paging=always
116+ if extra_plain && plain_last_index > paging_last_index {
117+ PagingMode :: Never
118+ } else {
119+ PagingMode :: Always
120+ }
121+ }
102122 Some ( "never" ) => PagingMode :: Never ,
103123 Some ( "auto" ) | None => {
104124 // If we have -pp as an option when in auto mode, the pager should be disabled.
105- let extra_plain = self . matches . get_count ( "plain" ) > 1 ;
106125 if extra_plain || self . matches . get_flag ( "no-paging" ) {
107126 PagingMode :: Never
108127 } else if inputs. iter ( ) . any ( Input :: is_stdin) {
@@ -193,6 +212,11 @@ impl App {
193212 Some ( "caret" ) => NonprintableNotation :: Caret ,
194213 _ => unreachable ! ( "other values for --nonprintable-notation are not allowed" ) ,
195214 } ,
215+ binary : match self . matches . get_one :: < String > ( "binary" ) . map ( |s| s. as_str ( ) ) {
216+ Some ( "as-text" ) => BinaryBehavior :: AsText ,
217+ Some ( "no-printing" ) => BinaryBehavior :: NoPrinting ,
218+ _ => unreachable ! ( "other values for --binary are not allowed" ) ,
219+ } ,
196220 wrapping_mode : if self . interactive_output || maybe_term_width. is_some ( ) {
197221 if !self . matches . get_flag ( "chop-long-lines" ) {
198222 match self . matches . get_one :: < String > ( "wrap" ) . map ( |s| s. as_str ( ) ) {
0 commit comments