on master help sign in
Disabled tab expansion when decorations and pager are not used.
commiteb6e43b9a91e1b3d59b208dad8c3889f1ddbc0c8 authoreth-p <32112321+eth-p@users.noreply.github.com> dateMon 10 Sep 2018, 20:12 (8 years ago) parent7cdcdbb
1 file changed+202−194
src/app.rs+202−194
src/app.rs+202−194
@@ -16,7 +16,7 @@ use errors::*;
1616use line_range::LineRange;
1717use style::{OutputComponent, OutputComponents, OutputWrap};
1818
19−#[derive(Debug, Clone, Copy)]
19+#[derive(Debug, Clone, Copy, PartialEq)]
2020pub enum PagingMode {
2121 Always,
2222 QuitIfOneScreen,
@@ -133,7 +133,7 @@ impl App {
133133 to read from standard input.",
134134 ).multiple(true)
135135 .empty_values(false),
136− )
136+ )
137137 .arg(
138138 Arg::with_name("language")
139139 .short("l")
@@ -147,204 +147,204 @@ impl App {
147147 language names and file extensions."
148148 ).takes_value(true),
149149 ).arg(
150− Arg::with_name("list-languages")
151− .long("list-languages")
152− .conflicts_with("list-themes")
153− .help("Display all supported languages.")
154− .long_help("Display a list of supported languages for syntax highlighting."),
155− ).arg(
156− Arg::with_name("theme")
157− .long("theme")
158− .overrides_with("theme")
159− .takes_value(true)
160− .help("Set the color theme for syntax highlighting.")
161− .long_help(
162− "Set the theme for syntax highlighting. Use '--list-themes' to \
150+ Arg::with_name("list-languages")
151+ .long("list-languages")
152+ .conflicts_with("list-themes")
153+ .help("Display all supported languages.")
154+ .long_help("Display a list of supported languages for syntax highlighting."),
155+ ).arg(
156+ Arg::with_name("theme")
157+ .long("theme")
158+ .overrides_with("theme")
159+ .takes_value(true)
160+ .help("Set the color theme for syntax highlighting.")
161+ .long_help(
162+ "Set the theme for syntax highlighting. Use '--list-themes' to \
163163 see all available themes. To set a default theme, export the \
164164 BAT_THEME environment variable (e.g.: export \
165165 BAT_THEME=\"TwoDark\").",
166− ),
167− ).arg(
168− Arg::with_name("list-themes")
169− .long("list-themes")
170− .help("Display all supported highlighting themes.")
171− .long_help("Display a list of supported themes for syntax highlighting."),
172− ).arg(
173− Arg::with_name("style")
174− .long("style")
175− .value_name("style-components")
176− .use_delimiter(true)
177− .takes_value(true)
178− .possible_values(&[
179− "auto", "full", "plain", "changes", "header", "grid", "numbers",
180− ]).default_value("auto")
181− .help("Comma-separated list of style elements to display.")
182− .long_help(
183− "Configure which elements (line numbers, file headers, grid \
166+ ),
167+ ).arg(
168+ Arg::with_name("list-themes")
169+ .long("list-themes")
170+ .help("Display all supported highlighting themes.")
171+ .long_help("Display a list of supported themes for syntax highlighting."),
172+ ).arg(
173+ Arg::with_name("style")
174+ .long("style")
175+ .value_name("style-components")
176+ .use_delimiter(true)
177+ .takes_value(true)
178+ .possible_values(&[
179+ "auto", "full", "plain", "changes", "header", "grid", "numbers",
180+ ]).default_value("auto")
181+ .help("Comma-separated list of style elements to display.")
182+ .long_help(
183+ "Configure which elements (line numbers, file headers, grid \
184184 borders, Git modifications, ..) to display in addition to the \
185185 file contents. The argument is a comma-separated list of \
186186 components to display (e.g. 'numbers,changes,grid') or a \
187187 pre-defined style ('full')",
188− ),
189− ).arg(
190− Arg::with_name("plain")
191− .overrides_with("plain")
192− .short("p")
193− .long("plain")
194− .conflicts_with("style")
195− .conflicts_with("number")
196− .help("Show plain style (alias for '--style=plain').")
197− .long_help(
198− "Only show plain style, no decorations. This is an alias for \
188+ ),
189+ ).arg(
190+ Arg::with_name("plain")
191+ .overrides_with("plain")
192+ .short("p")
193+ .long("plain")
194+ .conflicts_with("style")
195+ .conflicts_with("number")
196+ .help("Show plain style (alias for '--style=plain').")
197+ .long_help(
198+ "Only show plain style, no decorations. This is an alias for \
199199 '--style=plain'",
200− ),
201− ).arg(
202− Arg::with_name("number")
203− .long("number")
204− .overrides_with("number")
205− .short("n")
206− .conflicts_with("style")
207− .help("Show line numbers (alias for '--style=numbers').")
208− .long_help(
209− "Only show line numbers, no other decorations. This is an alias for \
200+ ),
201+ ).arg(
202+ Arg::with_name("number")
203+ .long("number")
204+ .overrides_with("number")
205+ .short("n")
206+ .conflicts_with("style")
207+ .help("Show line numbers (alias for '--style=numbers').")
208+ .long_help(
209+ "Only show line numbers, no other decorations. This is an alias for \
210210 '--style=numbers'",
211− ),
212− ).arg(
213− Arg::with_name("line-range")
214− .long("line-range")
215− .overrides_with("line-range")
216− .takes_value(true)
217− .value_name("N:M")
218− .help("Only print the lines from N to M.")
219− .long_help(
220− "Only print the specified range of lines for each file. \
211+ ),
212+ ).arg(
213+ Arg::with_name("line-range")
214+ .long("line-range")
215+ .overrides_with("line-range")
216+ .takes_value(true)
217+ .value_name("N:M")
218+ .help("Only print the lines from N to M.")
219+ .long_help(
220+ "Only print the specified range of lines for each file. \
221221 For example:\n \
222222 '--line-range 30:40' prints lines 30 to 40\n \
223223 '--line-range :40' prints lines 1 to 40\n \
224224 '--line-range 40:' prints lines 40 to the end of the file",
225− ),
226− ).arg(
227− Arg::with_name("color")
228− .long("color")
229− .overrides_with("color")
230− .takes_value(true)
231− .value_name("when")
232− .possible_values(&["auto", "never", "always"])
233− .default_value("auto")
234− .help("When to use colors.")
235− .long_help("Specify when to use colored output. The automatic mode \
225+ ),
226+ ).arg(
227+ Arg::with_name("color")
228+ .long("color")
229+ .overrides_with("color")
230+ .takes_value(true)
231+ .value_name("when")
232+ .possible_values(&["auto", "never", "always"])
233+ .default_value("auto")
234+ .help("When to use colors.")
235+ .long_help("Specify when to use colored output. The automatic mode \
236236 only enables colors if an interactive terminal is detected."),
237− ).arg(
238− Arg::with_name("decorations")
239− .long("decorations")
240− .overrides_with("decorations")
241− .takes_value(true)
242− .value_name("when")
243− .possible_values(&["auto", "never", "always"])
244− .default_value("auto")
245− .help("When to show the decorations specified by '--style'.")
246− .long_help("Specify when to use the decorations that have been specified \
237+ ).arg(
238+ Arg::with_name("decorations")
239+ .long("decorations")
240+ .overrides_with("decorations")
241+ .takes_value(true)
242+ .value_name("when")
243+ .possible_values(&["auto", "never", "always"])
244+ .default_value("auto")
245+ .help("When to show the decorations specified by '--style'.")
246+ .long_help("Specify when to use the decorations that have been specified \
247247 via '--style'. The automatic mode only enables decorations if \
248248 an interactive terminal is detected."),
249− ).arg(
250− Arg::with_name("paging")
251− .long("paging")
252− .overrides_with("paging")
253− .takes_value(true)
254− .value_name("when")
255− .possible_values(&["auto", "never", "always"])
256− .default_value("auto")
257− .help("Specify when to use the pager.")
258− .long_help("Specify when to use the pager. To control which pager \
249+ ).arg(
250+ Arg::with_name("paging")
251+ .long("paging")
252+ .overrides_with("paging")
253+ .takes_value(true)
254+ .value_name("when")
255+ .possible_values(&["auto", "never", "always"])
256+ .default_value("auto")
257+ .help("Specify when to use the pager.")
258+ .long_help("Specify when to use the pager. To control which pager \
259259 is used, set the PAGER or BAT_PAGER environment \
260260 variables (the latter takes precedence). The default \
261261 pager is 'less'. To disable the pager permanently, set \
262262 BAT_PAGER to an empty string."),
263− ).arg(
264− Arg::with_name("wrap")
265− .long("wrap")
266− .overrides_with("wrap")
267− .takes_value(true)
268− .value_name("mode")
269− .possible_values(&["auto", "never", "character"])
270− .default_value("auto")
271− .help("Specify the text-wrapping mode.")
272− .long_help("Specify the text-wrapping mode."),
273− ).arg(
274− Arg::with_name("unbuffered")
275− .short("u")
276− .hidden_short_help(true)
277− .long_help(
278− "This option exists for POSIX-compliance reasons ('u' is for \
263+ ).arg(
264+ Arg::with_name("wrap")
265+ .long("wrap")
266+ .overrides_with("wrap")
267+ .takes_value(true)
268+ .value_name("mode")
269+ .possible_values(&["auto", "never", "character"])
270+ .default_value("auto")
271+ .help("Specify the text-wrapping mode.")
272+ .long_help("Specify the text-wrapping mode."),
273+ ).arg(
274+ Arg::with_name("unbuffered")
275+ .short("u")
276+ .hidden_short_help(true)
277+ .long_help(
278+ "This option exists for POSIX-compliance reasons ('u' is for \
279279 'unbuffered'). The output is always unbuffered - this option \
280280 is simply ignored.",
281− ),
281+ ),
282+ ).arg(
283+ Arg::with_name("tabs")
284+ .long("tabs")
285+ .short("t")
286+ .takes_value(true)
287+ .value_name("width")
288+ .help("Sets the tab width.")
289+ .long_help("Sets the tab width. Use a width of 0 to pass tabs through \
290+ directly"),
291+ ).arg(
292+ Arg::with_name("terminal-width")
293+ .long("terminal-width")
294+ .takes_value(true)
295+ .value_name("width")
296+ .hidden(true)
297+ .help("Set the width of the terminal"),
298+ ).subcommand(
299+ SubCommand::with_name("cache")
300+ .about("Modify the syntax-definition and theme cache")
301+ .arg(
302+ Arg::with_name("init")
303+ .long("init")
304+ .short("i")
305+ .help("Initialize the syntax/theme cache.")
306+ .long_help(
307+ "Initialize the syntax/theme cache by loading from the \
308+ source directory (default: the configuration directory).",
309+ ),
310+ ).arg(
311+ Arg::with_name("clear")
312+ .long("clear")
313+ .short("c")
314+ .help("Remove the cached syntax definitions and themes."),
315+ ).arg(
316+ Arg::with_name("config-dir")
317+ .long("config-dir")
318+ .short("d")
319+ .help("Show bat's configuration directory."),
320+ ).group(
321+ ArgGroup::with_name("cache-actions")
322+ .args(&["init", "clear", "config-dir"])
323+ .required(arg_group_required),
282324 ).arg(
283− Arg::with_name("tabs")
284− .long("tabs")
285− .short("t")
325+ Arg::with_name("source")
326+ .long("source")
327+ .requires("init")
286328 .takes_value(true)
287− .value_name("width")
288− .help("Sets the tab width.")
289− .long_help("Sets the tab width. Use a width of 0 to pass tabs through \
290− directly"),
329+ .value_name("dir")
330+ .help("Use a different directory to load syntaxes and themes from."),
291331 ).arg(
292− Arg::with_name("terminal-width")
293− .long("terminal-width")
332+ Arg::with_name("target")
333+ .long("target")
334+ .requires("init")
294335 .takes_value(true)
295− .value_name("width")
296− .hidden(true)
297− .help("Set the width of the terminal"),
298− ).subcommand(
299− SubCommand::with_name("cache")
300− .about("Modify the syntax-definition and theme cache")
301− .arg(
302− Arg::with_name("init")
303− .long("init")
304− .short("i")
305− .help("Initialize the syntax/theme cache.")
306− .long_help(
307− "Initialize the syntax/theme cache by loading from the \
308− source directory (default: the configuration directory).",
309− ),
310− ).arg(
311− Arg::with_name("clear")
312− .long("clear")
313− .short("c")
314− .help("Remove the cached syntax definitions and themes."),
315− ).arg(
316− Arg::with_name("config-dir")
317− .long("config-dir")
318− .short("d")
319− .help("Show bat's configuration directory."),
320− ).group(
321− ArgGroup::with_name("cache-actions")
322− .args(&["init", "clear", "config-dir"])
323− .required(arg_group_required),
324− ).arg(
325− Arg::with_name("source")
326− .long("source")
327− .requires("init")
328− .takes_value(true)
329− .value_name("dir")
330− .help("Use a different directory to load syntaxes and themes from."),
331− ).arg(
332− Arg::with_name("target")
333− .long("target")
334− .requires("init")
335− .takes_value(true)
336− .value_name("dir")
337− .help(
338− "Use a different directory to store the cached syntax and theme set.",
339− ),
340− ).arg(
341− Arg::with_name("blank")
342− .long("blank")
343− .requires("init")
344− .help("Create completely new syntax and theme sets \
345− (instead of appending to the default sets).")
336+ .value_name("dir")
337+ .help(
338+ "Use a different directory to store the cached syntax and theme set.",
346339 ),
347− ).help_message("Print this help message.")
340+ ).arg(
341+ Arg::with_name("blank")
342+ .long("blank")
343+ .requires("init")
344+ .help("Create completely new syntax and theme sets \
345+ (instead of appending to the default sets).")
346+ ),
347+ ).help_message("Print this help message.")
348348 .version_message("Show version information.")
349349 .get_matches()
350350 }
@@ -353,6 +353,27 @@ impl App {
353353 let files = self.files();
354354 let output_components = self.output_components()?;
355355
356+ let paging_mode = match self.matches.value_of("paging") {
357+ Some("always") => PagingMode::Always,
358+ Some("never") => PagingMode::Never,
359+ Some("auto") | _ => if files.contains(&InputFile::StdIn) {
360+ // If we are reading from stdin, only enable paging if we write to an
361+ // interactive terminal and if we do not *read* from an interactive
362+ // terminal.
363+ if self.interactive_output && !atty::is(Stream::Stdin) {
364+ PagingMode::QuitIfOneScreen
365+ } else {
366+ PagingMode::Never
367+ }
368+ } else {
369+ if self.interactive_output {
370+ PagingMode::QuitIfOneScreen
371+ } else {
372+ PagingMode::Never
373+ }
374+ },
375+ };
376+
356377 Ok(Config {
357378 true_color: is_truecolor_terminal(),
358379 language: self.matches.value_of("language"),
@@ -376,26 +397,7 @@ impl App {
376397 Some("never") => false,
377398 Some("auto") | _ => self.interactive_output,
378399 },
379− paging_mode: match self.matches.value_of("paging") {
380− Some("always") => PagingMode::Always,
381− Some("never") => PagingMode::Never,
382− Some("auto") | _ => if files.contains(&InputFile::StdIn) {
383− // If we are reading from stdin, only enable paging if we write to an
384− // interactive terminal and if we do not *read* from an interactive
385− // terminal.
386− if self.interactive_output && !atty::is(Stream::Stdin) {
387− PagingMode::QuitIfOneScreen
388− } else {
389− PagingMode::Never
390− }
391− } else {
392− if self.interactive_output {
393− PagingMode::QuitIfOneScreen
394− } else {
395− PagingMode::Never
396− }
397− },
398− },
400+ paging_mode,
399401 term_width: self
400402 .matches
401403 .value_of("terminal-width")
@@ -410,7 +412,13 @@ impl App {
410412 .value_of("tabs")
411413 .and_then(|w| w.parse().ok())
412414 .or_else(|| env::var("BAT_TABS").ok().and_then(|w| w.parse().ok()))
413− .unwrap_or(8),
415+ .unwrap_or(
416+ if output_components.plain() && paging_mode == PagingMode::Never {
417+ 0
418+ } else {
419+ 8
420+ },
421+ ),
414422 theme: self
415423 .matches
416424 .value_of("theme")