summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md3
-rw-r--r--assets/patches/JavaScript.sublime-syntax.patch14
-rw-r--r--src/bin/bat/main.rs25
-rw-r--r--tests/integration_tests.rs35
4 files changed, 69 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7ebdc55..28e56e34 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@
- `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
@@ -33,6 +34,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
diff --git a/assets/patches/JavaScript.sublime-syntax.patch b/assets/patches/JavaScript.sublime-syntax.patch
new file mode 100644
index 00000000..9ab89d1d
--- /dev/null
+++ b/assets/patches/JavaScript.sublime-syntax.patch
@@ -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_]'
diff --git a/src/bin/bat/main.rs b/src/bin/bat/main.rs
index 615f1114..4528a60b 100644
--- a/src/bin/bat/main.rs
+++ b/src/bin/bat/main.rs
@@ -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(())
diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs
index d6523366..0285ac26 100644
--- a/tests/integration_tests.rs
+++ b/tests/integration_tests.rs
@@ -273,6 +273,41 @@ fn squeeze_limit_line_numbers() {
}
#[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() {
test_help("-h", "../doc/short-help.txt");