Compare commits

...

21 Commits

Author SHA1 Message Date
John DeBoard 8d8c6bd691
Merge b05cde7ab4 into bb4d1cbd2e 2024-04-23 14:41:21 -04:00
Stéphane Blondon bb4d1cbd2e refactor: factorize constants by inverting loop and condition order 2024-04-19 11:44:47 +02:00
Stéphane Blondon 23ec433167 display which theme is the default one in basic output 2024-04-19 11:44:47 +02:00
Sharun 9eaed3e3f0
[JavaScript] Support bun in shebang for syntax highlighting (#2913)
* [JavaScript] Support bun in shebang for syntax highlighting

---------

Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com>
2024-04-15 06:17:41 +00:00
sblondon d5bd4aa93f
display which theme is the default one in colored output (#2838) 2024-04-14 15:54:52 +02:00
John DeBoard b05cde7ab4
Merge branch 'master' into issue#2561 2024-02-02 09:19:02 -05:00
deboard 2a29029828 Merge branch 'issue#2561' of github.com:deboard/bat into issue#2561 2024-01-22 20:23:35 -05:00
deboard ac4f4b40df Ran cargo fmt. 2024-01-22 20:23:20 -05:00
John DeBoard b1819cb09d
Merge branch 'master' into issue#2561 2024-01-22 20:10:41 -05:00
deboard 10fd0b70e5 Add integration test. 2024-01-22 20:06:41 -05:00
deboard ed6aad7835 Add test. 2024-01-05 23:20:47 -05:00
John DeBoard e5858e27d9
Merge branch 'master' into issue#2561 2024-01-04 10:04:36 -05:00
deboard 1f3e3e0d71 Ammend CHANGELOG... Again... 2024-01-03 05:38:53 -05:00
deboard 635175ea64 Ammend CHANGELOG... Again... 2024-01-03 05:37:56 -05:00
deboard 7ae3185f47 Merge branch 'issue#2561' of github.com:deboard/bat into issue#2561 2024-01-02 19:09:10 -05:00
deboard cb2f8f8210 Ammend CHANGELOG... Again 2024-01-02 19:08:16 -05:00
deboard 76a655da5f Merge branch 'issue#2561' of github.com:deboard/bat into issue#2561 2024-01-02 19:03:02 -05:00
deboard 6a0f6beab6 Ammend CHANGELOG 2024-01-02 19:02:26 -05:00
deboard 6b90c21ba3 Merge branch 'issue#2561' of github.com:deboard/bat into issue#2561 2024-01-02 18:01:34 -05:00
deboard 6ea3ac71d7 issue 2561, send all [bat error]s to stderr in default_error_handler
match default.
2024-01-02 17:54:49 -05:00
deboard 54cec4a8e0 issue 2561, send all [bat error]s to stderr in default_error_handler
match default.
2024-01-02 17:44:27 -05:00
6 changed files with 108 additions and 9 deletions

View File

@ -6,10 +6,14 @@
- `bat --squeeze-blank`/`bat -s` will now squeeze consecutive empty lines, see #1441 (@eth-p) and #2665 (@einfachIrgendwer0815)
- `bat --squeeze-limit` to set the maximum number of empty consecutive when using `--squeeze-blank`, see #1441 (@eth-p) and #2665 (@einfachIrgendwer0815)
- `PrettyPrinter::squeeze_empty_lines` to support line squeezing for bat as a library, see #1441 (@eth-p) and #2665 (@einfachIrgendwer0815)
- Syntax highlighting for JavaScript files that start with `#!/usr/bin/env bun` #2913 (@sharunkumar)
## Bugfixes
- Send all bat error messages to stderr, see #2827 (@deboard)
- Fix long file name wrapping in header, see #2835 (@FilipRazek)
-
- Fix `NO_COLOR` support, see #2767 (@acuteenvy)
- Fix handling of inputs with OSC ANSI escape sequences, see #2541 and #2544 (@eth-p)
- Fix handling of inputs with combined ANSI color and attribute sequences, see #2185 and #2856 (@eth-p)
@ -33,6 +37,8 @@
- Relax syntax mapping rule restrictions to allow brace expansion #2865 (@cyqsimon)
- Apply clippy fixes #2864 (@cyqsimon)
- Faster startup by offloading glob matcher building to a worker thread #2868 (@cyqsimon)
- Display which theme is the default one in basic output (no colors), see #2937 (@sblondon)
- Display which theme is the default one in colored output, see #2838 (@sblondon)
## Syntaxes

View File

@ -0,0 +1,14 @@
Submodule assets/syntaxes/01_Packages contains modified content
diff --git syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax
index 05a4fed6..78a7bf55 100644
--- syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax
+++ syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax
@@ -5,7 +5,7 @@ name: JavaScript
file_extensions:
- js
- htc
-first_line_match: ^#!\s*/.*\b(node|js)\b
+first_line_match: ^#!\s*/.*\b(node|bun|js)\b
scope: source.js
variables:
bin_digit: '[01_]'

View File

@ -30,6 +30,7 @@ use directories::PROJECT_DIRS;
use globset::GlobMatcher;
use bat::{
assets::HighlightingAssets,
config::Config,
controller::Controller,
error::*,
@ -199,19 +200,31 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
let stdout = io::stdout();
let mut stdout = stdout.lock();
if config.colored_output {
for theme in assets.themes() {
let default_theme = HighlightingAssets::default_theme();
for theme in assets.themes() {
let default_theme_info = if default_theme == theme {
" (default)"
} else {
""
};
if config.colored_output {
writeln!(
stdout,
"Theme: {}\n",
Style::new().bold().paint(theme.to_string())
"Theme: {}{}\n",
Style::new().bold().paint(theme.to_string()),
default_theme_info
)?;
config.theme = theme.to_string();
Controller::new(&config, &assets)
.run(vec![theme_preview_file()], None)
.ok();
writeln!(stdout)?;
} else {
writeln!(stdout, "{theme}{default_theme_info}")?;
}
}
if config.colored_output {
writeln!(
stdout,
"Further themes can be installed to '{}', \
@ -220,10 +233,6 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
https://github.com/sharkdp/bat#adding-new-themes",
config_dir.join("themes").to_string_lossy()
)?;
} else {
for theme in assets.themes() {
writeln!(stdout, "{theme}")?;
}
}
Ok(())

View File

@ -67,7 +67,15 @@ pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
.ok();
}
_ => {
writeln!(output, "{}: {}", Red.paint("[bat error]"), error).ok();
// default - always write [bat error] to stderr
let stderr = std::io::stderr();
writeln!(
&mut stderr.lock(),
"{}: {}",
Red.paint("[bat error]"),
error
)
.ok();
}
};
}

View File

@ -272,6 +272,41 @@ fn squeeze_limit_line_numbers() {
.stdout(" 1 line 1\n 2 \n 3 \n 4 \n 5 line 5\n 6 \n 7 \n 8 \n 9 \n 10 \n 20 line 20\n 21 line 21\n 22 \n 23 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 28 \n 29 \n 30 line 30\n");
}
#[test]
fn list_themes_with_colors() {
#[cfg(target_os = "macos")]
let default_theme_chunk = "Monokai Extended Light\x1B[0m (default)";
#[cfg(not(target_os = "macos"))]
let default_theme_chunk = "Monokai Extended\x1B[0m (default)";
bat()
.arg("--color=always")
.arg("--list-themes")
.assert()
.success()
.stdout(predicate::str::contains("DarkNeon").normalize())
.stdout(predicate::str::contains(default_theme_chunk).normalize())
.stdout(predicate::str::contains("Output the square of a number.").normalize());
}
#[test]
fn list_themes_without_colors() {
#[cfg(target_os = "macos")]
let default_theme_chunk = "Monokai Extended Light (default)";
#[cfg(not(target_os = "macos"))]
let default_theme_chunk = "Monokai Extended (default)";
bat()
.arg("--color=never")
.arg("--list-themes")
.assert()
.success()
.stdout(predicate::str::contains("DarkNeon").normalize())
.stdout(predicate::str::contains(default_theme_chunk).normalize());
}
#[test]
#[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)]
fn short_help() {
@ -812,6 +847,16 @@ fn env_var_bat_pager_value_bat() {
.stderr(predicate::str::contains("bat as a pager is disallowed"));
}
#[test]
fn bat_error_to_stderr() {
bat()
.env("BAT_PAGER", "bat")
.arg("/tmp")
.assert()
.failure()
.stderr(predicate::str::contains("[bat error]"));
}
#[test]
fn pager_value_bat() {
bat()
@ -1284,6 +1329,9 @@ fn can_print_file_starting_with_cache() {
.stderr("");
}
#[test]
fn send_all_bat_error_to_stderr() {}
#[test]
fn does_not_print_unwanted_file_named_cache() {
bat_with_config().arg("cach").assert().failure();

14
tests/scripts/stderr1.sh Executable file
View File

@ -0,0 +1,14 @@
#!/bin/bash
## test for issue 2561
OUTPUT=$(mktemp)
BAT=bat
code=$($BAT /tmp 2> $OUTPUT; cat $OUTPUT | grep error; echo $?)
if [[ $code == 1 ]]; then
echo "stderr test fsil"
exit 1
fi
exit 0