Skip to content

Commit 01b7ac6

Browse files
authored
Merge pull request #3413 from sharkdp/ansi_theme_json
Update ansi theme to highlight JSON keys separately from string values
2 parents 6c89291 + aa1c4fb commit 01b7ac6

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
- Updated Catppuccin, see #3333 (@SchweGELBin)
7070
- Updated gruvbox, see #3372 (@Nicholas42)
7171
- Updated GitHub theme, see #3382 (@CosmicHorrorDev)
72+
- Updated ANSI theme to highlight JSON object keys differently from values, see #3413 (@keith-hall)
7273

7374
## `bat` as a library
7475

assets/themes.bin

-17 KB
Binary file not shown.

assets/themes/ansi.tmTheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@
234234
<key>name</key>
235235
<string>Headings</string>
236236
<key>scope</key>
237-
<string>markup.heading punctuation.definition.heading, entity.name.section, markup.heading - text.html.markdown</string>
237+
<string>markup.heading punctuation.definition.heading, entity.name.section, markup.heading - text.html.markdown, meta.mapping.key string.quoted.double</string>
238238
<key>settings</key>
239239
<dict>
240240
<key>fontStyle</key>

tests/integration_tests.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,24 @@ fn ansi_highlight_underline() {
24042404
.stderr("");
24052405
}
24062406

2407+
// we don't really test other color schemes in the syntax-tests/source vs highlighted stuff
2408+
// so here a simple integration test has been made for the ANSI theme,
2409+
// which lives directly inside the bat repository
2410+
#[test]
2411+
fn ansi_highlight_json_keys() {
2412+
bat()
2413+
.arg("--paging=never")
2414+
.arg("--color=always")
2415+
.arg("--decorations=never")
2416+
.arg("--theme=ansi")
2417+
.arg("--language=json")
2418+
.write_stdin("{\"foo\": \"bar\", \"test\": [123, \"baz\"] }")
2419+
.assert()
2420+
.success()
2421+
.stdout("{\x1B[34m\"\x1B[0m\x1B[34mfoo\x1B[0m\x1B[34m\"\x1B[0m: \x1B[32m\"\x1B[0m\x1B[32mbar\x1B[0m\x1B[32m\"\x1B[0m, \x1B[34m\"\x1B[0m\x1B[34mtest\x1B[0m\x1B[34m\"\x1B[0m: [\x1B[33m123\x1B[0m, \x1B[32m\"\x1B[0m\x1B[32mbaz\x1B[0m\x1B[32m\"\x1B[0m] }")
2422+
.stderr("");
2423+
}
2424+
24072425
// Ensure that ANSI passthrough is emitted properly for both wrapping and non-wrapping printer.
24082426
// See https://github.com/sharkdp/bat/issues/2307 for what common use case this test tests.
24092427
#[test]

0 commit comments

Comments
 (0)