Compare commits

..

30 Commits

Author SHA1 Message Date
Tau Gärtli 1819030368
Merge 4409c56754 into 9eaed3e3f0 2024-04-16 12:46:06 +00:00
Tau Gärtli 4409c56754
Use new `default_theme` fn for --list-themes 2024-04-16 14:43:50 +02:00
Tau Gärtli 1c6d40f562
Document breaking change in library 2024-04-16 14:43:48 +02:00
Tau Gärtli e6afa13ef4
Update terminal-colorsaurus (again) 2024-04-16 14:43:46 +02:00
Tau Gärtli c34a350ef0
Add changelog entry 2024-04-16 14:43:44 +02:00
Tau Gärtli 61132ddf9e
Disable color detection in test 2024-04-16 14:43:42 +02:00
Tau Gärtli e1602d79bc
Update readme 2024-04-16 14:43:39 +02:00
Tau Gärtli 547f30bec0
Update terminal-colorsaurus 2024-04-16 14:43:37 +02:00
Tau Gärtli 7d31a559ec
Remove cargo feature 2024-04-16 14:43:35 +02:00
Tau Gärtli 360f95be61
Improve upon the documentation 2024-04-16 14:43:33 +02:00
Tau Gärtli e72a95f3ab
Move actual detection into library 2024-04-16 14:43:31 +02:00
Tau Gärtli 19488dbf91
Remove HighlightingAssets::default_theme() 2024-04-16 14:43:29 +02:00
Tau Gärtli 0934558252
Add generated powershell completion to ignore list 2024-04-16 14:43:27 +02:00
Tau Gärtli eb974fe11a
Update completions and man page 2024-04-16 14:43:24 +02:00
Tau Gärtli 4b1b600994
Expose new theme selection in CLI 2024-04-16 14:43:22 +02:00
Tau Gärtli 85335f76eb
Use `default_theme()` function from theme module 2024-04-16 14:43:20 +02:00
Tau Gärtli b9b04164d1
Deprecate old `default_theme` function 2024-04-16 14:43:18 +02:00
Tau Gärtli 1999fa2303
Choose theme based on the terminal's color scheme 2024-04-16 14:43:16 +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
Keith Hall 66b70dd8ed
Merge pull request #2933 from vorburger/patch-1
Fix minor typo in GitHub Syntax Request Issue Template
2024-04-09 21:35:45 +03:00
Michael Vorburger 01731478a6
Fix minor typo in GitHub Syntax Request Issue Template 2024-04-09 19:54:46 +02:00
Rivera Calzadillas f8c5429a6c Print $TERM with --diagnostic 2024-04-07 14:24:16 +02:00
Rivera Calzadillas f71226adbb Sort env vars printed by --diagnostic 2024-04-07 14:24:16 +02:00
一个不知名の睡觉高手 e8d777b73a fix: some typos 2024-04-04 06:01:37 +02:00
dependabot[bot] 3cff44b652
Bump console from 0.15.7 to 0.15.8 (#2925)
Bumps [console](https://github.com/console-rs/console) from 0.15.7 to 0.15.8.
- [Changelog](https://github.com/console-rs/console/blob/master/CHANGELOG.md)
- [Commits](https://github.com/console-rs/console/compare/0.15.7...0.15.8)

---
updated-dependencies:
- dependency-name: console
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 04:11:21 +00:00
dependabot[bot] 26302a8b08
Bump serde from 1.0.193 to 1.0.197 (#2926)
Bumps [serde](https://github.com/serde-rs/serde) from 1.0.193 to 1.0.197.
- [Release notes](https://github.com/serde-rs/serde/releases)
- [Commits](https://github.com/serde-rs/serde/compare/v1.0.193...v1.0.197)

---
updated-dependencies:
- dependency-name: serde
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 03:58:57 +00:00
dependabot[bot] adc5bd0402
Bump serde_with from 3.6.1 to 3.7.0 (#2923)
Bumps [serde_with](https://github.com/jonasbb/serde_with) from 3.6.1 to 3.7.0.
- [Release notes](https://github.com/jonasbb/serde_with/releases)
- [Commits](https://github.com/jonasbb/serde_with/compare/v3.6.1...v3.7.0)

---
updated-dependencies:
- dependency-name: serde_with
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 03:44:58 +00:00
dependabot[bot] e3c3be950a
Bump predicates from 3.0.4 to 3.1.0 (#2924)
Bumps [predicates](https://github.com/assert-rs/predicates-rs) from 3.0.4 to 3.1.0.
- [Changelog](https://github.com/assert-rs/predicates-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/assert-rs/predicates-rs/compare/v3.0.4...v3.1.0)

---
updated-dependencies:
- dependency-name: predicates
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 03:30:00 +00:00
dependabot[bot] 8d92dc2083
Bump wild from 2.2.0 to 2.2.1 (#2922)
Bumps [wild](https://gitlab.com/kornelski/wild) from 2.2.0 to 2.2.1.
- [Commits](https://gitlab.com/kornelski/wild/compare/v2.2.0...v2.2.1)

---
updated-dependencies:
- dependency-name: wild
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-04-01 03:11:04 +00:00
9 changed files with 90 additions and 48 deletions

View File

@ -26,4 +26,4 @@ guidelines for adding new syntaxes:
[Name or description of the syntax/language here]
**Guideline Criteria:**
[packagecontro.io link here]
[packagecontrol.io link here]

View File

@ -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)
- Automatically choose theme based on the terminal's color scheme, see #2896 (@bash)
## Bugfixes
@ -34,6 +35,7 @@
- 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 colored output, see #2838 (@sblondon)
## Syntaxes

50
Cargo.lock generated
View File

@ -130,7 +130,7 @@ dependencies = [
"grep-cli",
"home",
"indexmap",
"itertools 0.12.1",
"itertools",
"nix",
"nu-ansi-term",
"once_cell",
@ -293,15 +293,15 @@ checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]]
name = "console"
version = "0.15.7"
version = "0.15.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8"
checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"unicode-width",
"windows-sys 0.45.0",
"windows-sys 0.52.0",
]
[[package]]
@ -657,15 +657,6 @@ dependencies = [
"serde",
]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.12.1"
@ -939,14 +930,13 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "predicates"
version = "3.0.4"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6dfc28575c2e3f19cb3c73b93af36460ae898d426eba6fc15b9bd2a5220758a0"
checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8"
dependencies = [
"anstyle",
"difflib",
"float-cmp",
"itertools 0.11.0",
"normalize-line-endings",
"predicates-core",
"regex",
@ -970,9 +960,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.78"
version = "1.0.79"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e"
dependencies = [
"unicode-ident",
]
@ -1138,18 +1128,18 @@ checksum = "b97ed7a9823b74f99c7742f5336af7be5ecd3eeafcb1507d1fa93347b1d589b0"
[[package]]
name = "serde"
version = "1.0.193"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "25dd9975e68d0cb5aa1120c288333fc98731bd1dd12f561e468ea4728c042b89"
checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.193"
version = "1.0.197"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3"
checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
dependencies = [
"proc-macro2",
"quote",
@ -1178,9 +1168,9 @@ dependencies = [
[[package]]
name = "serde_with"
version = "3.6.1"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15d167997bd841ec232f5b2b8e0e26606df2e7caa4c31b95ea9ca52b200bd270"
checksum = "ee80b0e361bbf88fd2f6e242ccd19cfda072cb0faa6ae694ecee08199938569a"
dependencies = [
"serde",
"serde_derive",
@ -1189,9 +1179,9 @@ dependencies = [
[[package]]
name = "serde_with_macros"
version = "3.6.1"
version = "3.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "865f9743393e638991566a8b7a479043c2c8da94a33e0a31f18214c9cae0a64d"
checksum = "6561dc161a9224638a31d876ccdfefbc1df91d3f3a8342eddb35f055d48c7655"
dependencies = [
"darling",
"proc-macro2",
@ -1267,9 +1257,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
version = "2.0.52"
version = "2.0.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
checksum = "11a6ae1e52eb25aab8f3fb9fca13be982a373b8f1157ca14b897a825ba4a2d35"
dependencies = [
"proc-macro2",
"quote",
@ -1554,9 +1544,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "wild"
version = "2.2.0"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10d01931a94d5a115a53f95292f51d316856b68a035618eb831bbba593a30b67"
checksum = "a3131afc8c575281e1e80f36ed6a092aa502c08b18ed7524e86fbbb12bb410e1"
dependencies = [
"glob",
]

View File

@ -44,7 +44,7 @@ regex-fancy = ["syntect/regex-fancy"] # Use the rust-only "fancy-regex" engine
nu-ansi-term = "0.50.0"
ansi_colours = "^1.2"
bincode = "1.0"
console = "0.15.7"
console = "0.15.8"
flate2 = "1.0"
once_cell = "1.19"
thiserror = "1.0"
@ -93,7 +93,7 @@ plist = "1.6.0"
assert_cmd = "2.0.12"
expect-test = "1.4.1"
serial_test = { version = "2.0.0", default-features = false }
predicates = "3.0.4"
predicates = "3.1.0"
wait-timeout = "0.2.0"
tempfile = "3.8.1"
serde = { version = "1.0", features = ["derive"] }
@ -109,7 +109,7 @@ once_cell = "1.18"
regex = "1.10.2"
serde = "1.0"
serde_derive = "1.0"
serde_with = { version = "3.6.1", default-features = false, features = ["macros"] }
serde_with = { version = "3.7.0", default-features = false, features = ["macros"] }
toml = { version = "0.8.9", features = ["preserve_order"] }
walkdir = "2.4"

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

@ -412,7 +412,7 @@ bat --list-themes | fzf --preview="bat --theme={} --color=always /path/to/file"
### 输出样式
你可以用`--style`参数来控制`bat`输出的样式。使用`--style=numbers,chanegs`可以只开启 Git 修改和行号显示而不添加其他内容。`BAT_STYLE`环境变量具有相同功能。
你可以用`--style`参数来控制`bat`输出的样式。使用`--style=numbers,changes`可以只开启 Git 修改和行号显示而不添加其他内容。`BAT_STYLE`环境变量具有相同功能。
### 添加新的语言和语法

View File

@ -35,7 +35,7 @@ use bat::{
error::*,
input::Input,
style::{StyleComponent, StyleComponents},
MappingTarget, PagingMode,
theme, MappingTarget, PagingMode,
};
const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs");
@ -200,11 +200,23 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
let mut stdout = stdout.lock();
if config.colored_output {
use theme::{color_scheme, default_theme, ColorScheme, DetectColorScheme};
let default_theme = default_theme(color_scheme(DetectColorScheme::Auto));
for theme in assets.themes() {
let default_theme_info = if default_theme == theme {
" (default)"
} else if theme::default_theme(ColorScheme::Dark) == theme {
" (default dark)"
} else if theme::default_theme(ColorScheme::Light) == theme {
" (default light)"
} else {
""
};
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)
@ -272,24 +284,25 @@ fn invoke_bugreport(app: &App, cache_dir: &Path) {
.info(OperatingSystem::default())
.info(CommandLine::default())
.info(EnvironmentVariables::list(&[
"SHELL",
"PAGER",
"LESS",
"LANG",
"LC_ALL",
"BAT_PAGER",
"BAT_PAGING",
"BAT_CACHE_PATH",
"BAT_CONFIG_PATH",
"BAT_OPTS",
"BAT_PAGER",
"BAT_PAGING",
"BAT_STYLE",
"BAT_TABS",
"BAT_THEME",
"XDG_CONFIG_HOME",
"XDG_CACHE_HOME",
"COLORTERM",
"NO_COLOR",
"LANG",
"LC_ALL",
"LESS",
"MANPAGER",
"NO_COLOR",
"PAGER",
"SHELL",
"TERM",
"XDG_CACHE_HOME",
"XDG_CONFIG_HOME",
]))
.info(FileContent::new("System Config file", system_config_file()))
.info(FileContent::new("Config file", config_file()))

View File

@ -19,6 +19,11 @@ pub const fn default_theme(color_scheme: ColorScheme) -> &'static str {
}
}
/// Detects the color scheme from the terminal.
pub fn color_scheme(when: DetectColorScheme) -> ColorScheme {
detect(when, &TerminalColorSchemeDetector).unwrap_or_default()
}
/// Options for configuring the theme used for syntax highlighting.
/// Used together with [`theme`].
#[derive(Debug, Default, PartialEq, Eq)]

View File

@ -272,6 +272,24 @@ 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() {
#[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]
#[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)]
fn short_help() {