on master help sign in
Print error message when invalid syntax is specified
commit35b60674962dcc5b0b09d121aa667c0d2c34d813 authorEthan P <eth-p+git@hidden.email> dateSat 16 May 2020, 02:42 (6 years ago) parent5aa20c0
3 files changed+14−7
CHANGELOG.md+3 src/controller.rs+1−1 src/printer.rs+10−6
CHANGELOG.md+3
@@ -10,6 +10,9 @@
1010- `--map-syntax` doesn't work with names provided through `--file-name` (@eth-p)
1111
1212## Other
13+
14+- bat now prints an error if an invalid syntax is specified (@sharkdp)
15+
1316## New syntaxes
1417## New themes
1518## `bat` as a library
src/controller.rs+1−1
@@ -121,7 +121,7 @@ impl<'b> Controller<'b> {
121121 &mut opened_input,
122122 #[cfg(feature = "git")]
123123 &line_changes,
124− ))
124+ )?)
125125 };
126126
127127 let result = self.print_file(
src/printer.rs+10−6
@@ -112,7 +112,7 @@ impl<'a> InteractivePrinter<'a> {
112112 assets: &'a HighlightingAssets,
113113 input: &mut OpenedInput,
114114 #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
115− ) -> Self {
115+ ) -> Result<Self> {
116116 let theme = assets.get_theme(&config.theme);
117117
118118 let background_color_highlight = theme.settings.line_highlight;
@@ -164,14 +164,18 @@ impl<'a> InteractivePrinter<'a> {
164164 None
165165 } else {
166166 // Determine the type of syntax for highlighting
167− let syntax = assets
168− .get_syntax(config.language, input, &config.syntax_mapping)
169− .unwrap_or_else(|_| assets.syntax_set.find_syntax_plain_text());
167+ let syntax = match assets.get_syntax(config.language, input, &config.syntax_mapping) {
168+ Ok(syntax) => syntax,
169+ Err(Error(ErrorKind::UndetectedSyntax(_), _)) => {
170+ assets.syntax_set.find_syntax_plain_text()
171+ }
172+ Err(e) => return Err(e),
173+ };
170174
171175 Some(HighlightLines::new(syntax, theme))
172176 };
173177
174− InteractivePrinter {
178+ Ok(InteractivePrinter {
175179 panel_width,
176180 colors,
177181 config,
@@ -183,7 +187,7 @@ impl<'a> InteractivePrinter<'a> {
183187 highlighter,
184188 syntax_set: &assets.syntax_set,
185189 background_color_highlight,
186− }
190+ })
187191 }
188192
189193 fn print_horizontal_line(&mut self, handle: &mut dyn Write, grid_char: char) -> Result<()> {