on master help sign in
Print error message when invalid syntax is specified
35b6067Ethan P
CHANGELOG.md+3
@@ -10,6 +10,9 @@
10- `--map-syntax` doesn't work with names provided through `--file-name` (@eth-p)
10- `--map-syntax` doesn't work with names provided through `--file-name` (@eth-p)
11
11
12## Other
12## Other
13+
14+- bat now prints an error if an invalid syntax is specified (@sharkdp)
15+
13## New syntaxes
16## New syntaxes
14## New themes
17## New themes
15## `bat` as a library
18## `bat` as a library
src/controller.rs+1−1
@@ -121,7 +121,7 @@ impl<'b> Controller<'b> {
121 &mut opened_input,
121 &mut opened_input,
122 #[cfg(feature = "git")]
122 #[cfg(feature = "git")]
123 &line_changes,
123 &line_changes,
124− ))
124+ )?)
125 };
125 };
126
126
127 let result = self.print_file(
127 let result = self.print_file(
src/printer.rs+10−6
@@ -112,7 +112,7 @@ impl<'a> InteractivePrinter<'a> {
112 assets: &'a HighlightingAssets,
112 assets: &'a HighlightingAssets,
113 input: &mut OpenedInput,
113 input: &mut OpenedInput,
114 #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
114 #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
115− ) -> Self {
115+ ) -> Result<Self> {
116 let theme = assets.get_theme(&config.theme);
116 let theme = assets.get_theme(&config.theme);
117
117
118 let background_color_highlight = theme.settings.line_highlight;
118 let background_color_highlight = theme.settings.line_highlight;
@@ -164,14 +164,18 @@ impl<'a> InteractivePrinter<'a> {
164 None
164 None
165 } else {
165 } else {
166 // Determine the type of syntax for highlighting
166 // Determine the type of syntax for highlighting
167− let syntax = assets
168− .get_syntax(config.language, input, &config.syntax_mapping)
167+ let syntax = match assets.get_syntax(config.language, input, &config.syntax_mapping) {
168+ Ok(syntax) => syntax,
169+ Err(Error(ErrorKind::UndetectedSyntax(_), _)) => {
169− .unwrap_or_else(|_| assets.syntax_set.find_syntax_plain_text());
170+ assets.syntax_set.find_syntax_plain_text()
171+ }
172+ Err(e) => return Err(e),
173+ };
170
174
171 Some(HighlightLines::new(syntax, theme))
175 Some(HighlightLines::new(syntax, theme))
172 };
176 };
173
177
174− InteractivePrinter {
178+ Ok(InteractivePrinter {
175 panel_width,
179 panel_width,
176 colors,
180 colors,
177 config,
181 config,
@@ -183,7 +187,7 @@ impl<'a> InteractivePrinter<'a> {
183 highlighter,
187 highlighter,
184 syntax_set: &assets.syntax_set,
188 syntax_set: &assets.syntax_set,
185 background_color_highlight,
189 background_color_highlight,
186− }
190+ })
187 }
191 }
188
192
189 fn print_horizontal_line(&mut self, handle: &mut dyn Write, grid_char: char) -> Result<()> {
193 fn print_horizontal_line(&mut self, handle: &mut dyn Write, grid_char: char) -> Result<()> {