mirror of
https://github.com/sharkdp/bat.git
synced 2026-11-18 04:05:54 +00:00
Compare commits
225
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c59b7853c4 | ||
|
|
fbd9a416e8 | ||
|
|
2c6bc33b43 | ||
|
|
2b3d6badda | ||
|
|
599c3835f1 | ||
|
|
87837d34d6 | ||
|
|
b198f1d93b | ||
|
|
c64b4b5f39 | ||
|
|
764f88a9a9 | ||
|
|
1ac519484b | ||
|
|
6dc5f57a0e | ||
|
|
311969b1f1 | ||
|
|
63ed796b0a | ||
|
|
38c77af14b | ||
|
|
3aa7ebb7ed | ||
|
|
914971d199 | ||
|
|
49acf7a766 | ||
|
|
e3dfca34cc | ||
|
|
e11fb0813e | ||
|
|
5810781fa2 | ||
|
|
dbabbdda1b | ||
|
|
5c2163c9c2 | ||
|
|
03bf655bf8 | ||
|
|
bdd77b9fb1 | ||
|
|
8cf33bdde9 | ||
|
|
120fa5258e | ||
|
|
6561174ab8 | ||
|
|
833a1a7647 | ||
|
|
c231941daa | ||
|
|
5dd9196bef | ||
|
|
c89e356840 | ||
|
|
7187ec3c02 | ||
|
|
a691ab6c74 | ||
|
|
3e58878e43 | ||
|
|
1b92cd272b | ||
|
|
d14e46c393 | ||
|
|
903808ea3e | ||
|
|
4701d15bc5 | ||
|
|
408801f2a7 | ||
|
|
3c8ca42bbc | ||
|
|
ba5fac9c29 | ||
|
|
956522a359 | ||
|
|
b843b05927 | ||
|
|
ed4cb7e2e9 | ||
|
|
b47e686563 | ||
|
|
a9d75b780b | ||
|
|
5bdd8e2800 | ||
|
|
3e2eb6f9a8 | ||
|
|
cbdad20b48 | ||
|
|
b2ef386d0b | ||
|
|
3dba15138d | ||
|
|
87c8610ffb | ||
|
|
73676df96d | ||
|
|
a0fd127e1e | ||
|
|
4cbcb2fdbf | ||
|
|
b2cb0352f8 | ||
|
|
c83792cfba | ||
|
|
94e9ae480c | ||
|
|
ac510bb19c | ||
|
|
0e8994a3f5 | ||
|
|
ad3f336f76 | ||
|
|
41931bc4ad | ||
|
|
78f54b3fee | ||
|
|
d9479df104 | ||
|
|
d19cca2349 | ||
|
|
46031658a0 | ||
|
|
b99f3176f9 | ||
|
|
5f971d9a40 | ||
|
|
599bae4594 | ||
|
|
d6a2958df2 | ||
|
|
67e2ec24e0 | ||
|
|
d0920557da | ||
|
|
cb6bb8eb03 | ||
|
|
1752596aa1 | ||
|
|
46eacfbbb8 | ||
|
|
d389ea3869 | ||
|
|
0db13cbd37 | ||
|
|
673bac99eb | ||
|
|
6ca658c80a | ||
|
|
6b2e311d79 | ||
|
|
1a2189789f | ||
|
|
57160c1bdd | ||
|
|
b5281b5a4f | ||
|
|
e95c32b6f0 | ||
|
|
f059c8da38 | ||
|
|
9507f53270 | ||
|
|
42a60bcce2 | ||
|
|
0318353e9d | ||
|
|
7df6406ca9 | ||
|
|
8f5727ea38 | ||
|
|
b4fdcec6a1 | ||
|
|
f06fd51c5a | ||
|
|
fe901f5051 | ||
|
|
3e2c1bdc8e | ||
|
|
e423744a7d | ||
|
|
445608e4e6 | ||
|
|
135582e99b | ||
|
|
e0af722689 | ||
|
|
26899e31cf | ||
|
|
41100fffcf | ||
|
|
9a633511a8 | ||
|
|
a9aa73d215 | ||
|
|
f0a58595bd | ||
|
|
2fd71ad588 | ||
|
|
49d9ac1d6e | ||
|
|
54b1f9c6af | ||
|
|
b841eadf09 | ||
|
|
c199cc427a | ||
|
|
f3cc4b6f03 | ||
|
|
62db8f51b4 | ||
|
|
4475d88b47 | ||
|
|
b49aae8b1f | ||
|
|
f748c1a467 | ||
|
|
d3afbaeb06 | ||
|
|
dbe6ec265d | ||
|
|
bc0a67e07c | ||
|
|
fca6c542d4 | ||
|
|
c2adbf6caa | ||
|
|
fef8513f6e | ||
|
|
61340f0e42 | ||
|
|
f48149b119 | ||
|
|
ca5eeb7c2a | ||
|
|
9438a74e6d | ||
|
|
8c63b37205 | ||
|
|
d50b53d0ef | ||
|
|
62b439dae3 | ||
|
|
e8d05da87a | ||
|
|
edd161aefb | ||
|
|
b95f8d37bf | ||
|
|
0e3074cfe1 | ||
|
|
4d916905d1 | ||
|
|
c47a163f4b | ||
|
|
a56bca503b | ||
|
|
164902d69b | ||
|
|
ec3f691a53 | ||
|
|
d9559c69f5 | ||
|
|
6c779b38c2 | ||
|
|
78ea14bd9a | ||
|
|
6ae020f998 | ||
|
|
12cbb20de4 | ||
|
|
a9b112b6fe | ||
|
|
5dbfe7fea3 | ||
|
|
4608fc959a | ||
|
|
dcd725dc4e | ||
|
|
4987f76709 | ||
|
|
156ef1d2f4 | ||
|
|
279395d607 | ||
|
|
eca6c5b688 | ||
|
|
7323a7514f | ||
|
|
cf72a432ac | ||
|
|
5b30913c55 | ||
|
|
9fbbfb60ec | ||
|
|
16b5f99d16 | ||
|
|
b784eaf0ae | ||
|
|
2ed8b010af | ||
|
|
5fee86b97b | ||
|
|
66ad54c27d | ||
|
|
2ed7adc49f | ||
|
|
ea3909bbdf | ||
|
|
0acf9417cd | ||
|
|
b5c8e101f8 | ||
|
|
383abc83c8 | ||
|
|
7928b4be52 | ||
|
|
036a201df9 | ||
|
|
2da852dc78 | ||
|
|
65c311e9fb | ||
|
|
b3c9516a9b | ||
|
|
5f12c62b3e | ||
|
|
7892a8754b | ||
|
|
400c5dc6f1 | ||
|
|
1cedc1b4c3 | ||
|
|
b8430080f0 | ||
|
|
a3f202f367 | ||
|
|
b671e53c2c | ||
|
|
de2e651bf5 | ||
|
|
061fb216cb | ||
|
|
af59a32183 | ||
|
|
c63838efeb | ||
|
|
cecbb80093 | ||
|
|
3ca4a01be6 | ||
|
|
8112350da6 | ||
|
|
a5deaf63ff | ||
|
|
2fb2415731 | ||
|
|
a58f23724a | ||
|
|
bb492fff47 | ||
|
|
a96b9e2230 | ||
|
|
531d54b110 | ||
|
|
db69aab106 | ||
|
|
2ba8db9c14 | ||
|
|
d344844486 | ||
|
|
aeb0e4c457 | ||
|
|
1cf12d49bd | ||
|
|
7cb212646c | ||
|
|
6573ca9307 | ||
|
|
f04dc80bc7 | ||
|
|
e6ac6ce08d | ||
|
|
949f18e23a | ||
|
|
969b33dad1 | ||
|
|
73dc3258be | ||
|
|
df38225653 | ||
|
|
c2cc79daa7 | ||
|
|
0230cba42d | ||
|
|
227e0fa00f | ||
|
|
384f2f5d13 | ||
|
|
060ccb1385 | ||
|
|
feabb25209 | ||
|
|
839f2300b7 | ||
|
|
ea0742babc | ||
|
|
bfa6e59978 | ||
|
|
9710a231d8 | ||
|
|
a9b67b2d99 | ||
|
|
b22be63fec | ||
|
|
3a7a750969 | ||
|
|
be5343c742 | ||
|
|
c371044276 | ||
|
|
d449ce5b7e | ||
|
|
71a573e953 | ||
|
|
1449bee283 | ||
|
|
218afc30ac | ||
|
|
78951393e2 | ||
|
|
0a52e4321f | ||
|
|
d72163160e | ||
|
|
971f9679da | ||
|
|
57d436861a | ||
|
|
530e83a455 |
No files matched your search
+15
-11
@@ -166,7 +166,8 @@ jobs:
|
||||
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-latest , dpkg_arch: armhf, use-cross: true }
|
||||
- { target: arm-unknown-linux-musleabihf, os: ubuntu-latest , dpkg_arch: musl-linux-armhf, use-cross: true }
|
||||
- { target: i686-pc-windows-msvc , os: windows-2025 , }
|
||||
- { target: i686-unknown-linux-gnu , os: ubuntu-latest , dpkg_arch: i386, use-cross: true }
|
||||
# The timeout test's socketpair fails on the Ubuntu 26.04 runner.
|
||||
- { target: i686-unknown-linux-gnu , os: ubuntu-24.04 , dpkg_arch: i386, use-cross: true }
|
||||
- { target: i686-unknown-linux-musl , os: ubuntu-latest , dpkg_arch: musl-linux-i686, use-cross: true }
|
||||
- { target: x86_64-apple-darwin , os: macos-15-intel, }
|
||||
- { target: aarch64-apple-darwin , os: macos-latest , }
|
||||
@@ -214,6 +215,9 @@ jobs:
|
||||
|
||||
- name: Build
|
||||
shell: bash
|
||||
env:
|
||||
BAT_ASSETS_GEN_DIR: ${{ env.CICD_INTERMEDIATES_DIR }}/generated
|
||||
CROSS_BUILD_ENV_PASSTHROUGH: BAT_ASSETS_GEN_DIR
|
||||
run: $BUILD_CMD build --locked --release --target=${{ matrix.job.target }}
|
||||
|
||||
- name: Set binary name & path
|
||||
@@ -302,13 +306,13 @@ jobs:
|
||||
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR"
|
||||
|
||||
# Man page
|
||||
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/manual/bat.1 "$ARCHIVE_DIR"
|
||||
cp "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/manual/bat.1" "$ARCHIVE_DIR"
|
||||
|
||||
# Autocompletion files
|
||||
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.bash "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.bash"
|
||||
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.fish "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.fish"
|
||||
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/_bat.ps1 "$ARCHIVE_DIR/autocomplete/_${{ needs.crate_metadata.outputs.name }}.ps1"
|
||||
cp 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.zsh "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.zsh"
|
||||
cp "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/bat.bash" "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.bash"
|
||||
cp "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/bat.fish" "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.fish"
|
||||
cp "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/_bat.ps1" "$ARCHIVE_DIR/autocomplete/_${{ needs.crate_metadata.outputs.name }}.ps1"
|
||||
cp "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/bat.zsh" "$ARCHIVE_DIR/autocomplete/${{ needs.crate_metadata.outputs.name }}.zsh"
|
||||
|
||||
# base compressed package
|
||||
pushd "${PKG_STAGING}/" >/dev/null
|
||||
@@ -343,13 +347,13 @@ jobs:
|
||||
install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}"
|
||||
|
||||
# Man page
|
||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/manual/bat.1 "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||
install -Dm644 "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/manual/bat.1" "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||
gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ needs.crate_metadata.outputs.name }}.1"
|
||||
|
||||
# Autocompletion files
|
||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.bash "${DPKG_DIR}/usr/share/bash-completion/completions/${{ needs.crate_metadata.outputs.name }}"
|
||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.fish "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ needs.crate_metadata.outputs.name }}.fish"
|
||||
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ needs.crate_metadata.outputs.name }}'-*/out/assets/completions/bat.zsh "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ needs.crate_metadata.outputs.name }}"
|
||||
install -Dm644 "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/bat.bash" "${DPKG_DIR}/usr/share/bash-completion/completions/${{ needs.crate_metadata.outputs.name }}"
|
||||
install -Dm644 "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/bat.fish" "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ needs.crate_metadata.outputs.name }}.fish"
|
||||
install -Dm644 "${{ env.CICD_INTERMEDIATES_DIR }}/generated/assets/completions/bat.zsh" "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ needs.crate_metadata.outputs.name }}"
|
||||
|
||||
# README and LICENSE
|
||||
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md"
|
||||
@@ -457,7 +461,7 @@ jobs:
|
||||
needs: build
|
||||
if: startsWith(github.ref, 'refs/tags/v')
|
||||
steps:
|
||||
- uses: vedantmgoyal9/winget-releaser@19e706d4c9121098010096f9c495a70a7518b30f
|
||||
- uses: vedantmgoyal9/winget-releaser@b7370d4d152efdce803a26cc6ca9eee58cb2ad54
|
||||
with:
|
||||
identifier: sharkdp.bat
|
||||
installers-regex: '-pc-windows-msvc\.zip$'
|
||||
|
||||
@@ -284,3 +284,6 @@
|
||||
[submodule "assets/syntaxes/02_Extra/Caddy"]
|
||||
path = assets/syntaxes/02_Extra/Caddy
|
||||
url = https://github.com/caddyserver/sublimetext.git
|
||||
[submodule "assets/syntaxes/02_Extra/CUE"]
|
||||
path = assets/syntaxes/02_Extra/CUE
|
||||
url = https://github.com/cue-lang/vscode-cue.git
|
||||
+51
-7
@@ -1,14 +1,12 @@
|
||||
# unreleased
|
||||
|
||||
|
||||
## Other
|
||||
|
||||
- Add instructions for removing fish help abbreviations to README, see #3655 (@claw-explorer). Closes #3536
|
||||
- Add .NET slnx extension, see #3682 (@ltrzesniewski)
|
||||
# v0.27.0
|
||||
|
||||
## Features
|
||||
|
||||
- Automatically build the syntax/theme cache on first run when custom themes or syntaxes are present but no cache exists yet, so newly installed dotfiles work without a manual `bat cache --build`. Use `--no-custom-assets` to opt out. Closes #4017, see #4038 (@mmustafasenoglu)
|
||||
- Add `-b` / `--number-nonblank` flag to only number non-blank lines, for `cat -b` compatibility. Closes #3856, see #3857 (@MeGaurav4)
|
||||
- Add a `--sanitize=<auto|always|never>` flag for safe display of untrusted input. It substitutes terminal-active control bytes (escape, cursor moves, charset switches, beep, etc.) and Unicode bidi / zero-width formatting characters with the Unicode replacement character (U+FFFD). Mitigates Trojan-Source-style spoofing (CVE-2021-42574). See #3729 (@curious-rabbit)
|
||||
- Map justfile, Justfile, .justfile, and *.justfile to Makefile syntax highlighting, see #3623 (@zachvalenta)
|
||||
- Map `.kube/config` to YAML syntax highlighting, see #3911 (@logarithmone1128)
|
||||
- Preserve `--diff` change markers and snip separators when `--plain` is set. Closes #3630, see #3643 (@mvanhorn)
|
||||
- Added support for `hidden_file_extensions` from `.sublime-syntax` files, see #3613 (@Matei02355)
|
||||
- Add word wrapping mode via `--wrap=word`, see #3597 (@veeceey)
|
||||
@@ -22,6 +20,41 @@
|
||||
- Syntax highlighting for Python files using uv as script runner in shebang #3689 (@janlarres)
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Fix `bat cache --help` returning exit code 1 instead of 0. Remove `.arg_required_else_help(true)` from the cache subcommand and show help when no arguments are provided. See #3798, #3831 and #3837 (@Amilliox)
|
||||
- Fix builtin pager (minus) not responding to search (`/`, `?`, `n`, `N`) and navigation (`PgUp`, `PgDown`, arrows, `g`, `G`) keys. `HashedEventRegister` was overriding all default `minus` bindings instead of extending them. Add `generate_default_bindings()` before custom bindings. See #3831, #3798 and #3837 (@Amilliox)
|
||||
- Build the cache automatically on first run when custom themes or syntaxes are in subdirectories, see #4131 (@NotAFlightRisk)
|
||||
- Do not run filter commands from the configuration of the Git repository that contains the displayed file, see #4127 (@curious-rabbit)
|
||||
- Ignore empty `--ignored-suffix` values to avoid a stack overflow, see #4122 (@spicysharkco)
|
||||
- Fix `--number-nonblank` counting empty UTF-16 lines, see #4118 (@pcbeingused333)
|
||||
- Fix automatic cache build progress polluting stdout, see #4130 (@intertermux-code)
|
||||
- Don't emit `--highlight-line` escape sequences (background color or `ansi` theme underline) when colors are disabled with `--color=never`. Closes #4099, see #4100 (@DeviousCardi)
|
||||
- Fix missing colors, pager, and decorations in mintty/MSYS2 and Cygwin terminals on Windows, see #4115 (@rezamuliawijaya)
|
||||
- Make full-path `--map-syntax` patterns and the built-in `$HOME` and `$XDG_CONFIG_HOME` mappings work on Windows, see #4113 (@b84330808)
|
||||
- Keep configuration and BAT_OPTS active for option-like filenames after `--`, and report invalid configuration for help-like filenames, see #4112 (@Marve10s)
|
||||
- Keep emoji sequences together within text chunks when wrapping content, and measure their combined display width, see #4108 (@Marve10s)
|
||||
- Preserve full-path syntax mappings when removing ignored filename suffixes, see #4111 (@Marve10s)
|
||||
- Fix UTF-16 line splitting at unaligned newline bytes corrupting text and shifting line ranges, see #4110 (@Marve10s)
|
||||
- Respect `NO_COLOR` for the `[bat error]` and `[bat warning]` prefixes, see #4048 (@qodelicious)
|
||||
- Offer the valid `--wrap` value `auto` instead of the rejected `always` in the PowerShell completion, see #4070 (@ump45nose)
|
||||
- Report `BAT_CONFIG_DIR` in `bat --diagnostic`, so bug reports show a config directory that overrides `$XDG_CONFIG_HOME`. See #4068 (@ump45nose)
|
||||
- Ignore a UTF-8 byte order mark at the start of the config file instead of treating it as part of the first argument, see #4103 (@jaeminbird)
|
||||
- Keep backslashes in the pager command on Windows, so `BAT_PAGER=C:\tools\less.exe` is found instead of becoming `C:toolsless.exe`, see #4104 (@jaeminbird)
|
||||
- Fix `bat` hanging forever on JavaScript (and Svelte) code where an expression is followed by a block comment, e.g. `a /* x */`. Closes #4080, see #4091 (@NavpreetSSidhu)
|
||||
- Fix the first line of UTF-16BE input swallowing the second line, which broke line numbers, `--line-range` and highlighting, see #4102 (@cindykrafft)
|
||||
- Exit quietly with status 0 instead of panicking when stdout is closed early (broken pipe) on auxiliary output paths such as `--completion`, `--config-file`, `--diagnostic`, `--generate-config-file`, `--set-terminal-title` and `cache --build`/`--clear`, matching the main output path since #232, closes #4034, see #4035 (@Mathjk)
|
||||
- Fix escape sequence handling in `--strip-ansi` and `--sanitize`. `--sanitize` no longer removes escape sequences, which could hide text, see #4024 (@curious-rabbit)
|
||||
- Track strikethrough (SGR 9 / 29) in the ANSI style tracker so it is re-emitted like bold, dim, italic, and underline, and is no longer dropped after the first highlighted token when displaying ANSI input with syntax highlighting, see #4015 (@mikehasa)
|
||||
- Allow boolean flags to be given more than once, so that a flag set in the config file can also be passed on the command line without erroring, see #3912 (@logarithmone1128)
|
||||
- Allow options that take a value (`--binary`, `--italic-text`, `--nonprintable-notation`, `--fallback-syntax`, `--squeeze-limit`) to be given more than once, so that a value from the config file can be overridden on the command line, see #4102 (@Huang-404-Q)
|
||||
- Use parsed CLI arguments to detect number flags, see #3908 (@cuishuang)
|
||||
- Detect binary content beyond the first line, preventing encrypted files with early line breaks from being treated as text. Closes #3554, see #3877 (@Matei02355)
|
||||
- Use the last occurrence of numbering and plain flags in combined short arguments, see #3897 (@cuishuang)
|
||||
- Avoid a spurious Cargo manifest error during installation from Git, see #3899 (@rootsec1)
|
||||
- Avoid repeated scans of long lines in Log syntax highlighting, see #3876 (@Matei02355)
|
||||
- Fix `--list-languages` respecting `--paging=never`, see #3828 (@cyphercodes)
|
||||
- Fix `--sanitize` passing through the bidi control characters U+200E, U+200F and U+061C, see #3862 (@lenamonj)
|
||||
- `--strip-ansi`: also strip 8-bit C1 introducers (U+0090, U+0098, U+009B, U+009D, U+009E, U+009F) and DCS/SOS/PM/APC sequence bodies, which previously passed through. See #3729 (@curious-rabbit)
|
||||
- Fix `--ignored-suffix` not falling back to first-line/shebang detection when the ignored suffix is also a registered extension (e.g. `--ignored-suffix .txt` on a shebang script), see #2745 and #3816 (@adnrivera)
|
||||
- Fix `capacity overflow` panic when printing a snip separator at `--terminal-width=1` with multiple line ranges. Closes #3803, see #3804 (@leeewee)
|
||||
- Pass `--no-paging` to `bat` invocations inside the bash / zsh / fish / PowerShell shell completion scripts so that shell-level pager wiring (e.g. `LESSOPEN='|-bat -f -pp %s'`) cannot inject ANSI escape sequences into the completion candidates. Closes #3760 (@mvanhorn)
|
||||
@@ -56,6 +89,14 @@
|
||||
- Builtin syntax mapping: cleanup matcher glob parsing logic #3652 (@cyqsimon)
|
||||
- Statically link the CRT for MSVC builds via Cargo config to avoid runtime DLL dependencies. Closes #3634, see #3692 (@barry3406)
|
||||
- Replace `libgit2` with a pure Rust implementation of git called `gitoxide`, see PR #3703 (@blinxen)
|
||||
- Document submodule initialization when rebuilding syntax and theme assets, see #3801 (@xfocus3)
|
||||
- Fix anchor case in `doc/assets.md` links, see #4026 (@ump45nose)
|
||||
- Pin the i686 GNU CI runner to Ubuntu 24.04 to avoid `socketpair` failures on Ubuntu 26.04, see #4101 (@PerchAnton)
|
||||
- Fix dead Visual C++ Redistributable link in README, see #3895 (@1t1sCooL)
|
||||
- Document `StripAnsiMode` and its variants in rustdoc, see #4067 (@ump45nose)
|
||||
- Update Cargo dependencies to resolve current RustSec advisories, see #3861 (@TyceHerrman)
|
||||
- Add instructions for removing fish help abbreviations to README, see #3655 (@claw-explorer). Closes #3536
|
||||
- Add .NET slnx extension, see #3682 (@ltrzesniewski)
|
||||
|
||||
## Syntaxes
|
||||
|
||||
@@ -72,6 +113,8 @@
|
||||
- Add syntax highlighting for `Caddyfile` #3789 (@CosmicHorrorDev)
|
||||
- Include `.code-workspace` as a JSON extension #3809 (@dhruvkb)
|
||||
- Add syntax mapping for DNF repo configuration files, see #3814 (@injust)
|
||||
- Add syntax mapping for Podman `.quadlets` files, see #4069 (@injust)
|
||||
- Add syntax highlighting for CUE, see #4094 (@nikarh)
|
||||
|
||||
## Themes
|
||||
|
||||
@@ -87,6 +130,7 @@
|
||||
|
||||
## Bugfixes
|
||||
|
||||
- Fix `capacity overflow` panic when wrapping a double-width character on a line narrower than the character while a background is painted (e.g. `--terminal-width=1 --wrap=character --highlight-line=1`). Closes #3844, see #4098 (@feafel)
|
||||
- Fix hang when using `--list-themes` with an explicit pager, see #3457 (@abhinavcool42)
|
||||
- Fix negative values of N not being parsed in <N:M> line ranges without `=` flag value separator, see #3442 (@lmmx)
|
||||
- Fix broken Docker syntax preventing use of custom assets, see #3476 (@keith-hall)
|
||||
|
||||
Generated
+382
-616
File diff suppressed because it is too large.
Load diff
+4
-4
@@ -6,7 +6,7 @@ homepage = "https://github.com/sharkdp/bat"
|
||||
license = "MIT OR Apache-2.0"
|
||||
name = "bat"
|
||||
repository = "https://github.com/sharkdp/bat"
|
||||
version = "0.26.1"
|
||||
version = "0.27.0"
|
||||
exclude = ["assets/syntaxes/*", "assets/themes/*"]
|
||||
build = "build/main.rs"
|
||||
edition = '2021'
|
||||
@@ -70,13 +70,13 @@ regex = { version = "1.12.3", optional = true }
|
||||
walkdir = { version = "2.5", optional = true }
|
||||
bytesize = { version = "2.3.1" }
|
||||
encoding_rs = "0.8.35"
|
||||
execute = { version = "0.2.15", optional = true }
|
||||
execute = { version = "0.3.0", optional = true }
|
||||
terminal-colorsaurus = "1.0"
|
||||
unicode-segmentation = "1.13.2"
|
||||
itertools = "0.14.0"
|
||||
|
||||
[dependencies.gix]
|
||||
version = "0.85"
|
||||
version = "0.90"
|
||||
optional = true
|
||||
default-features = false
|
||||
features = ["sha1", "blob-diff"]
|
||||
@@ -104,7 +104,7 @@ tempfile = "3.27.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
||||
[target.'cfg(unix)'.dev-dependencies]
|
||||
nix = { version = "0.31", default-features = false, features = ["term"] }
|
||||
nix = { version = "0.31", default-features = false, features = ["poll", "term"] }
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.97"
|
||||
|
||||
@@ -417,7 +417,7 @@ scoop install bat
|
||||
|
||||
You can download prebuilt binaries from the [Release page](https://github.com/sharkdp/bat/releases),
|
||||
|
||||
You will need to install the [Visual C++ Redistributable](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) package.
|
||||
You will need to install the [Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist) package.
|
||||
|
||||
### From binaries
|
||||
|
||||
@@ -427,10 +427,16 @@ binaries are also available: look for archives with `musl` in the file name.
|
||||
|
||||
### From source
|
||||
|
||||
If you want to build `bat` from source, you need Rust 1.79.0 or
|
||||
If you want to build `bat` from source, you need Rust 1.88.0 or
|
||||
higher. You can then use `cargo` to build everything:
|
||||
|
||||
#### From local source
|
||||
|
||||
The checkout includes prebuilt syntax and theme assets. If you want to regenerate them
|
||||
from their sources, first initialize the Git submodules with
|
||||
`git submodule update --init --recursive`, then follow the [Development](#development)
|
||||
instructions. This includes the `help` syntax used to highlight command-line help.
|
||||
|
||||
```bash
|
||||
cargo install --path . --locked
|
||||
```
|
||||
@@ -794,7 +800,7 @@ Example configuration file:
|
||||
|
||||
### Prerequisites
|
||||
|
||||
You will need to install the [Visual C++ Redistributable](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads) package.
|
||||
You will need to install the [Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist) package.
|
||||
|
||||
### Paging
|
||||
|
||||
@@ -843,6 +849,10 @@ If your version of `bat` supports the `--strip-ansi=auto` option, it can be used
|
||||
before syntax highlighting. Alternatively, you may disable both syntax highlighting and wrapping by
|
||||
passing the `--color=never --wrap=never` options to `bat`.
|
||||
|
||||
For untrusted input, the `--sanitize=auto|always|never` option replaces terminal-active control
|
||||
bytes, including the escape character, and Unicode bidi / zero-width formatting characters with the
|
||||
Unicode replacement character. Escape sequences are not removed, so they cannot hide text.
|
||||
|
||||
> [!NOTE]
|
||||
> The `auto` option of `--strip-ansi` avoids removing escape sequences when the syntax is plain text.
|
||||
|
||||
@@ -898,7 +908,7 @@ cargo install --path . --locked --force
|
||||
```
|
||||
|
||||
If you want to build an application that uses `bat`'s pretty-printing
|
||||
features as a library, check out the [the API documentation](https://docs.rs/bat/).
|
||||
features as a library, check out the [API documentation](https://docs.rs/bat/).
|
||||
Note that you have to use either `regex-onig` or `regex-fancy` as a feature
|
||||
when you depend on `bat` as a library.
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
Vendored
+7
-1
@@ -9,7 +9,7 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script
|
||||
$ArrayCompletion = @('bash', 'fish', 'zsh', 'ps1')
|
||||
$ArrayWhen = @('auto', 'never', 'always')
|
||||
$ArrayYesNo = @('never', 'always')
|
||||
$ArrayWrap = @('always', 'never', 'character', 'word')
|
||||
$ArrayWrap = @('auto', 'never', 'character', 'word')
|
||||
$ArrayBinary = @('no-printing', 'as-text')
|
||||
$ArrayPrint = @('unicode', 'caret')
|
||||
|
||||
@@ -100,6 +100,11 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script
|
||||
ForEach-Object {[System.Management.Automation.CompletionResult]::new($_, $_, [CompletionResultType]::ParameterValue, $_)}
|
||||
break
|
||||
}
|
||||
'*;--sanitize' {
|
||||
$ArrayWhen |
|
||||
ForEach-Object {[System.Management.Automation.CompletionResult]::new($_, $_, [CompletionResultType]::ParameterValue, $_)}
|
||||
break
|
||||
}
|
||||
'*;--strip-ansi' {
|
||||
$ArrayWhen |
|
||||
ForEach-Object {[System.Management.Automation.CompletionResult]::new($_, $_, [CompletionResultType]::ParameterValue, $_)}
|
||||
@@ -158,6 +163,7 @@ Register-ArgumentCompleter -Native -CommandName '{{PROJECT_EXECUTABLE}}' -Script
|
||||
[CompletionResult]::new('--ignored-suffix' , 'ignored-suffix' , [CompletionResultType]::ParameterName, 'Ignore extension. For example: ''bat --ignored-suffix ".dev" my_file.json.dev'' will use JSON syntax, and ignore ''.dev''')
|
||||
[CompletionResult]::new('--squeeze-blank' , 'squeeze-blank' , [CompletionResultType]::ParameterName, 'Squeeze consecutive empty lines into a single empty line.')
|
||||
[CompletionResult]::new('--squeeze-limit' , 'squeeze-limit' , [CompletionResultType]::ParameterName, 'Set the maximum number of consecutive empty lines to be printed.')
|
||||
[CompletionResult]::new('--sanitize' , 'sanitize' , [CompletionResultType]::ParameterName, 'Specify when to sanitize untrusted input for safe display. Implies --strip-ansi and also replaces terminal-active and bidi / zero-width bytes. (auto, always, *never*).')
|
||||
[CompletionResult]::new('--strip-ansi' , 'strip-ansi' , [CompletionResultType]::ParameterName, 'Specify when to strip ANSI escape sequences from the input. The automatic mode will remove escape sequences unless the syntax highlighting language is plain text. (auto, always, *never*).')
|
||||
# [CompletionResult]::new('-p' , 'p' , [CompletionResultType]::ParameterName, 'Show plain style (alias for ''--style=plain'').')
|
||||
[CompletionResult]::new('--plain' , 'plain' , [CompletionResultType]::ParameterName, 'Show plain style (alias for ''--style=plain'').')
|
||||
|
||||
Vendored
+5
@@ -132,6 +132,10 @@ _bat() {
|
||||
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--sanitize)
|
||||
COMPREPLY=($(compgen -W "auto never always" -- "$cur"))
|
||||
return 0
|
||||
;;
|
||||
--completion)
|
||||
COMPREPLY=($(compgen -W "bash fish zsh ps1" -- "$cur"))
|
||||
return 0
|
||||
@@ -221,6 +225,7 @@ _bat() {
|
||||
--list-themes
|
||||
--squeeze-blank
|
||||
--squeeze-limit
|
||||
--sanitize
|
||||
--strip-ansi
|
||||
--style
|
||||
--line-range
|
||||
|
||||
Vendored
+1
@@ -221,6 +221,7 @@ complete -c $bat -s s -l squeeze-blank -d "Squeeze consecutive empty lines into
|
||||
complete -c $bat -l squeeze-limit -x -d "Set the maximum number of consecutive empty lines to be printed" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -l strip-ansi -x -a "auto never always" -d "Specify when to strip ANSI escape sequences from the input" -n __bat_no_excl_args
|
||||
complete -c $bat -l sanitize -x -a "auto never always" -d "Specify when to sanitize untrusted input for safe display" -n __bat_no_excl_args
|
||||
|
||||
complete -c $bat -s p -l plain -d "Disable decorations" -n __bat_no_excl_args
|
||||
|
||||
|
||||
Vendored
+1
@@ -54,6 +54,7 @@ _{{PROJECT_EXECUTABLE}}_main() {
|
||||
--squeeze-blank'[squeeze consecutive empty lines into a single empty line]'
|
||||
--squeeze-limit='[set the maximum number of consecutive empty lines]:limit:'
|
||||
--strip-ansi='[specify when to strip ANSI escape sequences]:when:(auto never always)'
|
||||
--sanitize='[specify when to sanitize untrusted input for safe display]:when:(auto never always)'
|
||||
--style='[comma-separated list of style elements to display]: : _values "style [default]"
|
||||
default auto full plain changes header header-filename header-filesize grid rule numbers snip'
|
||||
\*{-r+,--line-range=}'[only print the specified line range]:start\:end'
|
||||
|
||||
+10
@@ -12,3 +12,13 @@ index 05a4fed6..78a7bf55 100644
|
||||
scope: source.js
|
||||
variables:
|
||||
bin_digit: '[01_]'
|
||||
@@ -93,7 +93,8 @@ variables:
|
||||
(?! \+\+ | -- )
|
||||
(?=
|
||||
!= |
|
||||
- [-+*/%><=&|^\[(;,.:?] |
|
||||
+ [-+*%><=&|^\[(;,.:?] |
|
||||
+ /(?!\*) |
|
||||
(?:in|instanceof){{identifier_break}}
|
||||
)
|
||||
))
|
||||
Vendored
BIN
Binary file not shown.
+1
Submodule assets/syntaxes/02_Extra/CUE added at 16796709f3.
+952
@@ -0,0 +1,952 @@
|
||||
%YAML 1.2
|
||||
---
|
||||
# http://www.sublimetext.com/docs/3/syntax.html
|
||||
name: CUE
|
||||
file_extensions:
|
||||
- cue
|
||||
scope: source.cue
|
||||
contexts:
|
||||
main:
|
||||
- include: invalid_slash
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(package)[ \t]+([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*)(?![\p{L}\p{Nd}_\$\#])'
|
||||
captures:
|
||||
1: keyword.other.package
|
||||
2: entity.name.namespace
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(import)[ \t]+(\()'
|
||||
captures:
|
||||
1: keyword.other.import
|
||||
2: punctuation.section.parens.begin
|
||||
push:
|
||||
- meta_scope: meta.imports
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.parens.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- match: '(?:([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_)[ \t]+)?(")([^:"]+)(?:(:)([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*))?(")'
|
||||
scope: meta.import-spec
|
||||
captures:
|
||||
1: entity.name.namespace
|
||||
2: punctuation.definition.string.begin
|
||||
3: string.quoted.double-import
|
||||
4: punctuation.colon
|
||||
5: entity.name
|
||||
6: punctuation.definition.string.end
|
||||
- match: ;
|
||||
scope: punctuation.separator
|
||||
- include: invalid_in_parens
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(import)[ \t]+(?:([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_)[ \t]+)?(")([^:"]+)(?:(:)([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*))?(")'
|
||||
scope: meta.import
|
||||
captures:
|
||||
1: keyword.other.import
|
||||
2: entity.name.namespace
|
||||
3: punctuation.definition.string.begin
|
||||
4: string.quoted.double-import
|
||||
5: punctuation.colon
|
||||
6: entity.name
|
||||
7: punctuation.definition.string.end
|
||||
- include: punctuation_comma
|
||||
- include: declaration
|
||||
- include: invalid_in_braces
|
||||
comment:
|
||||
- match: (//).*$\n?
|
||||
scope: comment.line
|
||||
captures:
|
||||
1: punctuation.definition.comment
|
||||
alias_postfix:
|
||||
- match: '(~)[ \t]*(?:([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_)|(\()[ \t]*([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_)(?:[ \t]*(,)[ \t]*([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_))?[ \t]*(\)))'
|
||||
captures:
|
||||
1: punctuation.alias
|
||||
2: variable.other
|
||||
3: punctuation.section.parens.begin
|
||||
4: variable.other
|
||||
5: punctuation.separator
|
||||
6: variable.other
|
||||
7: punctuation.section.parens.end
|
||||
attribute:
|
||||
- match: '(@)([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)(\()'
|
||||
captures:
|
||||
1: punctuation.definition.annotation
|
||||
2: variable.annotation
|
||||
3: punctuation.attribute-elements.begin
|
||||
push:
|
||||
- meta_scope: meta.annotation
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.attribute-elements.end
|
||||
pop: true
|
||||
- include: comment
|
||||
- include: punctuation_comma
|
||||
- include: attribute_element
|
||||
attribute_element:
|
||||
- match: '[ \t]*(?<![\p{L}\p{Nd}_\$\#])((?:[\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)(?:\.(?:[\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+))*)[ \t]*(=)(?!=)'
|
||||
captures:
|
||||
1: variable.other
|
||||
2: punctuation.bind
|
||||
push:
|
||||
- match: '(?=[,\)])'
|
||||
pop: true
|
||||
- include: comment
|
||||
- include: attribute_nested
|
||||
- include: attribute_string
|
||||
- include: attribute_nested
|
||||
- include: attribute_string
|
||||
attribute_nested:
|
||||
- match: '[ \t]*(?:([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)[ \t]*)?(\()'
|
||||
captures:
|
||||
1: variable.other
|
||||
2: punctuation.attribute-elements.begin
|
||||
push:
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.attribute-elements.end
|
||||
pop: true
|
||||
- include: comment
|
||||
- include: punctuation_comma
|
||||
- include: attribute_element
|
||||
attribute_string:
|
||||
- include: string
|
||||
- match: '(?:[^\n,"''#\(\)/]|/(?!/)|(?<!#)#++(?!["'']))+'
|
||||
scope: string.unquoted
|
||||
- match: '[^,\)]+'
|
||||
scope: invalid
|
||||
declaration:
|
||||
- include: attribute
|
||||
- include: alias_postfix
|
||||
- include: punctuation_ellipsis
|
||||
- include: punctuation_colon
|
||||
- include: punctuation_option
|
||||
- include: punctuation_bind
|
||||
- include: expression
|
||||
expression:
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(for)[ \t]+([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_)(?:[ \t]*(,)[ \t]*([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_))?[ \t]+(in)(?![\p{L}\p{Nd}_\$\#])(?:[ \t]+(else|otherwise|fallback|try)(?![\p{L}\p{Nd}_\$\#]))?'
|
||||
captures:
|
||||
1: keyword.control.for
|
||||
2: variable.other
|
||||
3: punctuation.separator
|
||||
4: variable.other
|
||||
5: keyword.control.in
|
||||
6: variable.other
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(if)(?![\p{L}\p{Nd}_\$\#])(?:[ \t]+(else|otherwise|fallback|try)(?![\p{L}\p{Nd}_\$\#]))?'
|
||||
captures:
|
||||
1: keyword.control.conditional
|
||||
2: variable.other
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(try)[ \t]+([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+|_)[ \t]*(=)(?![=~])'
|
||||
captures:
|
||||
1: keyword.control.try
|
||||
2: variable.other
|
||||
3: punctuation.bind
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])try(?=[ \t]*\{|[ \t]+(?:for|if|let|try)(?![\p{L}\p{Nd}_\$\#]))'
|
||||
scope: keyword.control.try
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(?:else|otherwise|fallback)(?=[ \t]*\{)'
|
||||
scope: keyword.control.conditional
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])func(?=[ \t]*\()'
|
||||
scope: keyword.function
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(let)[ \t]+([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)[ \t]*(=)(?![=])'
|
||||
captures:
|
||||
1: keyword.control.let
|
||||
2: variable.other
|
||||
3: punctuation.bind
|
||||
- match: "->"
|
||||
scope: keyword.operator.arrow
|
||||
- match: '[\+\-\*]|/(?!/)'
|
||||
scope: keyword.operator
|
||||
- match: "=[=~]|![=~]|<=|>=|[<](?!=)|[>](?![=])"
|
||||
scope: keyword.operator.comparison
|
||||
- match: '&{2}|\|{2}|!(?![=~])'
|
||||
scope: keyword.operator.logical
|
||||
- match: '&(?!&)|\|(?!\|)'
|
||||
scope: keyword.operator.set
|
||||
- match: '(?<!\.)(\.)[ \t]*([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)(?![\p{L}\p{Nd}_\$\#])'
|
||||
captures:
|
||||
1: punctuation.accessor
|
||||
2: variable.other.member
|
||||
- match: '(?<!\.)(\.)(?=[ \t]*(?:#*"|//|$))'
|
||||
captures:
|
||||
1: punctuation.accessor
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])_(?!\|)(?![\p{L}\p{Nd}_\$\#])'
|
||||
scope: constant.language.top
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])_\|_(?![\p{L}\p{Nd}_\$\#])'
|
||||
scope: constant.language.bottom
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])null(?![\p{L}\p{Nd}_\$\#])'
|
||||
scope: constant.language.null
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(?:true|false)(?![\p{L}\p{Nd}_\$\#])'
|
||||
scope: constant.language.bool
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])[0-9](?:_?[0-9])*\.(?:[0-9](?:_?[0-9])*)?(?:[eE][\+\-]?[0-9](?:_?[0-9])*)?(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.float.decimal
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])[0-9](?:_?[0-9])*[eE][\+\-]?[0-9](?:_?[0-9])*(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.float.decimal
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])\.[0-9](?:_?[0-9])*(?:[eE][\+\-]?[0-9](?:_?[0-9])*)?(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.float.decimal
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])(?:0|[1-9](?:_?[0-9])*)(?:\.[0-9](?:_?[0-9])*)?(?:[KMGTP]i?)(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.integer.other
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])\.[0-9](?:_?[0-9])*(?:[KMGTP]i?)(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.integer.other
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])(?:0|[1-9](?:_?[0-9])*)(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.integer.decimal
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])0b_?[0-1](?:_?[0-1])*(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.integer.binary
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])0[xX]_?[0-9a-fA-F](?:_?[0-9a-fA-F])*(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.integer.hexadecimal
|
||||
- match: '(?<![\p{L}\p{Nd}_\.])0o_?[0-7](?:_?[0-7])*(?![\p{L}\p{Nd}_]|\.(?!\.\.))'
|
||||
scope: constant.numeric.integer.octal
|
||||
- include: string
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(?:bool|u?int(?:8|16|32|64|128)?|float(?:32|64)?|string|bytes|number|rune)(?![\p{L}\p{Nd}_\$\#])'
|
||||
scope: support.type
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(?:__)?self(?![\p{L}\p{Nd}_\$\#])(?![ \t]*+(?:[?!][ \t]*+)?:|[ \t]*+~|[ \t]*+=(?![=~]))'
|
||||
scope: variable.language.self
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(len|close|and|or|div|mod|quo|rem|matchN|matchIf|error|validator)(\()'
|
||||
captures:
|
||||
1: support.function
|
||||
2: punctuation.section.parens.begin
|
||||
push:
|
||||
- meta_scope: meta.function-call
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.parens.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- include: punctuation_comma
|
||||
- include: attribute
|
||||
- include: alias_postfix
|
||||
- include: punctuation_colon
|
||||
- include: punctuation_option
|
||||
- include: punctuation_bind
|
||||
- include: punctuation_ellipsis
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)(\.)(\p{Lu}[\p{L}\p{Nd}_\$\#]*)(\()'
|
||||
captures:
|
||||
1: support.module
|
||||
2: punctuation
|
||||
3: support.function
|
||||
4: punctuation.section.parens.begin
|
||||
push:
|
||||
- meta_scope: meta.function-call
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.parens.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- include: punctuation_comma
|
||||
- include: attribute
|
||||
- include: alias_postfix
|
||||
- include: punctuation_colon
|
||||
- include: punctuation_option
|
||||
- include: punctuation_bind
|
||||
- include: punctuation_ellipsis
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])(?:[\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)(?![\p{L}\p{Nd}_\$\#])'
|
||||
scope: variable.other
|
||||
- match: '\{'
|
||||
captures:
|
||||
0: punctuation.definition.struct.begin
|
||||
push:
|
||||
- meta_scope: meta.struct
|
||||
- match: '\}'
|
||||
captures:
|
||||
0: punctuation.definition.struct.end
|
||||
pop: true
|
||||
- include: invalid_slash
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- include: punctuation_comma
|
||||
- include: punctuation_ellipsis
|
||||
- include: declaration
|
||||
- include: invalid_in_braces
|
||||
- match: '\['
|
||||
captures:
|
||||
0: punctuation.section.brackets.begin
|
||||
push:
|
||||
- meta_scope: meta.brackets
|
||||
- match: '\]'
|
||||
captures:
|
||||
0: punctuation.section.brackets.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- include: punctuation_colon
|
||||
- include: punctuation_comma
|
||||
- include: punctuation_ellipsis
|
||||
- include: punctuation_option
|
||||
- match: '(?<![\p{L}\p{Nd}_\$\#])([\p{L}\$\#][\p{L}\p{Nd}_\$\#]*|_[\p{L}\p{Nd}_\$\#]+)[ \t]*(=)(?![=~])'
|
||||
captures:
|
||||
1: variable.other
|
||||
2: punctuation.alias
|
||||
- include: expression
|
||||
- match: '[^\s\]]'
|
||||
scope: invalid
|
||||
- match: \(
|
||||
captures:
|
||||
0: punctuation.section.parens.begin
|
||||
push:
|
||||
- meta_scope: meta.parens
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.parens.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: comment
|
||||
- include: punctuation_comma
|
||||
- include: attribute
|
||||
- include: alias_postfix
|
||||
- include: punctuation_colon
|
||||
- include: punctuation_option
|
||||
- include: punctuation_bind
|
||||
- include: punctuation_ellipsis
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
invalid_in_braces:
|
||||
- match: '[^\s\}]'
|
||||
scope: invalid
|
||||
invalid_in_parens:
|
||||
- match: '[^\s\)]'
|
||||
scope: invalid
|
||||
invalid_slash:
|
||||
- match: '(?<=^|[\{,:])[ \t]*+(/)(?!/)'
|
||||
captures:
|
||||
1: invalid
|
||||
punctuation_bind:
|
||||
- match: "(?<![=!><])=(?![=~])"
|
||||
scope: punctuation.bind
|
||||
punctuation_colon:
|
||||
- match: (?<!:):(?!:)
|
||||
scope: punctuation.colon
|
||||
punctuation_comma:
|
||||
- match: ","
|
||||
scope: punctuation.separator
|
||||
punctuation_ellipsis:
|
||||
- match: '(?<!\.)\.{3}(?!\.)'
|
||||
scope: punctuation.ellipsis
|
||||
punctuation_option:
|
||||
- match: \?
|
||||
scope: punctuation.option
|
||||
string:
|
||||
- match: '####"""'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double-multiline
|
||||
- match: '"""####'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\####(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\####(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\####\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\####$
|
||||
scope: constant.character.escape
|
||||
- match: \\####.
|
||||
scope: invalid.illegal
|
||||
- match: '####"'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double
|
||||
- match: '"####'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\####(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\####(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\####\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\####.
|
||||
scope: invalid.illegal
|
||||
- match: "####'''"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single-multiline
|
||||
- match: "'''####"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\####(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\####(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\####\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\####$
|
||||
scope: constant.character.escape
|
||||
- match: \\####.
|
||||
scope: invalid.illegal
|
||||
- match: "####'"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single
|
||||
- match: "'####"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\####(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\####(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\####\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\####.
|
||||
scope: invalid.illegal
|
||||
- match: '###"""'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double-multiline
|
||||
- match: '"""###'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\###(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\###(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\###\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\###$
|
||||
scope: constant.character.escape
|
||||
- match: \\###.
|
||||
scope: invalid.illegal
|
||||
- match: '###"'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double
|
||||
- match: '"###'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\###(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\###(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\###\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\###.
|
||||
scope: invalid.illegal
|
||||
- match: "###'''"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single-multiline
|
||||
- match: "'''###"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\###(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\###(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\###\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\###$
|
||||
scope: constant.character.escape
|
||||
- match: \\###.
|
||||
scope: invalid.illegal
|
||||
- match: "###'"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single
|
||||
- match: "'###"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\###(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\###(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\###\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\###.
|
||||
scope: invalid.illegal
|
||||
- match: '##"""'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double-multiline
|
||||
- match: '"""##'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\##(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\##(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\##\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\##$
|
||||
scope: constant.character.escape
|
||||
- match: \\##.
|
||||
scope: invalid.illegal
|
||||
- match: '##"'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double
|
||||
- match: '"##'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\##(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\##(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\##\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\##.
|
||||
scope: invalid.illegal
|
||||
- match: "##'''"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single-multiline
|
||||
- match: "'''##"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\##(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\##(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\##\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\##$
|
||||
scope: constant.character.escape
|
||||
- match: \\##.
|
||||
scope: invalid.illegal
|
||||
- match: "##'"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single
|
||||
- match: "'##"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\##(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\##(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\##\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\##.
|
||||
scope: invalid.illegal
|
||||
- match: '#"""'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double-multiline
|
||||
- match: '"""#'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\#(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\#(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\#\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\#$
|
||||
scope: constant.character.escape
|
||||
- match: \\#.
|
||||
scope: invalid.illegal
|
||||
- match: '#"'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double
|
||||
- match: '"#'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\#(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\#(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\#\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\#.
|
||||
scope: invalid.illegal
|
||||
- match: "#'''"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single-multiline
|
||||
- match: "'''#"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\#(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\#(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\#\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\#$
|
||||
scope: constant.character.escape
|
||||
- match: \\#.
|
||||
scope: invalid.illegal
|
||||
- match: "#'"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single
|
||||
- match: "'#"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\#(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\#(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\#\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\#.
|
||||
scope: invalid.illegal
|
||||
- match: '"""'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double-multiline
|
||||
- match: '"""'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\$
|
||||
scope: constant.character.escape
|
||||
- match: \\.
|
||||
scope: invalid.illegal
|
||||
- match: '"'
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.double
|
||||
- match: '"'
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\(?:"|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: invalid.illegal
|
||||
- match: \\\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\.
|
||||
scope: invalid.illegal
|
||||
- match: "'''"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single-multiline
|
||||
- match: "'''"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\$
|
||||
scope: constant.character.escape
|
||||
- match: \\.
|
||||
scope: invalid.illegal
|
||||
- match: "'"
|
||||
captures:
|
||||
0: punctuation.definition.string.begin
|
||||
push:
|
||||
- meta_scope: meta.string
|
||||
- meta_content_scope: string.quoted.single
|
||||
- match: "'"
|
||||
captures:
|
||||
0: punctuation.definition.string.end
|
||||
pop: true
|
||||
- match: '\\(?:''|/|\\|[abfnrtv]|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})'
|
||||
scope: constant.character.escape
|
||||
- match: '\\(?:[0-7]{3}|x[0-9A-Fa-f]{2})'
|
||||
scope: constant.character.escape
|
||||
- match: \\\(
|
||||
captures:
|
||||
0: punctuation.section.interpolation.begin
|
||||
push:
|
||||
- meta_scope: meta.interpolation
|
||||
- meta_content_scope: source.cue.embedded
|
||||
- match: \)
|
||||
captures:
|
||||
0: punctuation.section.interpolation.end
|
||||
pop: true
|
||||
- include: whitespace
|
||||
- include: punctuation_option
|
||||
- include: expression
|
||||
- include: invalid_in_parens
|
||||
- match: \\.
|
||||
scope: invalid.illegal
|
||||
whitespace:
|
||||
- match: '[ \t\r\n]+'
|
||||
Vendored
+1
-1
Submodule assets/syntaxes/02_Extra/Kotlin updated: c353694169...8c44d40c94.
Vendored
+1
-1
Submodule assets/syntaxes/02_Extra/LESS updated: 836b47ec61...d076a4dd41.
+23
-4
@@ -38,22 +38,41 @@ contexts:
|
||||
scope: markup.underline.link.scheme.log
|
||||
push: url-host
|
||||
log_level_lines:
|
||||
- match: (?=.*{{error}})
|
||||
# Prevent retrying each lookahead at every position.
|
||||
- match: ^(?=.*{{error}})
|
||||
push:
|
||||
- error_line_meta
|
||||
- main_pop_at_eol
|
||||
- match: (?=.*{{warning}})
|
||||
- match: ^(?=.*{{warning}})
|
||||
push:
|
||||
- warning_line_meta
|
||||
- main_pop_at_eol
|
||||
- match: (?=.*{{info}})
|
||||
- match: ^(?=.*{{info}})
|
||||
push:
|
||||
- info_line_meta
|
||||
- main_pop_at_eol
|
||||
- match: (?=.*{{debug}})
|
||||
- match: ^(?=.*{{debug}})
|
||||
push:
|
||||
- debug_line_meta
|
||||
- main_pop_at_eol
|
||||
# For syntaxes that embed Log after consuming a prefix. Call this context once.
|
||||
log_level_lines_at_current_position:
|
||||
- match: (?=.*{{error}})
|
||||
set:
|
||||
- error_line_meta
|
||||
- main_pop_at_eol
|
||||
- match: (?=.*{{warning}})
|
||||
set:
|
||||
- warning_line_meta
|
||||
- main_pop_at_eol
|
||||
- match: (?=.*{{info}})
|
||||
set:
|
||||
- info_line_meta
|
||||
- main_pop_at_eol
|
||||
- match: (?=.*{{debug}})
|
||||
set:
|
||||
- debug_line_meta
|
||||
- main_pop_at_eol
|
||||
log_levels:
|
||||
- match: '{{error}}'
|
||||
scope: markup.error.log
|
||||
|
||||
+11
-1
@@ -50,6 +50,17 @@ contexts:
|
||||
- match: (?=\])
|
||||
pop: true
|
||||
text:
|
||||
- include: text_special
|
||||
- match: ''
|
||||
set: classify_log_text
|
||||
classify_log_text:
|
||||
- include: scope:text.log#log_level_lines_at_current_position
|
||||
- match: ''
|
||||
set: text_body
|
||||
text_body:
|
||||
- include: text_special
|
||||
- include: scope:text.log
|
||||
text_special:
|
||||
- match: $
|
||||
pop: true
|
||||
- match: '<\w+>'
|
||||
@@ -62,4 +73,3 @@ contexts:
|
||||
escape: \)$
|
||||
escape_captures:
|
||||
0: punctuation.section.block.end.syslog
|
||||
- include: scope:text.log
|
||||
Vendored
BIN
Binary file not shown.
@@ -33,6 +33,7 @@ pub fn gen_man_and_comp() -> anyhow::Result<()> {
|
||||
else {
|
||||
anyhow::bail!("BAT_ASSETS_GEN_DIR or OUT_DIR should be set for build.rs");
|
||||
};
|
||||
let out_dir = env::current_dir()?.join(out_dir);
|
||||
|
||||
fs::create_dir_all(out_dir.join("assets/manual")).unwrap();
|
||||
fs::create_dir_all(out_dir.join("assets/completions")).unwrap();
|
||||
|
||||
+1
-1
@@ -366,7 +366,7 @@ ansible-galaxy install aeimer.install_bat
|
||||
### From source
|
||||
|
||||
|
||||
`bat` をソースからビルドしたいならば、Rust 1.79.0 以上の環境が必要です。
|
||||
`bat` をソースからビルドしたいならば、Rust 1.88.0 以上の環境が必要です。
|
||||
`cargo` を使用してビルドすることができます:
|
||||
|
||||
```bash
|
||||
|
||||
+1
-1
@@ -416,7 +416,7 @@ scoop install bat
|
||||
|
||||
### 소스에서
|
||||
|
||||
`bat`의 소스를 빌드하기 위해서는, Rust 1.79.0 이상이 필요합니다.
|
||||
`bat`의 소스를 빌드하기 위해서는, Rust 1.88.0 이상이 필요합니다.
|
||||
`cargo`를 이용해 전부 빌드할 수 있습니다:
|
||||
|
||||
```bash
|
||||
|
||||
+1
-1
@@ -388,7 +388,7 @@ scoop install bat
|
||||
|
||||
### Из исходников
|
||||
|
||||
Если вы желаете установить `bat` из исходников, вам понадобится Rust 1.79.0 или выше. После этого используйте `cargo`, чтобы всё скомпилировать:
|
||||
Если вы желаете установить `bat` из исходников, вам понадобится Rust 1.88.0 или выше. После этого используйте `cargo`, чтобы всё скомпилировать:
|
||||
|
||||
```bash
|
||||
cargo install --locked bat
|
||||
|
||||
+6
-2
@@ -6,7 +6,7 @@ Should you find that a particular syntax is not available within `bat` and think
|
||||
code. As a basis, syntect uses [Sublime Text](https://www.sublimetext.com/) syntax definitions
|
||||
in the `.sublime-syntax` format.
|
||||
|
||||
**Important:** Before proceeding, verify that the syntax you wish to add meets the [criteria for inclusion](#Criteria-for-inclusion-of-new-syntaxes).
|
||||
**Important:** Before proceeding, verify that the syntax you wish to add meets the [criteria for inclusion](#criteria-for-inclusion-of-new-syntaxes).
|
||||
|
||||
1. Find a Sublime Text syntax for the given language, preferably in a separate Git repository
|
||||
which can be included as a submodule (under `assets/syntaxes`) using
|
||||
@@ -28,7 +28,7 @@ in the `.sublime-syntax` format.
|
||||
|
||||
5. Use `bat --list-languages` to check if the new languages are available. You may want to do something like ``export PATH="`pwd`/target/debug:$PATH"`` to ensure the locally compiled version is the one being used.
|
||||
|
||||
6. Add a syntax test for the new language. See [below](#Syntax-tests) for details.
|
||||
6. Add a syntax test for the new language. See [below](#syntax-tests) for details.
|
||||
|
||||
7. If you send a pull request with your changes, please do *not* include the changed `syntaxes.bin`
|
||||
file. A new binary cache file will be created once before every new release of `bat`. This
|
||||
@@ -103,3 +103,7 @@ The following files have been manually modified after converting from a `.tmLang
|
||||
* `Cabal.sublime_syntax` has been added manually from
|
||||
https://github.com/SublimeHaskell/SublimeHaskell/ - we don't want to include the whole submodule because it includes other syntaxes ("Haskell improved") as well.
|
||||
* `Lean.sublime-syntax` has been added manually from https://github.com/leanprover/vscode-lean4/blob/master/vscode-lean4/syntaxes/lean4.json via conversion.
|
||||
* `CUE.sublime-syntax` has been added manually from https://github.com/cue-lang/vscode-cue/blob/master/extension/syntaxes/cue.tmLanguage.json via conversion.
|
||||
Sublime Text's converter rejects rules that only group other patterns (see https://github.com/cue-lang/cue/issues/3427), so they are inlined before converting:
|
||||
`jq 'walk(if type == "object" and has("patterns") then .patterns |= [.[] | if type == "object" and keys == ["patterns"] then .patterns[] else . end] else . end)'`.
|
||||
The converted syntax reproduces the token goldens in `extension/testdata/syntax` of that repository.
|
||||
+20
-1
@@ -83,6 +83,16 @@ Options:
|
||||
-n, --number
|
||||
Only show line numbers, no other decorations. This is an alias for '--style=numbers'
|
||||
|
||||
-b, --number-nonblank
|
||||
Only show line numbers for non-blank lines, no other decorations. This is an alias for
|
||||
'--style=numbers'. Non-blank lines are lines that contain any character before the line
|
||||
ending, including spaces and tabs. When used together with --number (-n),
|
||||
--number-nonblank (-b) takes precedence.
|
||||
|
||||
Example:
|
||||
printf 'alpha\n\nbeta\n' | bat -b
|
||||
numbers 'alpha' and 'beta', but skips the empty line.
|
||||
|
||||
--color <when>
|
||||
Specify when to use colored output. The automatic mode only enables colors if an
|
||||
interactive terminal is detected - colors are automatically disabled if the output goes to
|
||||
@@ -161,7 +171,16 @@ Options:
|
||||
|
||||
--strip-ansi <when>
|
||||
Specify when to strip ANSI escape sequences from the input. The automatic mode will remove
|
||||
escape sequences unless the syntax highlighting language is plain text. Possible values:
|
||||
escape sequences unless the syntax highlighting language is plain text. Piped output is
|
||||
not stripped. Possible values: auto, always, *never*.
|
||||
|
||||
--sanitize <when>
|
||||
Specify when to sanitize input bytes for safe terminal display. Substitutes
|
||||
terminal-active control bytes (escape, cursor moves, charset switches, beep, etc.) and
|
||||
Unicode bidi / zero-width formatting characters with the Unicode replacement character
|
||||
(U+FFFD). Escape sequences are not removed, so they cannot hide text. Overrides
|
||||
--strip-ansi. Tab, LF, FF, and CRLF pass through. Useful for displaying untrusted file
|
||||
content (e.g. file-manager preview panes). Piped output is not sanitized. Possible values:
|
||||
auto, always, *never*.
|
||||
|
||||
--style <components>
|
||||
|
||||
@@ -33,6 +33,8 @@ Options:
|
||||
Truncate all lines longer than screen width. Alias for '--wrap=never'.
|
||||
-n, --number
|
||||
Show line numbers (alias for '--style=numbers').
|
||||
-b, --number-nonblank
|
||||
Show line numbers for non-blank lines only (alias for '--style=numbers').
|
||||
--color <when>
|
||||
When to use colors (*auto*, never, always).
|
||||
--italic-text <when>
|
||||
|
||||
+7
-3
@@ -201,7 +201,10 @@ impl HighlightingAssets {
|
||||
return self.get_theme("ansi");
|
||||
}
|
||||
if !theme.is_empty() {
|
||||
bat_warning!("Unknown theme '{theme}', using default.")
|
||||
bat_warning!(
|
||||
"Unknown theme '{}', using default.",
|
||||
crate::preprocessor::sanitize_for_terminal(theme)
|
||||
)
|
||||
}
|
||||
self.get_theme_set()
|
||||
.get(
|
||||
@@ -363,11 +366,11 @@ impl HighlightingAssets {
|
||||
reader: &mut InputReader,
|
||||
) -> Result<Option<SyntaxReferenceInSet<'_>>> {
|
||||
let syntax_set = self.get_syntax_set()?;
|
||||
Ok(String::from_utf8(reader.first_line.clone())
|
||||
Ok(std::str::from_utf8(&reader.first_line)
|
||||
.ok()
|
||||
.and_then(|l| {
|
||||
// Strip UTF-8 BOM if present
|
||||
let line = l.strip_prefix('\u{feff}').unwrap_or(&l);
|
||||
let line = l.strip_prefix('\u{feff}').unwrap_or(l);
|
||||
syntax_set.find_syntax_by_first_line(line)
|
||||
})
|
||||
.map(|syntax| SyntaxReferenceInSet { syntax, syntax_set }))
|
||||
@@ -792,6 +795,7 @@ contexts:
|
||||
false,
|
||||
cache_dir.path(),
|
||||
env!("CARGO_PKG_VERSION"),
|
||||
&mut std::io::sink(),
|
||||
)
|
||||
.expect("custom assets can be built");
|
||||
|
||||
|
||||
+41
-18
@@ -1,4 +1,5 @@
|
||||
use std::convert::TryInto;
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
use syntect::highlighting::ThemeSet;
|
||||
@@ -15,16 +16,18 @@ pub fn build(
|
||||
include_acknowledgements: bool,
|
||||
target_dir: &Path,
|
||||
current_version: &str,
|
||||
progress: &mut dyn Write,
|
||||
) -> Result<()> {
|
||||
let theme_set = build_theme_set(source_dir, include_integrated_assets)?;
|
||||
let theme_set = build_theme_set(source_dir, include_integrated_assets, progress)?;
|
||||
|
||||
let syntax_set_builder = build_syntax_set_builder(source_dir, include_integrated_assets)?;
|
||||
let syntax_set_builder =
|
||||
build_syntax_set_builder(source_dir, include_integrated_assets, progress)?;
|
||||
|
||||
let syntax_set = syntax_set_builder.build();
|
||||
|
||||
let acknowledgements = build_acknowledgements(source_dir, include_acknowledgements)?;
|
||||
|
||||
print_unlinked_contexts(&syntax_set);
|
||||
print_unlinked_contexts(&syntax_set, progress)?;
|
||||
|
||||
write_assets(
|
||||
&theme_set,
|
||||
@@ -32,10 +35,15 @@ pub fn build(
|
||||
&acknowledgements,
|
||||
target_dir,
|
||||
current_version,
|
||||
progress,
|
||||
)
|
||||
}
|
||||
|
||||
fn build_theme_set(source_dir: &Path, include_integrated_assets: bool) -> Result<LazyThemeSet> {
|
||||
fn build_theme_set(
|
||||
source_dir: &Path,
|
||||
include_integrated_assets: bool,
|
||||
progress: &mut dyn Write,
|
||||
) -> Result<LazyThemeSet> {
|
||||
let mut theme_set = if include_integrated_assets {
|
||||
crate::assets::get_integrated_themeset().try_into()?
|
||||
} else {
|
||||
@@ -46,16 +54,18 @@ fn build_theme_set(source_dir: &Path, include_integrated_assets: bool) -> Result
|
||||
if theme_dir.exists() {
|
||||
let res = theme_set.add_from_folder(&theme_dir);
|
||||
if let Err(err) = res {
|
||||
println!(
|
||||
writeln!(
|
||||
progress,
|
||||
"Failed to load one or more themes from '{}' (reason: '{err}')",
|
||||
theme_dir.to_string_lossy(),
|
||||
);
|
||||
)?;
|
||||
}
|
||||
} else {
|
||||
println!(
|
||||
writeln!(
|
||||
progress,
|
||||
"No themes were found in '{}', using the default set",
|
||||
theme_dir.to_string_lossy()
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
theme_set.try_into()
|
||||
@@ -64,6 +74,7 @@ fn build_theme_set(source_dir: &Path, include_integrated_assets: bool) -> Result
|
||||
fn build_syntax_set_builder(
|
||||
source_dir: &Path,
|
||||
include_integrated_assets: bool,
|
||||
progress: &mut dyn Write,
|
||||
) -> Result<SyntaxSetBuilder> {
|
||||
let mut syntax_set_builder = if !include_integrated_assets {
|
||||
let mut builder = syntect::parsing::SyntaxSetBuilder::new();
|
||||
@@ -78,23 +89,25 @@ fn build_syntax_set_builder(
|
||||
if syntax_dir.exists() {
|
||||
syntax_set_builder.add_from_folder(syntax_dir, true)?;
|
||||
} else {
|
||||
println!(
|
||||
writeln!(
|
||||
progress,
|
||||
"No syntaxes were found in '{}', using the default set.",
|
||||
syntax_dir.to_string_lossy()
|
||||
);
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(syntax_set_builder)
|
||||
}
|
||||
|
||||
fn print_unlinked_contexts(syntax_set: &SyntaxSet) {
|
||||
fn print_unlinked_contexts(syntax_set: &SyntaxSet, progress: &mut dyn Write) -> Result<()> {
|
||||
let missing_contexts = syntax_set.find_unlinked_contexts();
|
||||
if !missing_contexts.is_empty() {
|
||||
println!("Some referenced contexts could not be found!");
|
||||
writeln!(progress, "Some referenced contexts could not be found!")?;
|
||||
for context in missing_contexts {
|
||||
println!("- {context}");
|
||||
writeln!(progress, "- {context}")?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write_assets(
|
||||
@@ -103,6 +116,7 @@ fn write_assets(
|
||||
acknowledgements: &Option<String>,
|
||||
target_dir: &Path,
|
||||
current_version: &str,
|
||||
progress: &mut dyn Write,
|
||||
) -> Result<()> {
|
||||
let _ = std::fs::create_dir_all(target_dir);
|
||||
asset_to_cache(
|
||||
@@ -110,12 +124,14 @@ fn write_assets(
|
||||
&target_dir.join("themes.bin"),
|
||||
"theme set",
|
||||
COMPRESS_THEMES,
|
||||
progress,
|
||||
)?;
|
||||
asset_to_cache(
|
||||
syntax_set,
|
||||
&target_dir.join("syntaxes.bin"),
|
||||
"syntax set",
|
||||
COMPRESS_SYNTAXES,
|
||||
progress,
|
||||
)?;
|
||||
|
||||
if let Some(acknowledgements) = acknowledgements {
|
||||
@@ -124,15 +140,17 @@ fn write_assets(
|
||||
&target_dir.join("acknowledgements.bin"),
|
||||
"acknowledgements",
|
||||
COMPRESS_ACKNOWLEDGEMENTS,
|
||||
progress,
|
||||
)?;
|
||||
}
|
||||
|
||||
print!(
|
||||
write!(
|
||||
progress,
|
||||
"Writing metadata to folder {} ... ",
|
||||
target_dir.to_string_lossy()
|
||||
);
|
||||
)?;
|
||||
crate::assets_metadata::AssetsMetadata::new(current_version).save_to_folder(target_dir)?;
|
||||
println!("okay");
|
||||
writeln!(progress, "okay")?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -160,11 +178,16 @@ fn asset_to_cache<T: serde::Serialize>(
|
||||
path: &Path,
|
||||
description: &str,
|
||||
compressed: bool,
|
||||
progress: &mut dyn Write,
|
||||
) -> Result<()> {
|
||||
print!("Writing {description} to {} ... ", path.to_string_lossy());
|
||||
write!(
|
||||
progress,
|
||||
"Writing {description} to {} ... ",
|
||||
path.to_string_lossy()
|
||||
)?;
|
||||
let contents = asset_to_contents(asset, description, compressed)?;
|
||||
std::fs::write(path, &contents[..])
|
||||
.map_err(|_| format!("Could not save {description} to {}", path.to_string_lossy()))?;
|
||||
println!("okay");
|
||||
writeln!(progress, "okay")?;
|
||||
Ok(())
|
||||
}
|
||||
+69
-62
@@ -38,6 +38,15 @@ pub fn env_no_color() -> bool {
|
||||
env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty())
|
||||
}
|
||||
|
||||
fn parse_strip_ansi_value(raw: Option<&str>, flag_name: &str) -> StripAnsiMode {
|
||||
match raw {
|
||||
Some("never") | None => StripAnsiMode::Never,
|
||||
Some("always") => StripAnsiMode::Always,
|
||||
Some("auto") => StripAnsiMode::Auto,
|
||||
_ => unreachable!("other values for {flag_name} are not allowed"),
|
||||
}
|
||||
}
|
||||
|
||||
enum HelpType {
|
||||
Short,
|
||||
Long,
|
||||
@@ -50,6 +59,18 @@ pub struct App {
|
||||
/// (not from config file or environment variables).
|
||||
/// This is used to honor the flag when piping output, similar to `cat -n`.
|
||||
number_from_cli: bool,
|
||||
/// True if -b / --number-nonblank was passed on the command line
|
||||
/// (not from config file or environment variables).
|
||||
/// This is used to honor the flag when piping output, similar to `cat -b`.
|
||||
number_nonblank_from_cli: bool,
|
||||
}
|
||||
|
||||
/// True if stdout is attached to an interactive terminal. On Windows this also
|
||||
/// recognizes mintty/MSYS2 and Cygwin pseudo-terminals, which expose stdout as
|
||||
/// a named pipe that `std::io::IsTerminal` does not report as a terminal.
|
||||
/// Regular pipes (e.g. `bat file | grep`) are not affected.
|
||||
fn is_interactive_output() -> bool {
|
||||
std::io::stdout().is_terminal() || Term::stdout().features().is_msys_tty()
|
||||
}
|
||||
|
||||
impl App {
|
||||
@@ -57,40 +78,16 @@ impl App {
|
||||
#[cfg(windows)]
|
||||
let _ = nu_ansi_term::enable_ansi_support();
|
||||
|
||||
let interactive_output = std::io::stdout().is_terminal();
|
||||
let interactive_output = is_interactive_output();
|
||||
|
||||
// Check if the -n / --number option was passed on the command line
|
||||
// (before merging with config file and environment variables).
|
||||
// This is needed to honor the -n flag when piping output, similar to `cat -n`.
|
||||
// We need to handle both standalone (-n, --number) and combined short flags (-pn, -An, etc.)
|
||||
// Note: We only check if -n appears and is not overridden by -p in the same combined flag.
|
||||
// For combined flags like -np, -p comes after -n and overrides it, so we don't count it.
|
||||
// For combined flags like -pn, -n comes after -p and takes effect.
|
||||
let number_from_cli = wild::args_os().any(|arg| {
|
||||
let arg_str = arg.to_string_lossy();
|
||||
if arg_str == "-n" || arg_str == "--number" {
|
||||
return true;
|
||||
}
|
||||
// Handle combined short flags
|
||||
// Only count -n if it's the LAST flag in the combined form (so -p doesn't override it)
|
||||
// or if -p is not present in the combined form
|
||||
if arg_str.starts_with('-') && !arg_str.starts_with("--") && arg_str.len() > 2 {
|
||||
let chars: Vec<char> = arg_str.chars().skip(1).collect();
|
||||
let n_pos = chars.iter().position(|&c| c == 'n');
|
||||
let p_pos = chars.iter().position(|&c| c == 'p');
|
||||
// -n is in the combined flag and either:
|
||||
// - -p is not present, OR
|
||||
// - -n comes after -p (so -n takes effect)
|
||||
if let Some(n) = n_pos {
|
||||
if p_pos.is_none() || n > p_pos.unwrap() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
});
|
||||
// Parse the original command line separately from config and environment arguments.
|
||||
// Using clap here keeps CLI-only detection consistent with the final parser, including
|
||||
// option terminators, combined short flags, and options that take values.
|
||||
let cli_matches = Self::cli_matches(interactive_output);
|
||||
let number_from_cli = cli_matches.get_flag("number");
|
||||
let number_nonblank_from_cli = cli_matches.get_flag("number-nonblank");
|
||||
|
||||
let matches = Self::matches(interactive_output)?;
|
||||
let matches = Self::matches(interactive_output, &cli_matches)?;
|
||||
|
||||
if matches.get_flag("help") {
|
||||
let help_type = if wild::args_os().any(|arg| arg == "--help") {
|
||||
@@ -130,6 +127,7 @@ impl App {
|
||||
matches,
|
||||
interactive_output,
|
||||
number_from_cli,
|
||||
number_nonblank_from_cli,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -179,7 +177,8 @@ impl App {
|
||||
};
|
||||
|
||||
let cache_dir = PROJECT_DIRS.cache_dir();
|
||||
let assets = assets_from_cache_or_binary(use_custom_assets, cache_dir)?;
|
||||
let config_dir = PROJECT_DIRS.config_dir();
|
||||
let assets = assets_from_cache_or_binary(use_custom_assets, config_dir, cache_dir)?;
|
||||
Controller::new(&help_config, &assets)
|
||||
.run(inputs, None)
|
||||
.ok();
|
||||
@@ -201,20 +200,17 @@ impl App {
|
||||
args
|
||||
}
|
||||
|
||||
fn matches(interactive_output: bool) -> Result<ArgMatches> {
|
||||
// Check if we should skip config file processing for special arguments
|
||||
// that don't require full application setup (version, diagnostic)
|
||||
let should_skip_config = wild::args_os().any(|arg| {
|
||||
matches!(
|
||||
arg.to_str(),
|
||||
Some("-V" | "--version" | "--diagnostic" | "--diagnostics")
|
||||
)
|
||||
});
|
||||
fn cli_matches(interactive_output: bool) -> ArgMatches {
|
||||
clap_app::build_app(interactive_output).get_matches_from(wild::args_os())
|
||||
}
|
||||
|
||||
fn matches(interactive_output: bool, cli_matches: &ArgMatches) -> Result<ArgMatches> {
|
||||
let should_skip_config =
|
||||
cli_matches.get_flag("no-config") || cli_matches.get_flag("diagnostic");
|
||||
|
||||
// Check if help was requested - help should read the config file but be
|
||||
// forgiving of invalid arguments (so configured theme etc. can be used)
|
||||
let help_requested =
|
||||
wild::args_os().any(|arg| matches!(arg.to_str(), Some("-h" | "--help")));
|
||||
let help_requested = cli_matches.get_flag("help");
|
||||
|
||||
if wild::args_os().nth(1) == Some("cache".into()) {
|
||||
// Skip the config file and env vars
|
||||
@@ -222,9 +218,9 @@ impl App {
|
||||
return Ok(clap_app::build_app(interactive_output).get_matches_from(args));
|
||||
}
|
||||
|
||||
if wild::args_os().any(|arg| arg == "--no-config") || should_skip_config {
|
||||
if should_skip_config {
|
||||
// Skip the arguments in bats config file when --no-config is present
|
||||
// or when user requests version or diagnostic information
|
||||
// or when user requests diagnostic information
|
||||
let args = Self::build_args_without_config();
|
||||
return Ok(clap_app::build_app(interactive_output).get_matches_from(args));
|
||||
}
|
||||
@@ -340,13 +336,12 @@ impl App {
|
||||
// later args take precedence over earlier ones, hence `.rev()`
|
||||
// see: https://github.com/sharkdp/bat/pull/2755#discussion_r1456416875
|
||||
for from_to in values.rev() {
|
||||
let parts: Vec<_> = from_to.split(':').collect();
|
||||
|
||||
if parts.len() != 2 {
|
||||
// The glob can contain colons itself, e.g. after a drive letter on Windows.
|
||||
let Some((from, to)) = from_to.rsplit_once(':') else {
|
||||
return Err("Invalid syntax mapping. The format of the -m/--map-syntax option is '<glob-pattern>:<syntax-name>'. For example: '*.cpp:C++'.".into());
|
||||
}
|
||||
};
|
||||
|
||||
syntax_mapping.insert(parts[0], MappingTarget::MapTo(parts[1]))?;
|
||||
syntax_mapping.insert(from, MappingTarget::MapTo(to))?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -445,7 +440,8 @@ impl App {
|
||||
.map(|s| s.as_str())
|
||||
== Some("always")
|
||||
|| self.matches.get_flag("force-colorization")
|
||||
|| self.number_from_cli),
|
||||
|| self.number_from_cli
|
||||
|| self.number_nonblank_from_cli),
|
||||
tab_width: self
|
||||
.matches
|
||||
.get_one::<String>("tabs")
|
||||
@@ -458,18 +454,22 @@ impl App {
|
||||
4
|
||||
},
|
||||
),
|
||||
strip_ansi: match self
|
||||
.matches
|
||||
.get_one::<String>("strip-ansi")
|
||||
.map(|s| s.as_str())
|
||||
{
|
||||
Some("never") => StripAnsiMode::Never,
|
||||
Some("always") => StripAnsiMode::Always,
|
||||
Some("auto") => StripAnsiMode::Auto,
|
||||
_ => unreachable!("other values for --strip-ansi are not allowed"),
|
||||
},
|
||||
strip_ansi: parse_strip_ansi_value(
|
||||
self.matches
|
||||
.get_one::<String>("strip-ansi")
|
||||
.map(|s| s.as_str()),
|
||||
"--strip-ansi",
|
||||
),
|
||||
sanitize: parse_strip_ansi_value(
|
||||
self.matches
|
||||
.get_one::<String>("sanitize")
|
||||
.map(|s| s.as_str()),
|
||||
"--sanitize",
|
||||
),
|
||||
quiet_empty: self.matches.get_flag("quiet-empty"),
|
||||
unbuffered: self.matches.get_flag("unbuffered"),
|
||||
number_nonblank: self.matches.get_flag("number-nonblank")
|
||||
|| self.number_nonblank_from_cli,
|
||||
theme: theme(self.theme_options()).to_string(),
|
||||
visible_lines: match self.matches.try_contains_id("diff").unwrap_or_default()
|
||||
&& self.matches.get_flag("diff")
|
||||
@@ -588,6 +588,13 @@ impl App {
|
||||
])));
|
||||
}
|
||||
|
||||
// Only line numbers for non-blank lines if `--number-nonblank`.
|
||||
if self.matches.get_flag("number-nonblank") || self.number_nonblank_from_cli {
|
||||
return Some(StyleComponents(HashSet::from([
|
||||
StyleComponent::LineNumbers,
|
||||
])));
|
||||
}
|
||||
|
||||
// Plain if `--plain` is specified at least once.
|
||||
if self.matches.get_count("plain") > 0 {
|
||||
let mut components = HashSet::from([StyleComponent::Plain]);
|
||||
|
||||
+67
-10
@@ -1,5 +1,5 @@
|
||||
use std::fs;
|
||||
use std::io;
|
||||
use std::io::{self, Write};
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
@@ -9,16 +9,22 @@ use bat::assets::HighlightingAssets;
|
||||
use bat::assets_metadata::AssetsMetadata;
|
||||
use bat::error::*;
|
||||
|
||||
pub fn clear_assets(cache_dir: &Path) {
|
||||
clear_asset(cache_dir.join("themes.bin"), "theme set cache");
|
||||
clear_asset(cache_dir.join("syntaxes.bin"), "syntax set cache");
|
||||
clear_asset(cache_dir.join("metadata.yaml"), "metadata file");
|
||||
pub fn clear_assets(cache_dir: &Path) -> Result<()> {
|
||||
clear_asset(cache_dir.join("themes.bin"), "theme set cache")?;
|
||||
clear_asset(cache_dir.join("syntaxes.bin"), "syntax set cache")?;
|
||||
clear_asset(cache_dir.join("metadata.yaml"), "metadata file")?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn assets_from_cache_or_binary(
|
||||
use_custom_assets: bool,
|
||||
config_dir: &Path,
|
||||
cache_dir: &Path,
|
||||
) -> Result<HighlightingAssets> {
|
||||
if use_custom_assets {
|
||||
ensure_cache_built(config_dir, cache_dir);
|
||||
}
|
||||
|
||||
if let Some(metadata) = AssetsMetadata::load_from_folder(cache_dir)? {
|
||||
if !metadata.is_compatible_with(crate_version!()) {
|
||||
return Err(format!(
|
||||
@@ -43,15 +49,66 @@ pub fn assets_from_cache_or_binary(
|
||||
Ok(custom_assets.unwrap_or_else(HighlightingAssets::from_binary))
|
||||
}
|
||||
|
||||
fn clear_asset(path: PathBuf, description: &str) {
|
||||
print!("Clearing {description} ... ");
|
||||
fn clear_asset(path: PathBuf, description: &str) -> Result<()> {
|
||||
write!(io::stdout(), "Clearing {description} ... ")?;
|
||||
match fs::remove_file(&path) {
|
||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
||||
println!("skipped (not present)");
|
||||
writeln!(io::stdout(), "skipped (not present)")?;
|
||||
}
|
||||
Err(err) => {
|
||||
println!("could not remove the cache file {path:?}: {err}");
|
||||
writeln!(
|
||||
io::stdout(),
|
||||
"could not remove the cache file {path:?}: {err}"
|
||||
)?;
|
||||
}
|
||||
Ok(_) => println!("okay"),
|
||||
Ok(_) => writeln!(io::stdout(), "okay")?,
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Build the cache on first run when custom themes or syntaxes are present
|
||||
/// but no cache exists yet (see #4017). A failed build is not fatal: warn
|
||||
/// and fall back to the integrated assets.
|
||||
#[cfg(feature = "build-assets")]
|
||||
fn ensure_cache_built(config_dir: &Path, cache_dir: &Path) {
|
||||
if cache_exists(cache_dir) || !custom_sources_exist(config_dir) {
|
||||
return;
|
||||
}
|
||||
|
||||
eprintln!("bat: custom themes or syntaxes found, building cache ...");
|
||||
let mut progress = io::stderr();
|
||||
if let Err(err) = bat::assets::build(
|
||||
config_dir,
|
||||
true,
|
||||
false,
|
||||
cache_dir,
|
||||
crate_version!(),
|
||||
&mut progress,
|
||||
) {
|
||||
eprintln!("bat: automatic cache build failed ({err}), falling back to integrated assets.");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "build-assets"))]
|
||||
fn ensure_cache_built(_config_dir: &Path, _cache_dir: &Path) {}
|
||||
|
||||
#[cfg(feature = "build-assets")]
|
||||
fn cache_exists(cache_dir: &Path) -> bool {
|
||||
cache_dir.join("themes.bin").is_file()
|
||||
&& cache_dir.join("syntaxes.bin").is_file()
|
||||
&& cache_dir.join("metadata.yaml").is_file()
|
||||
}
|
||||
|
||||
#[cfg(feature = "build-assets")]
|
||||
fn custom_sources_exist(config_dir: &Path) -> bool {
|
||||
dir_has_files(&config_dir.join("themes")) || dir_has_files(&config_dir.join("syntaxes"))
|
||||
}
|
||||
|
||||
#[cfg(feature = "build-assets")]
|
||||
fn dir_has_files(dir: &Path) -> bool {
|
||||
walkdir::WalkDir::new(dir)
|
||||
.follow_links(true)
|
||||
.into_iter()
|
||||
.filter_map(|entry| entry.ok())
|
||||
.any(|entry| entry.path().is_file())
|
||||
}
|
||||
+53
-2
@@ -52,6 +52,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.long("show-all")
|
||||
.alias("show-nonprintable")
|
||||
.short('A')
|
||||
.overrides_with("show-all")
|
||||
.action(ArgAction::SetTrue)
|
||||
.conflicts_with("language")
|
||||
.help("Show non-printable characters (space, tab, newline, ..).")
|
||||
@@ -64,6 +65,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("nonprintable-notation")
|
||||
.long("nonprintable-notation")
|
||||
.overrides_with("nonprintable-notation")
|
||||
.action(ArgAction::Set)
|
||||
.default_value("unicode")
|
||||
.value_parser(["unicode", "caret"])
|
||||
@@ -80,6 +82,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("binary")
|
||||
.long("binary")
|
||||
.overrides_with("binary")
|
||||
.action(ArgAction::Set)
|
||||
.default_value("no-printing")
|
||||
.value_parser(["no-printing", "as-text"])
|
||||
@@ -97,6 +100,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("plain")
|
||||
.overrides_with("plain")
|
||||
.overrides_with("number")
|
||||
.overrides_with("number-nonblank")
|
||||
.short('p')
|
||||
.long("plain")
|
||||
.action(ArgAction::Count)
|
||||
@@ -123,6 +127,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("fallback-syntax")
|
||||
.long("fallback-syntax")
|
||||
.overrides_with("fallback-syntax")
|
||||
.visible_alias("fallback-language")
|
||||
.help("Set a fallback language for undetected syntaxes.")
|
||||
.long_help(
|
||||
@@ -170,6 +175,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("diff")
|
||||
.long("diff")
|
||||
.short('d')
|
||||
.overrides_with("diff")
|
||||
.action(ArgAction::SetTrue)
|
||||
.conflicts_with("line-range")
|
||||
.help("Only show lines that have been added/removed/modified.")
|
||||
@@ -234,6 +240,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("chop-long-lines")
|
||||
.long("chop-long-lines")
|
||||
.short('S')
|
||||
.overrides_with("chop-long-lines")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Truncate all lines longer than screen width. Alias for '--wrap=never'."),
|
||||
)
|
||||
@@ -277,6 +284,23 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
'--style=numbers'",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("number-nonblank")
|
||||
.long("number-nonblank")
|
||||
.overrides_with("number-nonblank")
|
||||
.short('b')
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Show line numbers for non-blank lines only (alias for '--style=numbers').")
|
||||
.long_help(
|
||||
"Only show line numbers for non-blank lines, no other decorations. This is an \
|
||||
alias for '--style=numbers'. Non-blank lines are lines that contain any \
|
||||
character before the line ending, including spaces and tabs. When used \
|
||||
together with --number (-n), --number-nonblank (-b) takes precedence.\n\n\
|
||||
Example:\n \
|
||||
printf 'alpha\\n\\nbeta\\n' | bat -b\n \
|
||||
numbers 'alpha' and 'beta', but skips the empty line.",
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::new("color")
|
||||
.long("color")
|
||||
@@ -296,6 +320,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("italic-text")
|
||||
.long("italic-text")
|
||||
.overrides_with("italic-text")
|
||||
.value_name("when")
|
||||
.value_parser(["always", "never"])
|
||||
.default_value("never")
|
||||
@@ -455,6 +480,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("squeeze-blank")
|
||||
.long("squeeze-blank")
|
||||
.short('s')
|
||||
.overrides_with("squeeze-blank")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Squeeze consecutive empty lines.")
|
||||
.long_help("Squeeze consecutive empty lines into a single empty line.")
|
||||
@@ -462,6 +488,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("squeeze-limit")
|
||||
.long("squeeze-limit")
|
||||
.overrides_with("squeeze-limit")
|
||||
.value_parser(|s: &str| s.parse::<usize>().map_err(|_| "Requires a non-negative number".to_owned()))
|
||||
.long_help("Set the maximum number of consecutive empty lines to be printed.")
|
||||
.hide_short_help(true)
|
||||
@@ -477,7 +504,27 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.help("Strip colors from the input (auto, always, *never*)")
|
||||
.long_help("Specify when to strip ANSI escape sequences from the input. \
|
||||
The automatic mode will remove escape sequences unless the syntax highlighting \
|
||||
language is plain text. Possible values: auto, always, *never*.")
|
||||
language is plain text. Piped output is not stripped. \
|
||||
Possible values: auto, always, *never*.")
|
||||
.hide_short_help(true)
|
||||
)
|
||||
.arg(
|
||||
Arg::new("sanitize")
|
||||
.long("sanitize")
|
||||
.overrides_with("sanitize")
|
||||
.value_name("when")
|
||||
.value_parser(["auto", "always", "never"])
|
||||
.default_value("never")
|
||||
.hide_default_value(true)
|
||||
.help("Sanitize untrusted input for safe display (auto, always, *never*)")
|
||||
.long_help("Specify when to sanitize input bytes for safe terminal display. \
|
||||
Substitutes terminal-active control bytes (escape, cursor moves, charset \
|
||||
switches, beep, etc.) and Unicode bidi / zero-width formatting characters \
|
||||
with the Unicode replacement character (U+FFFD). Escape sequences are not \
|
||||
removed, so they cannot hide text. Overrides --strip-ansi. \
|
||||
Tab, LF, FF, and CRLF pass through. Useful \
|
||||
for displaying untrusted file content (e.g. file-manager preview panes). \
|
||||
Piped output is not sanitized. Possible values: auto, always, *never*.")
|
||||
.hide_short_help(true)
|
||||
)
|
||||
.arg(
|
||||
@@ -562,6 +609,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("unbuffered")
|
||||
.short('u')
|
||||
.long("unbuffered")
|
||||
.overrides_with("unbuffered")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Enable unbuffered input reading for streaming use cases.")
|
||||
.long_help(
|
||||
@@ -583,6 +631,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("no-custom-assets")
|
||||
.long("no-custom-assets")
|
||||
.overrides_with("no-custom-assets")
|
||||
.action(ArgAction::SetTrue)
|
||||
.hide(true)
|
||||
.help("Do not load custom assets"),
|
||||
@@ -663,6 +712,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Arg::new("quiet-empty")
|
||||
.long("quiet-empty")
|
||||
.short('E')
|
||||
.overrides_with("quiet-empty")
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Produce no output when the input is empty.")
|
||||
.long_help(
|
||||
@@ -681,6 +731,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
.arg(
|
||||
Arg::new("set-terminal-title")
|
||||
.long("set-terminal-title")
|
||||
.overrides_with("set-terminal-title")
|
||||
.action(ArgAction::SetTrue)
|
||||
.hide_short_help(true)
|
||||
.help("Sets terminal title to filenames when using a pager."),
|
||||
@@ -710,7 +761,7 @@ pub fn build_app(interactive_output: bool) -> Command {
|
||||
Command::new("cache")
|
||||
.hide(true)
|
||||
.about("Modify the syntax-definition and theme cache")
|
||||
.arg_required_else_help(true)
|
||||
.disable_help_flag(true)
|
||||
.arg(
|
||||
Arg::new("help")
|
||||
.short('h')
|
||||
|
||||
+15
-7
@@ -32,12 +32,13 @@ pub fn config_file() -> PathBuf {
|
||||
pub fn generate_config_file() -> bat::error::Result<()> {
|
||||
let config_file = config_file();
|
||||
if config_file.is_file() {
|
||||
println!(
|
||||
writeln!(
|
||||
io::stdout(),
|
||||
"A config file already exists at: {}",
|
||||
config_file.to_string_lossy()
|
||||
);
|
||||
)?;
|
||||
|
||||
print!("Overwrite? (y/N): ");
|
||||
write!(io::stdout(), "Overwrite? (y/N): ")?;
|
||||
io::stdout().flush()?;
|
||||
let mut decision = String::new();
|
||||
io::stdin().read_line(&mut decision)?;
|
||||
@@ -93,10 +94,11 @@ pub fn generate_config_file() -> bat::error::Result<()> {
|
||||
)
|
||||
})?;
|
||||
|
||||
println!(
|
||||
writeln!(
|
||||
io::stdout(),
|
||||
"Success! Config file written to {}",
|
||||
config_file.to_string_lossy()
|
||||
);
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -108,7 +110,7 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
|
||||
let user_config = config_file();
|
||||
|
||||
if let Ok(c) = fs::read_to_string(&system_config) {
|
||||
config.push_str(&c);
|
||||
config.push_str(strip_bom(&c));
|
||||
config.push('\n');
|
||||
}
|
||||
|
||||
@@ -116,7 +118,7 @@ pub fn get_args_from_config_file() -> Result<Vec<OsString>, shell_words::ParseEr
|
||||
// which can happen when BAT_CONFIG_DIR is set to e.g. "/etc/bat". See #3589.
|
||||
if !same_file(&system_config, &user_config) {
|
||||
if let Ok(c) = fs::read_to_string(&user_config) {
|
||||
config.push_str(&c);
|
||||
config.push_str(strip_bom(&c));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +136,12 @@ pub fn get_args_from_env_opts_var() -> Option<Result<Vec<OsString>, shell_words:
|
||||
env::var("BAT_OPTS").ok().map(|s| get_args_from_str(&s))
|
||||
}
|
||||
|
||||
/// Editors on Windows (e.g. `Set-Content -Encoding UTF8` in Windows PowerShell)
|
||||
/// may prepend a UTF-8 byte order mark, which would otherwise end up in the first argument.
|
||||
fn strip_bom(content: &str) -> &str {
|
||||
content.strip_prefix('\u{feff}').unwrap_or(content)
|
||||
}
|
||||
|
||||
fn get_args_from_str(content: &str) -> Result<Vec<OsString>, shell_words::ParseError> {
|
||||
let args_per_line = content
|
||||
.split('\n')
|
||||
|
||||
+48
-34
@@ -50,6 +50,7 @@ fn build_assets(matches: &clap::ArgMatches, config_dir: &Path, cache_dir: &Path)
|
||||
.get_one::<String>("source")
|
||||
.map(Path::new)
|
||||
.unwrap_or_else(|| config_dir);
|
||||
let mut progress = io::stdout();
|
||||
|
||||
bat::assets::build(
|
||||
source_dir,
|
||||
@@ -57,6 +58,7 @@ fn build_assets(matches: &clap::ArgMatches, config_dir: &Path, cache_dir: &Path)
|
||||
matches.get_flag("acknowledgements"),
|
||||
cache_dir,
|
||||
clap::crate_version!(),
|
||||
&mut progress,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -74,9 +76,9 @@ fn run_cache_subcommand(
|
||||
#[cfg(feature = "build-assets")]
|
||||
build_assets(matches, config_dir, cache_dir)?;
|
||||
#[cfg(not(feature = "build-assets"))]
|
||||
println!("bat has been built without the 'build-assets' feature. The 'cache --build' option is not available.");
|
||||
writeln!(io::stdout(), "bat has been built without the 'build-assets' feature. The 'cache --build' option is not available.")?;
|
||||
} else if matches.get_flag("clear") {
|
||||
clear_assets(cache_dir);
|
||||
clear_assets(cache_dir)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -97,10 +99,10 @@ where
|
||||
map
|
||||
}
|
||||
|
||||
pub fn get_languages(config: &Config, cache_dir: &Path) -> Result<String> {
|
||||
pub fn get_languages(config: &Config, config_dir: &Path, cache_dir: &Path) -> Result<String> {
|
||||
let mut result: String = String::new();
|
||||
|
||||
let assets = assets_from_cache_or_binary(config.use_custom_assets, cache_dir)?;
|
||||
let assets = assets_from_cache_or_binary(config.use_custom_assets, config_dir, cache_dir)?;
|
||||
let mut languages = assets
|
||||
.get_syntaxes()?
|
||||
.iter()
|
||||
@@ -205,7 +207,7 @@ pub fn list_themes(
|
||||
cache_dir: &Path,
|
||||
theme_options: ThemeOptions,
|
||||
) -> Result<()> {
|
||||
let assets = assets_from_cache_or_binary(cfg.use_custom_assets, cache_dir)?;
|
||||
let assets = assets_from_cache_or_binary(cfg.use_custom_assets, config_dir, cache_dir)?;
|
||||
let mut config = cfg.clone();
|
||||
let mut style = HashSet::new();
|
||||
style.insert(StyleComponent::Plain);
|
||||
@@ -262,13 +264,17 @@ pub fn list_themes(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_terminal_title_to(new_terminal_title: String) {
|
||||
fn set_terminal_title_to(new_terminal_title: String) -> Result<()> {
|
||||
let osc_command_for_setting_terminal_title = "\x1b]0;";
|
||||
let osc_end_command = "\x07";
|
||||
// Prevent BEL/ESC/C1 bytes in the title from terminating or nesting the OSC.
|
||||
let safe_title = bat::sanitize_for_terminal(&new_terminal_title);
|
||||
print!("{osc_command_for_setting_terminal_title}{safe_title}{osc_end_command}");
|
||||
io::stdout().flush().unwrap();
|
||||
write!(
|
||||
io::stdout(),
|
||||
"{osc_command_for_setting_terminal_title}{safe_title}{osc_end_command}"
|
||||
)?;
|
||||
io::stdout().flush()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_new_terminal_title(inputs: &Vec<Input>) -> String {
|
||||
@@ -282,17 +288,22 @@ fn get_new_terminal_title(inputs: &Vec<Input>) -> String {
|
||||
new_terminal_title
|
||||
}
|
||||
|
||||
fn run_controller(inputs: Vec<Input>, config: &Config, cache_dir: &Path) -> Result<bool> {
|
||||
let assets = assets_from_cache_or_binary(config.use_custom_assets, cache_dir)?;
|
||||
fn run_controller(
|
||||
inputs: Vec<Input>,
|
||||
config: &Config,
|
||||
config_dir: &Path,
|
||||
cache_dir: &Path,
|
||||
) -> Result<bool> {
|
||||
let assets = assets_from_cache_or_binary(config.use_custom_assets, config_dir, cache_dir)?;
|
||||
let controller = Controller::new(config, &assets);
|
||||
if config.paging_mode != PagingMode::Never && config.set_terminal_title {
|
||||
set_terminal_title_to(get_new_terminal_title(&inputs));
|
||||
set_terminal_title_to(get_new_terminal_title(&inputs))?;
|
||||
}
|
||||
controller.run(inputs, None)
|
||||
}
|
||||
|
||||
#[cfg(feature = "bugreport")]
|
||||
fn invoke_bugreport(app: &App, cache_dir: &Path) {
|
||||
fn invoke_bugreport(app: &App, cache_dir: &Path) -> Result<()> {
|
||||
use bugreport::{bugreport, collector::*, format::Markdown, report::ReportEntry};
|
||||
|
||||
struct ColorSchemeCollector;
|
||||
@@ -329,6 +340,7 @@ fn invoke_bugreport(app: &App, cache_dir: &Path) {
|
||||
.info(CommandLine::default())
|
||||
.info(EnvironmentVariables::list(&[
|
||||
"BAT_CACHE_PATH",
|
||||
"BAT_CONFIG_DIR",
|
||||
"BAT_CONFIG_PATH",
|
||||
"BAT_OPTS",
|
||||
"BAT_PAGER",
|
||||
@@ -370,7 +382,8 @@ fn invoke_bugreport(app: &App, cache_dir: &Path) {
|
||||
))
|
||||
};
|
||||
|
||||
report.print::<Markdown>();
|
||||
writeln!(io::stdout(), "{}", report.format::<Markdown>())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Returns `Err(..)` upon fatal errors. Otherwise, returns `Ok(true)` on full success and
|
||||
@@ -382,21 +395,22 @@ fn run() -> Result<bool> {
|
||||
|
||||
if app.matches.get_flag("diagnostic") {
|
||||
#[cfg(feature = "bugreport")]
|
||||
invoke_bugreport(&app, cache_dir);
|
||||
invoke_bugreport(&app, cache_dir)?;
|
||||
#[cfg(not(feature = "bugreport"))]
|
||||
println!("bat has been built without the 'bugreport' feature. The '--diagnostic' option is not available.");
|
||||
writeln!(io::stdout(), "bat has been built without the 'bugreport' feature. The '--diagnostic' option is not available.")?;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
#[cfg(feature = "application")]
|
||||
if let Some(shell) = app.matches.get_one::<String>("completion") {
|
||||
match shell.as_str() {
|
||||
"bash" => println!("{}", completions::BASH_COMPLETION),
|
||||
"fish" => println!("{}", completions::FISH_COMPLETION),
|
||||
"ps1" => println!("{}", completions::PS1_COMPLETION),
|
||||
"zsh" => println!("{}", completions::ZSH_COMPLETION),
|
||||
let completion = match shell.as_str() {
|
||||
"bash" => completions::BASH_COMPLETION,
|
||||
"fish" => completions::FISH_COMPLETION,
|
||||
"ps1" => completions::PS1_COMPLETION,
|
||||
"zsh" => completions::ZSH_COMPLETION,
|
||||
_ => unreachable!("No completion for shell '{shell}' available."),
|
||||
}
|
||||
};
|
||||
writeln!(io::stdout(), "{completion}")?;
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
@@ -414,10 +428,12 @@ fn run() -> Result<bool> {
|
||||
)?;
|
||||
Ok(true)
|
||||
} else {
|
||||
let inputs = vec![Input::ordinary_file("cache")];
|
||||
let config = app.config(&inputs)?;
|
||||
|
||||
run_controller(inputs, &config, cache_dir)
|
||||
// No arguments provided to cache subcommand - show help
|
||||
let mut cmd = clap_app::build_app(true);
|
||||
if let Some(cache_cmd) = cmd.find_subcommand_mut("cache") {
|
||||
print!("{}", cache_cmd.render_help());
|
||||
}
|
||||
Ok(true)
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
@@ -425,19 +441,17 @@ fn run() -> Result<bool> {
|
||||
let config = app.config(&inputs)?;
|
||||
|
||||
if app.matches.get_flag("list-languages") {
|
||||
let languages: String = get_languages(&config, cache_dir)?;
|
||||
let languages: String = get_languages(&config, config_dir, cache_dir)?;
|
||||
let inputs: Vec<Input> = vec![Input::from_reader(Box::new(languages.as_bytes()))];
|
||||
let plain_config = Config {
|
||||
style_components: StyleComponents::new(StyleComponent::Plain.components(false)),
|
||||
paging_mode: PagingMode::QuitIfOneScreen,
|
||||
..Default::default()
|
||||
};
|
||||
run_controller(inputs, &plain_config, cache_dir)
|
||||
let mut plain_config = config.clone();
|
||||
plain_config.style_components =
|
||||
StyleComponents::new(StyleComponent::Plain.components(false));
|
||||
run_controller(inputs, &plain_config, config_dir, cache_dir)
|
||||
} else if app.matches.get_flag("list-themes") {
|
||||
list_themes(&config, config_dir, cache_dir, app.theme_options())?;
|
||||
Ok(true)
|
||||
} else if app.matches.get_flag("config-file") {
|
||||
println!("{}", config_file().to_string_lossy());
|
||||
writeln!(io::stdout(), "{}", config_file().to_string_lossy())?;
|
||||
Ok(true)
|
||||
} else if app.matches.get_flag("generate-config-file") {
|
||||
generate_config_file()?;
|
||||
@@ -452,7 +466,7 @@ fn run() -> Result<bool> {
|
||||
writeln!(io::stdout(), "{}", bat::assets::get_acknowledgements())?;
|
||||
Ok(true)
|
||||
} else {
|
||||
run_controller(inputs, &config, cache_dir)
|
||||
run_controller(inputs, &config, config_dir, cache_dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
-3
@@ -98,24 +98,31 @@ pub struct Config<'a> {
|
||||
/// cached assets) are not available, assets from the binary will be used instead.
|
||||
pub use_custom_assets: bool,
|
||||
|
||||
// Whether or not to use $LESSOPEN if set
|
||||
/// Whether or not to use $LESSOPEN if set
|
||||
#[cfg(feature = "lessopen")]
|
||||
pub use_lessopen: bool,
|
||||
|
||||
// Whether or not to set terminal title when using a pager
|
||||
/// Whether or not to set terminal title when using a pager
|
||||
pub set_terminal_title: bool,
|
||||
|
||||
/// The maximum number of consecutive empty lines to display
|
||||
pub squeeze_lines: Option<usize>,
|
||||
|
||||
// Whether or not to strip ANSI escape codes from the input
|
||||
/// Whether or not to strip ANSI escape codes from the input
|
||||
pub strip_ansi: StripAnsiMode,
|
||||
|
||||
/// Substitute terminal-active and spoofing-relevant bytes; overrides strip_ansi.
|
||||
pub sanitize: StripAnsiMode,
|
||||
|
||||
/// Whether or not to produce no output when input is empty
|
||||
pub quiet_empty: bool,
|
||||
|
||||
/// Whether or not to use unbuffered input reading for streaming use cases
|
||||
pub unbuffered: bool,
|
||||
|
||||
/// Only number non-blank lines (like `cat -b`). Has no effect if `style_components` doesn't
|
||||
/// include `LineNumbers`.
|
||||
pub number_nonblank: bool,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "minimal-application", feature = "paging"))]
|
||||
|
||||
+29
-4
@@ -18,6 +18,8 @@ use std::io::{self, BufRead, Write};
|
||||
use std::mem;
|
||||
|
||||
use clircle::{Clircle, Identifier};
|
||||
use content_inspector::ContentType;
|
||||
use encoding_rs::{UTF_16BE, UTF_16LE};
|
||||
|
||||
pub struct Controller<'a> {
|
||||
config: &'a Config<'a>,
|
||||
@@ -276,10 +278,33 @@ impl Controller<'_> {
|
||||
}
|
||||
if !reached_eof {
|
||||
if reader.read_line(&mut current_line_buffer)? {
|
||||
// Fill the buffer
|
||||
buffered_lines
|
||||
.push_back((mem::take(&mut current_line_buffer), current_line_number));
|
||||
current_line_number += 1;
|
||||
// Fill the buffer. In number-nonblank mode, don't advance the
|
||||
// line counter for empty lines (content-free lines that contain
|
||||
// only the line terminator).
|
||||
if self.config.number_nonblank
|
||||
&& match reader.content_type {
|
||||
Some(ContentType::UTF_16LE) => UTF_16LE
|
||||
.decode_with_bom_removal(¤t_line_buffer)
|
||||
.0
|
||||
.trim_end_matches(['\r', '\n'])
|
||||
.is_empty(),
|
||||
Some(ContentType::UTF_16BE) => UTF_16BE
|
||||
.decode_with_bom_removal(¤t_line_buffer)
|
||||
.0
|
||||
.trim_end_matches(['\r', '\n'])
|
||||
.is_empty(),
|
||||
_ => current_line_buffer
|
||||
.iter()
|
||||
.all(|&b| b == b'\r' || b == b'\n'),
|
||||
}
|
||||
{
|
||||
buffered_lines
|
||||
.push_back((mem::take(&mut current_line_buffer), current_line_number));
|
||||
} else {
|
||||
buffered_lines
|
||||
.push_back((mem::take(&mut current_line_buffer), current_line_number));
|
||||
current_line_number += 1;
|
||||
}
|
||||
} else {
|
||||
// No more data to read
|
||||
reached_eof = true;
|
||||
|
||||
@@ -45,6 +45,14 @@ impl Decoration for LineNumberDecoration {
|
||||
continuation: bool,
|
||||
_printer: &InteractivePrinter,
|
||||
) -> DecorationText {
|
||||
if line_number == 0 {
|
||||
// Blank line in number-nonblank mode: show empty space instead of a number.
|
||||
return DecorationText {
|
||||
text: self.color.paint(" ".repeat(self.width())).to_string(),
|
||||
width: self.width(),
|
||||
};
|
||||
}
|
||||
|
||||
if continuation {
|
||||
if line_number >= self.cached_wrap_invalid_at {
|
||||
let new_width = self.cached_wrap.width + 1;
|
||||
|
||||
+39
-4
@@ -40,13 +40,31 @@ fn collect_changes_from_hunks(hunks: HunkIter) -> Option<LineChanges> {
|
||||
Some(changes)
|
||||
}
|
||||
|
||||
// The repository config can define filter commands and must not be trusted.
|
||||
fn is_not_repository_config(meta: &gix::config::file::Metadata) -> bool {
|
||||
meta.source.kind() != gix::config::source::Kind::Repository
|
||||
}
|
||||
|
||||
pub fn get_git_diff(filename: &Path) -> Option<LineChanges> {
|
||||
let filepath_absolute = filename.canonicalize().ok()?;
|
||||
let repository = gix::discover(filepath_absolute.parent().ok()?).ok()?;
|
||||
let mut trust_map = gix::sec::trust::Mapping::<gix::open::Options>::default();
|
||||
trust_map.full = trust_map
|
||||
.full
|
||||
.filter_config_section(is_not_repository_config);
|
||||
trust_map.reduced = trust_map
|
||||
.reduced
|
||||
.filter_config_section(is_not_repository_config);
|
||||
let repository = gix::ThreadSafeRepository::discover_opts(
|
||||
filepath_absolute.parent().ok()?,
|
||||
Default::default(),
|
||||
trust_map,
|
||||
)
|
||||
.ok()?
|
||||
.to_thread_local();
|
||||
let repo_path_absolute = repository.workdir()?.canonicalize().ok()?;
|
||||
let filepath_relative_to_repo = gix::path::to_unix_separators_on_windows(gix::path::into_bstr(
|
||||
filepath_absolute.strip_prefix(&repo_path_absolute).ok()?,
|
||||
));
|
||||
let filepath_relative_to_repo = gix::path::to_unix_separators_on_windows(
|
||||
gix::path::into_bstr(filepath_absolute.strip_prefix(&repo_path_absolute).ok()?).ok()?,
|
||||
);
|
||||
let index = repository.index_or_load_from_head_or_empty().ok()?;
|
||||
let index_entry = index.entry_by_path(filepath_relative_to_repo.as_ref())?;
|
||||
let mut cache = repository
|
||||
@@ -179,6 +197,23 @@ mod tests {
|
||||
assert_eq!(changes.get(&2), Some(&LineChange::Added));
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn filter_from_repository_config_is_not_executed() {
|
||||
let repo = setup_repo();
|
||||
let file = create_and_track_file(&repo, "file.txt");
|
||||
let marker = repo.path().join("marker");
|
||||
let clean = format!("touch '{}'; cat", marker.display());
|
||||
git(repo.path(), &["config", "filter.marker.clean", &clean]);
|
||||
std::fs::write(repo.path().join(".gitattributes"), "* filter=marker\n")
|
||||
.expect("can write file");
|
||||
std::fs::write(&file, "file\nline 2 added\n").expect("can write file");
|
||||
|
||||
let changes = get_git_diff(&file).expect("one change");
|
||||
assert_eq!(changes.get(&2), Some(&LineChange::Added));
|
||||
assert!(!marker.exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn faulty_git_version_does_not_panic() {
|
||||
let repo = setup_repo();
|
||||
|
||||
+13
-2
@@ -53,6 +53,17 @@ impl From<String> for Error {
|
||||
|
||||
pub type Result<T> = std::result::Result<T, Error>;
|
||||
|
||||
/// Paint a `[bat error]`/`[bat warning]` style prefix, unless the user asked
|
||||
/// for no colors by setting the `NO_COLOR` environment variable.
|
||||
#[doc(hidden)]
|
||||
pub fn paint_prefix(color: nu_ansi_term::Color, prefix: &str) -> String {
|
||||
if std::env::var_os("NO_COLOR").is_some_and(|x| !x.is_empty()) {
|
||||
prefix.to_owned()
|
||||
} else {
|
||||
color.paint(prefix).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
|
||||
use nu_ansi_term::Color::Red;
|
||||
|
||||
@@ -64,7 +75,7 @@ pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
|
||||
writeln!(
|
||||
output,
|
||||
"{}: Error while parsing metadata.yaml file: {error}",
|
||||
Red.paint("[bat error]"),
|
||||
paint_prefix(Red, "[bat error]"),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
@@ -72,7 +83,7 @@ pub fn default_error_handler(error: &Error, output: &mut dyn Write) {
|
||||
writeln!(
|
||||
&mut std::io::stderr().lock(),
|
||||
"{}: {error}",
|
||||
Red.paint("[bat error]"),
|
||||
paint_prefix(Red, "[bat error]"),
|
||||
)
|
||||
.ok();
|
||||
}
|
||||
|
||||
+111
-4
@@ -9,6 +9,8 @@ use content_inspector::{self, ContentType};
|
||||
|
||||
use crate::error::*;
|
||||
|
||||
const CONTENT_INSPECTION_LIMIT: usize = 1024;
|
||||
|
||||
/// A description of an Input source.
|
||||
/// This tells bat how to refer to the input.
|
||||
#[derive(Clone)]
|
||||
@@ -263,14 +265,38 @@ impl<'a> InputReader<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn try_new<R: BufRead + 'a>(mut reader: R) -> io::Result<InputReader<'a>> {
|
||||
let mut first_line = vec![];
|
||||
reader.read_until(b'\n', &mut first_line)?;
|
||||
// content_inspector scans at most 1024 bytes. Capture the already-buffered
|
||||
// prefix before splitting out the first line so an early newline in binary
|
||||
// data does not shorten the inspected content. This does not consume input
|
||||
// or perform an additional read beyond the one read_until needs anyway.
|
||||
let mut inspection_prefix = {
|
||||
let buffered = reader.fill_buf()?;
|
||||
buffered[..buffered.len().min(CONTENT_INSPECTION_LIMIT)].to_vec()
|
||||
};
|
||||
|
||||
let content_type = inspect_content_type(&first_line);
|
||||
let mut first_line = vec![];
|
||||
if !inspection_prefix.is_empty() {
|
||||
reader.read_until(b'\n', &mut first_line)?;
|
||||
}
|
||||
|
||||
// A custom BufRead implementation may expose less than 1024 bytes at a
|
||||
// time. Keep the old behavior for long first lines in that case.
|
||||
let first_line_prefix_len = first_line.len().min(CONTENT_INSPECTION_LIMIT);
|
||||
if first_line_prefix_len > inspection_prefix.len() {
|
||||
inspection_prefix.clear();
|
||||
inspection_prefix.extend_from_slice(&first_line[..first_line_prefix_len]);
|
||||
}
|
||||
|
||||
let content_type = inspect_content_type(&inspection_prefix);
|
||||
|
||||
if content_type == Some(ContentType::UTF_16LE) {
|
||||
read_utf16_line(&mut reader, &mut first_line, 0x00, 0x0A)?;
|
||||
} else if content_type == Some(ContentType::UTF_16BE) {
|
||||
} else if content_type == Some(ContentType::UTF_16BE)
|
||||
// In UTF-16BE a newline is encoded as 0x00 0x0A, so `read_until(b'\n')` above
|
||||
// may already have read a complete first line. Only keep reading if it did not
|
||||
// (e.g. the 0x0A byte was part of another character such as U+4E0A).
|
||||
&& !(first_line.len() % 2 == 0 && first_line.ends_with(&[0x00, 0x0A]))
|
||||
{
|
||||
read_utf16_line(&mut reader, &mut first_line, 0x0A, 0x00)?;
|
||||
}
|
||||
|
||||
@@ -354,6 +380,7 @@ fn read_utf16_line<R: BufRead>(
|
||||
}
|
||||
buf.extend_from_slice(&temp);
|
||||
if buf.len() >= 2
|
||||
&& buf.len().is_multiple_of(2)
|
||||
&& buf[buf.len() - 2] == preceded_by_char
|
||||
&& buf[buf.len() - 1] == read_until_char
|
||||
{
|
||||
@@ -410,6 +437,53 @@ fn non_zip_pk_prefix_is_not_treated_as_binary() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binary_detection_scans_beyond_first_line_and_preserves_input() {
|
||||
let mut content = vec![b'a'; CONTENT_INSPECTION_LIMIT + 1];
|
||||
content[1] = b'\n';
|
||||
content[CONTENT_INSPECTION_LIMIT - 1] = 0;
|
||||
|
||||
let mut reader = InputReader::new(&content[..]);
|
||||
assert_eq!(Some(ContentType::BINARY), reader.content_type);
|
||||
|
||||
let mut replayed = Vec::new();
|
||||
while reader.read_line(&mut replayed).unwrap() {}
|
||||
assert_eq!(content, replayed);
|
||||
|
||||
drop(reader);
|
||||
|
||||
content[CONTENT_INSPECTION_LIMIT - 1] = b'a';
|
||||
content[CONTENT_INSPECTION_LIMIT] = 0;
|
||||
|
||||
let reader = InputReader::new(&content[..]);
|
||||
assert_eq!(Some(ContentType::UTF_8), reader.content_type);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn input_detection_does_not_read_twice() {
|
||||
struct OneRead(Option<&'static [u8]>);
|
||||
|
||||
impl Read for OneRead {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
match self.0.take() {
|
||||
None => Err(io::Error::new(
|
||||
io::ErrorKind::WouldBlock,
|
||||
"no more data is available yet",
|
||||
)),
|
||||
Some(content) => {
|
||||
buf[..content.len()].copy_from_slice(content);
|
||||
Ok(content.len())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (content, expected) in [(&b"text\n"[..], Some(ContentType::UTF_8)), (&b""[..], None)] {
|
||||
let input = InputReader::try_new(BufReader::new(OneRead(Some(content)))).unwrap();
|
||||
assert_eq!(expected, input.content_type);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn input_open_returns_initial_read_errors() {
|
||||
struct FailingRead;
|
||||
@@ -543,6 +617,39 @@ fn unbuffered_eof_handling() {
|
||||
assert!(buffer.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn utf16_newlines_are_code_unit_aligned() {
|
||||
let cases: &[&[&[u8]]] = &[
|
||||
&[b"\xFF\xFE\x85\x0A\x00\x25\x0A\x00", b"\x7A\x00"],
|
||||
&[
|
||||
b"\xFF\xFE\x73\x00\x0A\x00",
|
||||
b"\x85\x0A\x00\x25\x0A\x00",
|
||||
b"\x7A\x00",
|
||||
],
|
||||
&[
|
||||
b"\xFE\xFF\x4E\x0A\x00\x0A",
|
||||
b"\x25\x00\x0A\x85\x00\x0A",
|
||||
b"\x00\x7A",
|
||||
],
|
||||
];
|
||||
|
||||
for &lines in cases {
|
||||
let content = lines.concat();
|
||||
let mut reader = InputReader::new(&content[..]);
|
||||
assert_eq!(lines[0], &reader.first_line[..]);
|
||||
|
||||
for &line in lines {
|
||||
let mut buffer = vec![];
|
||||
assert!(reader.read_line(&mut buffer).unwrap());
|
||||
assert_eq!(line, &buffer[..]);
|
||||
}
|
||||
|
||||
let mut buffer = vec![];
|
||||
assert!(!reader.read_line(&mut buffer).unwrap());
|
||||
assert!(buffer.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn utf16le_issue3367() {
|
||||
let content = b"\xFF\xFE\x0A\x4E\x00\x4E\x0A\x4F\x00\x52\x0A\x00\
|
||||
|
||||
+3
-3
@@ -355,13 +355,13 @@ fn test_parse_context_fail() {
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum RangeCheckResult {
|
||||
// Within one of the given ranges
|
||||
/// Within one of the given ranges
|
||||
InRange,
|
||||
|
||||
// Before the first range or within two ranges
|
||||
/// Before the first range or within two ranges
|
||||
BeforeOrBetweenRanges,
|
||||
|
||||
// Line number is outside of all ranges and larger than the last range.
|
||||
/// Line number is outside of all ranges and larger than the last range.
|
||||
AfterLastRange,
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -1,7 +1,10 @@
|
||||
#[macro_export]
|
||||
macro_rules! bat_warning {
|
||||
($($arg:tt)*) => ({
|
||||
use nu_ansi_term::Color::Yellow;
|
||||
eprintln!("{}: {}", Yellow.paint("[bat warning]"), format!($($arg)*));
|
||||
eprintln!(
|
||||
"{}: {}",
|
||||
$crate::error::paint_prefix(nu_ansi_term::Color::Yellow, "[bat warning]"),
|
||||
format!($($arg)*)
|
||||
);
|
||||
})
|
||||
}
|
||||
@@ -25,6 +25,7 @@ impl BuiltinPager {
|
||||
let pager = minus::Pager::new();
|
||||
|
||||
let mut input_register = minus::input::HashedEventRegister::default();
|
||||
minus::input::generate_default_bindings(&mut input_register);
|
||||
input_register.add_key_events(&["home"], |_, _| {
|
||||
minus::input::InputEvent::UpdateUpperMark(0)
|
||||
});
|
||||
|
||||
+81
-1
@@ -108,7 +108,7 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
|
||||
_ => ("less", PagerSource::Default),
|
||||
};
|
||||
|
||||
let parts = shell_words::split(cmd)?;
|
||||
let parts = split_command(cmd)?;
|
||||
match parts.split_first() {
|
||||
Some((bin, args)) => {
|
||||
let kind = PagerKind::from_bin(bin);
|
||||
@@ -136,3 +136,83 @@ pub(crate) fn get_pager(config_pager: Option<&str>) -> Result<Option<Pager>, Par
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Splits a pager command into the program and its arguments.
|
||||
fn split_command(cmd: &str) -> Result<Vec<String>, ParseError> {
|
||||
if cfg!(windows) {
|
||||
split_command_windows(cmd)
|
||||
} else {
|
||||
shell_words::split(cmd)
|
||||
}
|
||||
}
|
||||
|
||||
/// Like `shell_words::split`, but `\` is not an escape character, since it is
|
||||
/// the path separator on Windows: `C:\tools\less.exe` must not become
|
||||
/// `C:toolsless.exe`. Single and double quotes still group words.
|
||||
fn split_command_windows(cmd: &str) -> Result<Vec<String>, ParseError> {
|
||||
let mut words = Vec::new();
|
||||
let mut word = String::new();
|
||||
let mut in_word = false;
|
||||
let mut quote = None;
|
||||
|
||||
for c in cmd.chars() {
|
||||
match quote {
|
||||
Some(q) if c == q => quote = None,
|
||||
Some(_) => word.push(c),
|
||||
None if c == '"' || c == '\'' => {
|
||||
quote = Some(c);
|
||||
in_word = true;
|
||||
}
|
||||
None if c.is_whitespace() => {
|
||||
if in_word {
|
||||
words.push(std::mem::take(&mut word));
|
||||
in_word = false;
|
||||
}
|
||||
}
|
||||
None => {
|
||||
word.push(c);
|
||||
in_word = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if quote.is_some() {
|
||||
return Err(ParseError);
|
||||
}
|
||||
if in_word {
|
||||
words.push(word);
|
||||
}
|
||||
Ok(words)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::split_command_windows;
|
||||
|
||||
#[test]
|
||||
fn split_command_windows_keeps_backslashes() {
|
||||
let cases: &[(&str, &[&str])] = &[
|
||||
(r"C:\tools\less.exe", &[r"C:\tools\less.exe"]),
|
||||
(r"C:\tools\less.exe -R", &[r"C:\tools\less.exe", "-R"]),
|
||||
(
|
||||
r#""C:\Program Files\Less\less.exe" -R"#,
|
||||
&[r"C:\Program Files\Less\less.exe", "-R"],
|
||||
),
|
||||
(
|
||||
r"'C:\Program Files\Less\less.exe'",
|
||||
&[r"C:\Program Files\Less\less.exe"],
|
||||
),
|
||||
(r#"less --prompt="a b" """#, &["less", "--prompt=a b", ""]),
|
||||
(" less -R ", &["less", "-R"]),
|
||||
("", &[]),
|
||||
];
|
||||
for (cmd, expected) in cases {
|
||||
assert_eq!(split_command_windows(cmd).unwrap(), *expected, "{cmd}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn split_command_windows_rejects_unclosed_quote() {
|
||||
assert!(split_command_windows(r#""C:\tools\less.exe"#).is_err());
|
||||
}
|
||||
}
|
||||
+225
-4
@@ -138,17 +138,116 @@ pub fn replace_nonprintable(
|
||||
|
||||
/// Strips ANSI escape sequences from the input.
|
||||
pub fn strip_ansi(line: &str) -> String {
|
||||
// Parse without the line ending so an unfinished sequence cannot remove it.
|
||||
let body = line
|
||||
.strip_suffix("\r\n")
|
||||
.or_else(|| line.strip_suffix('\n'))
|
||||
.unwrap_or(line);
|
||||
let mut buffer = String::with_capacity(line.len());
|
||||
|
||||
for seq in EscapeSequenceOffsetsIterator::new(line) {
|
||||
for seq in EscapeSequenceOffsetsIterator::new(body) {
|
||||
if let EscapeSequenceOffsets::Text { .. } = seq {
|
||||
buffer.push_str(&line[seq.index_of_start()..seq.index_past_end()]);
|
||||
buffer.push_str(&body[seq.index_of_start()..seq.index_past_end()]);
|
||||
}
|
||||
}
|
||||
|
||||
buffer.push_str(&line[body.len()..]);
|
||||
buffer
|
||||
}
|
||||
|
||||
/// Substitutes control bytes and bidi / zero-width codepoints with U+FFFD, removing nothing.
|
||||
pub fn sanitize(line: &str) -> String {
|
||||
let mut buffer = String::with_capacity(line.len());
|
||||
let bytes = line.as_bytes();
|
||||
let mut start = 0;
|
||||
let mut i = 0;
|
||||
// Skip directly to the next trigger byte instead of testing each one.
|
||||
while let Some(off) = bytes[i..].iter().position(|&b| is_sanitize_trigger(b)) {
|
||||
i += off;
|
||||
let len = sanitize_at(bytes, i, line, &mut buffer, &mut start);
|
||||
i += len;
|
||||
}
|
||||
buffer.push_str(&line[start..]);
|
||||
buffer
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_sanitize_trigger(b: u8) -> bool {
|
||||
// C0 controls minus \t \n \f; DEL; UTF-8 leads with dangerous codepoints.
|
||||
matches!(b, 0x00..=0x08 | 0x0B | 0x0D..=0x1F | 0x7F | 0xC2 | 0xD8 | 0xE2 | 0xEF)
|
||||
}
|
||||
|
||||
/// Substitutes the byte/sequence at `bytes[i]` (or passes it through on
|
||||
/// false-alarm trigger), flushing the prefix from `start`. Returns bytes consumed.
|
||||
fn sanitize_at(
|
||||
bytes: &[u8],
|
||||
i: usize,
|
||||
full: &str,
|
||||
buffer: &mut String,
|
||||
start: &mut usize,
|
||||
) -> usize {
|
||||
buffer.push_str(&full[*start..i]);
|
||||
let consumed = match bytes[i] {
|
||||
b'\r' if bytes.get(i + 1) == Some(&b'\n') => {
|
||||
buffer.push_str("\r\n");
|
||||
2
|
||||
}
|
||||
// 0xC2 leads U+0080..U+00FF; filter the C1 range.
|
||||
0xC2 if matches!(bytes.get(i + 1), Some(0x80..=0x9F)) => {
|
||||
buffer.push('\u{FFFD}');
|
||||
2
|
||||
}
|
||||
0xE2 if is_dangerous_e2(bytes, i) => {
|
||||
buffer.push('\u{FFFD}');
|
||||
3
|
||||
}
|
||||
// 0xEF 0xBB 0xBF = U+FEFF (BOM / zero-width no-break space).
|
||||
0xEF if bytes.get(i + 1) == Some(&0xBB) && bytes.get(i + 2) == Some(&0xBF) => {
|
||||
buffer.push('\u{FFFD}');
|
||||
3
|
||||
}
|
||||
// 0xD8 0x9C = U+061C (Arabic letter mark, a bidi control). The rest of
|
||||
// the 0xD8 block is ordinary Arabic text.
|
||||
0xD8 if bytes.get(i + 1) == Some(&0x9C) => {
|
||||
buffer.push('\u{FFFD}');
|
||||
2
|
||||
}
|
||||
// False-alarm trigger: pass the full UTF-8 sequence through.
|
||||
lead @ (0xC2 | 0xD8 | 0xE2 | 0xEF) => {
|
||||
let n = utf8_len_from_lead(lead);
|
||||
buffer.push_str(&full[i..i + n]);
|
||||
n
|
||||
}
|
||||
_ => {
|
||||
buffer.push('\u{FFFD}');
|
||||
1
|
||||
}
|
||||
};
|
||||
*start = i + consumed;
|
||||
consumed
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_dangerous_e2(bytes: &[u8], i: usize) -> bool {
|
||||
// U+200B..D (zero-width), U+200E..F (LRM/RLM), U+202A..E (bidi embedding
|
||||
// and override), U+2066..9 (bidi isolates).
|
||||
matches!(
|
||||
(bytes.get(i + 1), bytes.get(i + 2)),
|
||||
(Some(0x80), Some(0x8B..=0x8F | 0xAA..=0xAE)) | (Some(0x81), Some(0xA6..=0xA9))
|
||||
)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn utf8_len_from_lead(lead: u8) -> usize {
|
||||
if lead < 0x80 {
|
||||
1
|
||||
} else if lead < 0xE0 {
|
||||
2
|
||||
} else if lead < 0xF0 {
|
||||
3
|
||||
} else {
|
||||
4
|
||||
}
|
||||
}
|
||||
|
||||
/// Escape C0, DEL, and C1 control characters so a string from an untrusted
|
||||
/// filename or path can be safely written to the terminal.
|
||||
pub fn sanitize_for_terminal(input: &str) -> String {
|
||||
@@ -207,11 +306,21 @@ pub fn strip_overstrike(line: &str, first_backspace: usize) -> String {
|
||||
output
|
||||
}
|
||||
|
||||
/// Specify when to strip ANSI escape sequences from the input.
|
||||
///
|
||||
/// Used for both the `--strip-ansi` and the `--sanitize` option, the latter
|
||||
/// implying the former with the same value.
|
||||
#[derive(Debug, PartialEq, Clone, Copy, Default)]
|
||||
pub enum StripAnsiMode {
|
||||
/// Keep escape sequences in the output
|
||||
#[default]
|
||||
Never,
|
||||
|
||||
/// Strip escape sequences from the output
|
||||
Always,
|
||||
|
||||
/// Strip escape sequences unless the syntax highlighting language is plain
|
||||
/// text, in which case they may be part of what the input wants to display
|
||||
Auto,
|
||||
}
|
||||
|
||||
@@ -270,6 +379,118 @@ fn test_strip_ansi() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_ansi_8bit_c1_introducers() {
|
||||
assert_eq!(strip_ansi("a\u{9B}31mRED\u{9B}0mb"), "aREDb");
|
||||
assert_eq!(strip_ansi("a\x1bP1;0|payload\x1b\\b"), "ab");
|
||||
assert_eq!(strip_ansi("a\u{90}body\u{9C}b"), "ab");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_ansi_single_char_esc() {
|
||||
// strip_ansi must consume both bytes of single-byte ESC sequences (RIS, DECSC, keypad, VT52).
|
||||
assert_eq!(strip_ansi("a\x1bcb"), "ab");
|
||||
assert_eq!(strip_ansi("a\x1b7b\x1b8c"), "abc");
|
||||
assert_eq!(strip_ansi("a\x1b=b\x1b>c"), "abc");
|
||||
assert_eq!(strip_ansi("a\x1bZb"), "ab");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_ansi_preserves_control_bytes() {
|
||||
// strip_ansi removes only ANSI escape sequences; control bytes pass through.
|
||||
assert_eq!(strip_ansi("safe\rEVIL"), "safe\rEVIL");
|
||||
assert_eq!(strip_ansi("a\x08b\x07c\x0E\x0Fd"), "a\x08b\x07c\x0E\x0Fd");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_substitutes_dangerous_bytes() {
|
||||
let r = '\u{FFFD}';
|
||||
assert_eq!(sanitize("safe\rEVIL"), format!("safe{r}EVIL"));
|
||||
assert_eq!(sanitize("a\x08b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\x07b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\x0Bb"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\x0Eb\x0Fc"), format!("a{r}b{r}c"));
|
||||
assert_eq!(sanitize("a\u{8D}b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\u{85}b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("trailing\r"), format!("trailing{r}"));
|
||||
assert_eq!(sanitize("a\x7Fb"), format!("a{r}b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_substitutes_bidi_and_zero_width() {
|
||||
let r = '\u{FFFD}';
|
||||
// Trojan-Source bidi formatting: U+202A..U+202E
|
||||
assert_eq!(sanitize("a\u{202A}b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\u{202E}b"), format!("a{r}b"));
|
||||
// Bidi isolates: U+2066..U+2069
|
||||
assert_eq!(sanitize("a\u{2066}b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\u{2069}b"), format!("a{r}b"));
|
||||
// Zero-width: U+200B..U+200D
|
||||
assert_eq!(sanitize("a\u{200B}b"), format!("a{r}b"));
|
||||
assert_eq!(sanitize("a\u{200D}b"), format!("a{r}b"));
|
||||
// BOM in middle of file: U+FEFF
|
||||
assert_eq!(sanitize("a\u{FEFF}b"), format!("a{r}b"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_substitutes_every_bidi_control() {
|
||||
// Unicode Bidi_Control is exactly these 12 codepoints. Covering only some
|
||||
// of them leaves a reordering attack available through the rest.
|
||||
let r = '\u{FFFD}';
|
||||
for c in [
|
||||
'\u{061C}', '\u{200E}', '\u{200F}', '\u{202A}', '\u{202B}', '\u{202C}', '\u{202D}',
|
||||
'\u{202E}', '\u{2066}', '\u{2067}', '\u{2068}', '\u{2069}',
|
||||
] {
|
||||
assert_eq!(
|
||||
sanitize(&format!("a{c}b")),
|
||||
format!("a{r}b"),
|
||||
"U+{:04X} was not substituted",
|
||||
c as u32
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_preserves_arabic_sharing_the_alm_lead_byte() {
|
||||
// U+061C is reached via lead byte 0xD8, which also leads ordinary Arabic.
|
||||
assert_eq!(
|
||||
sanitize("\u{0600}\u{061F}\u{06FF}"),
|
||||
"\u{0600}\u{061F}\u{06FF}"
|
||||
);
|
||||
assert_eq!(sanitize("مرحبا بالعالم"), "مرحبا بالعالم");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_preserves_legitimate_bytes() {
|
||||
assert_eq!(sanitize("crlf\r\nline\r\n"), "crlf\r\nline\r\n");
|
||||
assert_eq!(sanitize("a\tb\nc"), "a\tb\nc");
|
||||
assert_eq!(sanitize("plain ascii"), "plain ascii");
|
||||
assert_eq!(sanitize("üñíçödé"), "üñíçödé");
|
||||
// FF (U+000C) passes through; section separator in C source / Emacs Lisp.
|
||||
assert_eq!(sanitize("section1\x0Csection2"), "section1\x0Csection2");
|
||||
// Common Unicode that shares a UTF-8 lead byte with dangerous codepoints
|
||||
// must pass through unchanged.
|
||||
assert_eq!(sanitize("snowman ☃ moon ☾"), "snowman ☃ moon ☾");
|
||||
assert_eq!(sanitize("emoji 🎉 ☃"), "emoji 🎉 ☃");
|
||||
assert_eq!(sanitize("0xC2 lead: ÿ ñ ç"), "0xC2 lead: ÿ ñ ç");
|
||||
assert_eq!(sanitize("CJK 漢字 emoji 🦀"), "CJK 漢字 emoji 🦀");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sanitize_keeps_escape_sequence_text() {
|
||||
let r = '\u{FFFD}';
|
||||
// Only the introducer is substituted, the rest of the sequence stays visible.
|
||||
assert_eq!(sanitize("a\x1B[31mb\x1B[0mc"), format!("a{r}[31mb{r}[0mc"));
|
||||
assert_eq!(sanitize("a\u{9B}31mb\u{9B}0mc"), format!("a{r}31mb{r}0mc"));
|
||||
// A string sequence must not hide the command a shell would run.
|
||||
assert_eq!(sanitize("true \x1B]0; rm x"), format!("true {r}]0; rm x"));
|
||||
assert_eq!(sanitize("true \x1B[;rm x"), format!("true {r}[;rm x"));
|
||||
assert_eq!(
|
||||
sanitize("true \x1BP; rm x\x1B\\"),
|
||||
format!("true {r}P; rm x{r}\\")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_strip_overstrike() {
|
||||
// Bold: X\x08X (same char repeated)
|
||||
|
||||
@@ -192,6 +192,14 @@ impl<'a> PrettyPrinter<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
/// Whether to sanitize untrusted input for safe display (default: never)
|
||||
///
|
||||
/// Substitutes control bytes and bidi / zero-width codepoints with U+FFFD. Overrides `strip_ansi`.
|
||||
pub fn sanitize(&mut self, mode: StripAnsiMode) -> &mut Self {
|
||||
self.config.sanitize = mode;
|
||||
self
|
||||
}
|
||||
|
||||
/// Text wrapping mode (default: do not wrap)
|
||||
pub fn wrapping_mode(&mut self, mode: WrappingMode) -> &mut Self {
|
||||
self.config.wrapping_mode = mode;
|
||||
|
||||
+52
-20
@@ -16,7 +16,7 @@ use content_inspector::ContentType;
|
||||
use encoding_rs::{UTF_16BE, UTF_16LE};
|
||||
|
||||
use unicode_segmentation::UnicodeSegmentation;
|
||||
use unicode_width::UnicodeWidthChar;
|
||||
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
|
||||
|
||||
use crate::assets::{HighlightingAssets, SyntaxReferenceInSet};
|
||||
use crate::config::Config;
|
||||
@@ -30,7 +30,8 @@ use crate::input::OpenedInput;
|
||||
use crate::line_range::{MaxBufferedLineNumber, RangeCheckResult};
|
||||
use crate::output::OutputHandle;
|
||||
use crate::preprocessor::{
|
||||
expand_tabs, replace_nonprintable, sanitize_for_terminal, strip_ansi, strip_overstrike,
|
||||
expand_tabs, replace_nonprintable, sanitize, sanitize_for_terminal, strip_ansi,
|
||||
strip_overstrike,
|
||||
};
|
||||
use crate::style::StyleComponent;
|
||||
use crate::terminal::{as_terminal_escaped, to_ansi_color};
|
||||
@@ -49,6 +50,14 @@ fn char_width(c: char) -> usize {
|
||||
c.width().unwrap_or(if c.is_control() { 2 } else { 0 })
|
||||
}
|
||||
|
||||
fn grapheme_width(grapheme: &str) -> usize {
|
||||
if grapheme.chars().any(char::is_control) {
|
||||
grapheme.chars().map(char_width).sum()
|
||||
} else {
|
||||
grapheme.width()
|
||||
}
|
||||
}
|
||||
|
||||
const ANSI_UNDERLINE_ENABLE: EscapeSequence = EscapeSequence::CSI {
|
||||
raw_sequence: "\x1B[4m",
|
||||
parameters: "4",
|
||||
@@ -210,6 +219,7 @@ pub(crate) struct InteractivePrinter<'a> {
|
||||
background_color_highlight: Option<Color>,
|
||||
consecutive_empty_lines: usize,
|
||||
strip_ansi: bool,
|
||||
sanitize: bool,
|
||||
strip_overstrike: bool,
|
||||
}
|
||||
|
||||
@@ -273,7 +283,9 @@ impl<'a> InteractivePrinter<'a> {
|
||||
|
||||
let needs_to_match_syntax = (!is_printing_binary
|
||||
|| matches!(config.binary, BinaryBehavior::AsText))
|
||||
&& (config.colored_output || config.strip_ansi == StripAnsiMode::Auto);
|
||||
&& (config.colored_output
|
||||
|| config.strip_ansi == StripAnsiMode::Auto
|
||||
|| config.sanitize == StripAnsiMode::Auto);
|
||||
|
||||
let (is_plain_text, strip_overstrike, highlighter_from_set) = if needs_to_match_syntax {
|
||||
// Determine the type of syntax for highlighting
|
||||
@@ -319,6 +331,14 @@ impl<'a> InteractivePrinter<'a> {
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let sanitize = match config.sanitize {
|
||||
_ if config.show_nonprintable => false,
|
||||
StripAnsiMode::Always => true,
|
||||
StripAnsiMode::Auto if is_plain_text => false,
|
||||
StripAnsiMode::Auto => true,
|
||||
_ => false,
|
||||
};
|
||||
|
||||
Ok(InteractivePrinter {
|
||||
panel_width,
|
||||
colors,
|
||||
@@ -332,6 +352,7 @@ impl<'a> InteractivePrinter<'a> {
|
||||
background_color_highlight,
|
||||
consecutive_empty_lines: 0,
|
||||
strip_ansi,
|
||||
sanitize,
|
||||
strip_overstrike,
|
||||
})
|
||||
}
|
||||
@@ -675,8 +696,10 @@ impl Printer for InteractivePrinter<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
// If ANSI escape sequences are supposed to be stripped, do it before syntax highlighting.
|
||||
if self.strip_ansi {
|
||||
// Sanitize wins over strip-ansi, because stripping can hide text.
|
||||
if self.sanitize {
|
||||
line = sanitize(&line).into()
|
||||
} else if self.strip_ansi {
|
||||
line = strip_ansi(&line).into()
|
||||
}
|
||||
|
||||
@@ -705,13 +728,15 @@ impl Printer for InteractivePrinter<'_> {
|
||||
let mut cursor_total: usize = 0;
|
||||
let mut panel_wrap: Option<String> = None;
|
||||
|
||||
// Line highlighting
|
||||
let highlight_this_line = self
|
||||
.config
|
||||
.highlighted_lines
|
||||
.0
|
||||
.check(line_number, max_buffered_line_number)
|
||||
== RangeCheckResult::InRange;
|
||||
// Line highlighting. It is done purely with escape sequences (background
|
||||
// color or underline), so it must be skipped when colors are disabled.
|
||||
let highlight_this_line = self.config.colored_output
|
||||
&& self
|
||||
.config
|
||||
.highlighted_lines
|
||||
.0
|
||||
.check(line_number, max_buffered_line_number)
|
||||
== RangeCheckResult::InRange;
|
||||
|
||||
if highlight_this_line && self.config.theme == "ansi" {
|
||||
self.ansi_style.update(ANSI_UNDERLINE_ENABLE);
|
||||
@@ -723,10 +748,17 @@ impl Printer for InteractivePrinter<'_> {
|
||||
|
||||
// Line decorations.
|
||||
if self.panel_width > 0 {
|
||||
let display_line_number =
|
||||
if self.config.number_nonblank && line.trim_end_matches(['\r', '\n']).is_empty() {
|
||||
0
|
||||
} else {
|
||||
line_number
|
||||
};
|
||||
|
||||
let decorations = self
|
||||
.decorations
|
||||
.iter()
|
||||
.map(|d| d.generate(line_number, false, self));
|
||||
.map(|d| d.generate(display_line_number, false, self));
|
||||
|
||||
for deco in decorations {
|
||||
write!(handle, "{} ", deco.text)?;
|
||||
@@ -804,7 +836,7 @@ impl Printer for InteractivePrinter<'_> {
|
||||
let text = self
|
||||
.preprocess(text.trim_end_matches(['\r', '\n']), &mut cursor_total);
|
||||
|
||||
let mut max_width = cursor_max - cursor;
|
||||
let mut max_width = cursor_max.saturating_sub(cursor);
|
||||
|
||||
// line buffer (avoid calling write! for every character)
|
||||
let mut line_buf = String::with_capacity(max_width * 4);
|
||||
@@ -817,13 +849,13 @@ impl Printer for InteractivePrinter<'_> {
|
||||
// For word wrapping, track last whitespace position.
|
||||
let mut last_ws_idx: Option<usize> = None;
|
||||
|
||||
for c in text.chars() {
|
||||
for grapheme in text.graphemes(true) {
|
||||
// calculate the displayed width for next character
|
||||
let cw = char_width(c);
|
||||
let cw = grapheme_width(grapheme);
|
||||
current_width += cw;
|
||||
|
||||
// Track whitespace positions for word wrapping.
|
||||
if word_wrap && c.is_whitespace() {
|
||||
if word_wrap && grapheme.starts_with(char::is_whitespace) {
|
||||
last_ws_idx = Some(line_buf.len());
|
||||
}
|
||||
|
||||
@@ -895,7 +927,7 @@ impl Printer for InteractivePrinter<'_> {
|
||||
// Word wrap: carry remainder to next line.
|
||||
let remainder = line_buf[rs..].to_string();
|
||||
let rem_width: usize =
|
||||
remainder.chars().map(char_width).sum();
|
||||
remainder.graphemes(true).map(grapheme_width).sum();
|
||||
line_buf.clear();
|
||||
line_buf.push_str(&remainder);
|
||||
current_width = rem_width + cw;
|
||||
@@ -906,7 +938,7 @@ impl Printer for InteractivePrinter<'_> {
|
||||
last_ws_idx = None;
|
||||
}
|
||||
|
||||
line_buf.push(c);
|
||||
line_buf.push_str(grapheme);
|
||||
}
|
||||
|
||||
// flush the buffer
|
||||
@@ -943,7 +975,7 @@ impl Printer for InteractivePrinter<'_> {
|
||||
write!(
|
||||
handle,
|
||||
"{}",
|
||||
ansi_style.paint(" ".repeat(cursor_max - cursor))
|
||||
ansi_style.paint(" ".repeat(cursor_max.saturating_sub(cursor)))
|
||||
)?;
|
||||
}
|
||||
writeln!(handle)?;
|
||||
|
||||
+122
-2
@@ -1,5 +1,5 @@
|
||||
use std::{
|
||||
path::Path,
|
||||
path::{Path, PathBuf},
|
||||
sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
@@ -24,6 +24,19 @@ pub(crate) enum Case {
|
||||
Insensitive,
|
||||
}
|
||||
|
||||
/// On Windows, `PathAbs` and `fs::canonicalize` return verbatim paths (`\\?\C:\dir\file`,
|
||||
/// `\\?\UNC\server\share\file`), which a pattern such as `C:/dir/*` would not match.
|
||||
fn without_verbatim_prefix(path: &Path) -> Option<PathBuf> {
|
||||
if !cfg!(windows) {
|
||||
return None;
|
||||
}
|
||||
let path = path.to_str()?;
|
||||
match path.strip_prefix(r"\\?\UNC\") {
|
||||
Some(rest) => Some(format!(r"\\{rest}").into()),
|
||||
None => path.strip_prefix(r"\\?\").map(PathBuf::from),
|
||||
}
|
||||
}
|
||||
|
||||
fn make_glob_matcher(from: &str, case: Case) -> Result<GlobMatcher> {
|
||||
let matcher = GlobBuilder::new(from)
|
||||
.case_insensitive(matches!(case, Case::Insensitive))
|
||||
@@ -162,9 +175,14 @@ impl<'a> SyntaxMapping<'a> {
|
||||
pub fn get_syntax_for(&self, path: impl AsRef<Path>) -> Option<MappingTarget<'a>> {
|
||||
// Try matching on the file name as-is.
|
||||
let candidate = Candidate::new(&path);
|
||||
let simplified_path = without_verbatim_prefix(path.as_ref());
|
||||
let candidate_simplified = simplified_path.as_ref().map(Candidate::new);
|
||||
let candidate_filename = path.as_ref().file_name().map(Candidate::new);
|
||||
for (glob, syntax) in self.all_mappings() {
|
||||
if glob.is_match_candidate(&candidate)
|
||||
|| candidate_simplified
|
||||
.as_ref()
|
||||
.is_some_and(|simplified| glob.is_match_candidate(simplified))
|
||||
|| candidate_filename
|
||||
.as_ref()
|
||||
.is_some_and(|filename| glob.is_match_candidate(filename))
|
||||
@@ -176,7 +194,10 @@ impl<'a> SyntaxMapping<'a> {
|
||||
let file_name = path.as_ref().file_name()?;
|
||||
self.ignored_suffixes
|
||||
.try_with_stripped_suffix(file_name, |stripped_file_name| {
|
||||
Ok(self.get_syntax_for(stripped_file_name))
|
||||
if Path::new(stripped_file_name).file_name().is_none() {
|
||||
return Ok(self.get_syntax_for(stripped_file_name));
|
||||
}
|
||||
Ok(self.get_syntax_for(path.as_ref().with_file_name(stripped_file_name)))
|
||||
})
|
||||
.ok()?
|
||||
}
|
||||
@@ -246,6 +267,105 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn custom_mappings_match_verbatim_paths() {
|
||||
let mut map = SyntaxMapping::new();
|
||||
map.insert("C:/dir/*.myconf", MappingTarget::MapTo("INI"))
|
||||
.unwrap();
|
||||
map.insert(r"\\server\share\*.myconf", MappingTarget::MapTo("TOML"))
|
||||
.unwrap();
|
||||
map.insert(r"\\?\C:\literal\*.myconf", MappingTarget::MapTo("JSON"))
|
||||
.unwrap();
|
||||
|
||||
for (path, expected) in [
|
||||
(r"C:\dir\file.myconf", Some(MappingTarget::MapTo("INI"))),
|
||||
(r"\\?\C:\dir\file.myconf", Some(MappingTarget::MapTo("INI"))),
|
||||
(r"\\?\D:\dir\file.myconf", None),
|
||||
(
|
||||
r"\\?\C:\literal\file.myconf",
|
||||
Some(MappingTarget::MapTo("JSON")),
|
||||
),
|
||||
(
|
||||
r"\\?\UNC\server\share\file.myconf",
|
||||
Some(MappingTarget::MapTo("TOML")),
|
||||
),
|
||||
] {
|
||||
assert_eq!(map.get_syntax_for(path), expected, "{path}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_mappings_with_ignored_suffix_preserve_paths() {
|
||||
for (pattern, parent) in [
|
||||
("/path/to/file.demo", "/path/to"),
|
||||
("/path/to/*.demo", "/path/to"),
|
||||
("path/to/*.demo", "path/to"),
|
||||
] {
|
||||
let mut map = SyntaxMapping::new();
|
||||
map.insert(pattern, MappingTarget::MapTo("JSON")).unwrap();
|
||||
map.insert_ignored_suffix(".custom");
|
||||
|
||||
for suffix in ["", ".bak", ".bak.old", ".custom.custom"] {
|
||||
let path = Path::new(parent).join(format!("file.demo{suffix}"));
|
||||
assert_eq!(
|
||||
map.get_syntax_for(&path),
|
||||
Some(MappingTarget::MapTo("JSON")),
|
||||
"{pattern}: {}",
|
||||
path.display()
|
||||
);
|
||||
}
|
||||
assert_eq!(map.get_syntax_for("/path/elsewhere/file.demo.bak"), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_mappings_with_ignored_suffix_preserve_precedence() {
|
||||
for (first, second) in [("/path/to/*.demo", "*.demo"), ("*.demo", "/path/to/*.demo")] {
|
||||
let mut map = SyntaxMapping::new();
|
||||
map.insert(first, MappingTarget::MapTo("first")).unwrap();
|
||||
map.insert(second, MappingTarget::MapTo("second")).unwrap();
|
||||
assert_eq!(
|
||||
map.get_syntax_for("/path/to/file.demo.bak"),
|
||||
Some(MappingTarget::MapTo("first"))
|
||||
);
|
||||
|
||||
map.insert("*.bak", MappingTarget::MapTo("backup")).unwrap();
|
||||
assert_eq!(
|
||||
map.get_syntax_for("/path/to/file.demo.bak"),
|
||||
Some(MappingTarget::MapTo("backup"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_mappings_with_empty_stripped_filename() {
|
||||
let mut map = SyntaxMapping::new();
|
||||
map.insert("to", MappingTarget::MapTo("parent")).unwrap();
|
||||
map.insert_ignored_suffix(".custom");
|
||||
|
||||
for name in [
|
||||
"~", ".bak", ".custom", "~.bak", ".~", "..bak", "..custom", "...bak",
|
||||
] {
|
||||
assert_eq!(map.get_syntax_for(Path::new("/path/to").join(name)), None);
|
||||
}
|
||||
|
||||
map.insert("", MappingTarget::MapTo("empty")).unwrap();
|
||||
assert_eq!(
|
||||
map.get_syntax_for("/path/to/~.bak"),
|
||||
Some(MappingTarget::MapTo("empty"))
|
||||
);
|
||||
|
||||
for (pattern, name) in [(".", ".~"), (".", "..bak"), ("..", "...bak")] {
|
||||
let mut map = SyntaxMapping::new();
|
||||
map.insert(pattern, MappingTarget::MapTo("dot")).unwrap();
|
||||
assert_eq!(
|
||||
map.get_syntax_for(Path::new("/path/to").join(name)),
|
||||
Some(MappingTarget::MapTo("dot"))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn custom_mappings_override_builtin() {
|
||||
let mut map = SyntaxMapping::new();
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
# kubectl's config file has no extension. The format is YAML.
|
||||
# https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/
|
||||
[mappings]
|
||||
"YAML" = ["**/.kube/config"]
|
||||
@@ -1,5 +1,6 @@
|
||||
# see `man quadlet`
|
||||
[mappings]
|
||||
"INI" = [
|
||||
"*.quadlets",
|
||||
"**/containers/systemd/**/*.{container,volume,network,kube,image,build,pod,artifact}",
|
||||
]
|
||||
@@ -39,7 +39,9 @@ impl Default for IgnoredSuffixes<'_> {
|
||||
|
||||
impl<'a> IgnoredSuffixes<'a> {
|
||||
pub fn add_suffix(&mut self, suffix: &'a str) {
|
||||
self.values.push(suffix)
|
||||
if !suffix.is_empty() {
|
||||
self.values.push(suffix)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn strip_suffix(&self, file_name: &'a str) -> Option<&'a str> {
|
||||
|
||||
+212
-66
@@ -173,8 +173,10 @@ impl Attributes {
|
||||
2 => self.dim = "\x1B[2m".to_owned(),
|
||||
3 => self.italic = "\x1B[3m".to_owned(),
|
||||
4 => self.underline = "\x1B[4m".to_owned(),
|
||||
9 => self.strike = "\x1B[9m".to_owned(),
|
||||
23 => self.italic.clear(),
|
||||
24 => self.underline.clear(),
|
||||
29 => self.strike.clear(),
|
||||
22 => {
|
||||
self.bold.clear();
|
||||
self.dim.clear();
|
||||
@@ -386,12 +388,23 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
||||
}
|
||||
|
||||
fn next_text(&mut self) -> Option<EscapeSequenceOffsets> {
|
||||
self.chars_take_while(|c| c != '\x1B')
|
||||
self.chars_take_while(|c| !is_sequence_introducer(c))
|
||||
.map(|(start, end)| EscapeSequenceOffsets::Text { start, end })
|
||||
}
|
||||
|
||||
fn next_sequence(&mut self) -> Option<EscapeSequenceOffsets> {
|
||||
let (start_sequence, c) = self.chars.next().expect("to not be finished");
|
||||
|
||||
// Handle 8-bit C1 introducers as their 7-bit `ESC <x>` equivalents.
|
||||
match c {
|
||||
'\u{9B}' => return self.next_csi_body(start_sequence),
|
||||
'\u{9D}' => return self.next_osc_body(start_sequence),
|
||||
'\u{90}' | '\u{98}' | '\u{9E}' | '\u{9F}' => {
|
||||
return self.next_string_terminated_body(start_sequence)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
match self.chars.peek() {
|
||||
None => Some(EscapeSequenceOffsets::Unknown {
|
||||
start: start_sequence,
|
||||
@@ -400,12 +413,24 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
||||
|
||||
Some((_, ']')) => self.next_osc(start_sequence),
|
||||
Some((_, '[')) => self.next_csi(start_sequence),
|
||||
Some((i, c)) => match c {
|
||||
// 7-bit DCS/SOS/PM/APC: `ESC P/X/^/_` introduces a string body.
|
||||
Some((_, 'P' | 'X' | '^' | '_')) => {
|
||||
self.chars.next();
|
||||
self.next_string_terminated_body(start_sequence)
|
||||
}
|
||||
Some(&(i, c)) => match c {
|
||||
'\x20'..='\x2F' => self.next_nf(start_sequence),
|
||||
c => Some(EscapeSequenceOffsets::Unknown {
|
||||
start: start_sequence,
|
||||
end: i + c.len_utf8(),
|
||||
}),
|
||||
c => {
|
||||
// Single-byte ESC sequence (RIS, DECSC/DECRC, keypad, VT52 etc.).
|
||||
let end = match self.chars.next() {
|
||||
Some((j, fc)) => j + fc.len_utf8(),
|
||||
None => i + c.len_utf8(),
|
||||
};
|
||||
Some(EscapeSequenceOffsets::Unknown {
|
||||
start: start_sequence,
|
||||
end,
|
||||
})
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -413,73 +438,85 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
||||
fn next_osc(&mut self, start_sequence: usize) -> Option<EscapeSequenceOffsets> {
|
||||
let (osc_open_index, osc_open_char) = self.chars.next().expect("to not be finished");
|
||||
debug_assert_eq!(osc_open_char, ']');
|
||||
let start_command = osc_open_index + osc_open_char.len_utf8();
|
||||
Some(self.read_osc_body(start_sequence, start_command))
|
||||
}
|
||||
|
||||
let mut start_terminator: usize;
|
||||
let mut end_sequence: usize;
|
||||
/// OSC body parser entered after the 8-bit introducer U+009D was consumed.
|
||||
fn next_osc_body(&mut self, start_sequence: usize) -> Option<EscapeSequenceOffsets> {
|
||||
let start_command = start_sequence + '\u{9D}'.len_utf8();
|
||||
Some(self.read_osc_body(start_sequence, start_command))
|
||||
}
|
||||
|
||||
loop {
|
||||
match self.chars_take_while(|c| !matches!(c, '\x07' | '\x1B')) {
|
||||
None => {
|
||||
start_terminator = self.text.len();
|
||||
end_sequence = start_terminator;
|
||||
break;
|
||||
}
|
||||
fn read_osc_body(
|
||||
&mut self,
|
||||
start_sequence: usize,
|
||||
start_command: usize,
|
||||
) -> EscapeSequenceOffsets {
|
||||
let start_terminator = self.take_string_body();
|
||||
|
||||
Some((_, end)) => {
|
||||
start_terminator = end;
|
||||
end_sequence = end;
|
||||
}
|
||||
}
|
||||
|
||||
match self.chars.next() {
|
||||
Some((ti, '\x07')) => {
|
||||
end_sequence = ti + '\x07'.len_utf8();
|
||||
break;
|
||||
}
|
||||
|
||||
Some((ti, '\x1B')) => {
|
||||
match self.chars.next() {
|
||||
Some((i, '\\')) => {
|
||||
end_sequence = i + '\\'.len_utf8();
|
||||
break;
|
||||
}
|
||||
|
||||
None => {
|
||||
end_sequence = ti + '\x1B'.len_utf8();
|
||||
break;
|
||||
}
|
||||
|
||||
_ => {
|
||||
// Repeat, since `\\`(anything) isn't a valid ST.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None => {
|
||||
// Prematurely ends.
|
||||
break;
|
||||
}
|
||||
|
||||
Some((_, tc)) => {
|
||||
panic!("this should not be reached: char {tc:?}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some(EscapeSequenceOffsets::OSC {
|
||||
EscapeSequenceOffsets::OSC {
|
||||
start_sequence,
|
||||
start_command: osc_open_index + osc_open_char.len_utf8(),
|
||||
start_command,
|
||||
start_terminator,
|
||||
end: end_sequence,
|
||||
end: self.take_string_terminator(start_terminator),
|
||||
}
|
||||
}
|
||||
|
||||
/// DCS/SOS/PM/APC body parser. Emitted as `Unknown` so the body is stripped.
|
||||
fn next_string_terminated_body(
|
||||
&mut self,
|
||||
start_sequence: usize,
|
||||
) -> Option<EscapeSequenceOffsets> {
|
||||
let start_terminator = self.take_string_body();
|
||||
|
||||
Some(EscapeSequenceOffsets::Unknown {
|
||||
start: start_sequence,
|
||||
end: self.take_string_terminator(start_terminator),
|
||||
})
|
||||
}
|
||||
|
||||
/// Consumes a string body up to BEL, ESC or U+009C and returns where it ends.
|
||||
fn take_string_body(&mut self) -> usize {
|
||||
match self.chars_take_while(|c| !matches!(c, '\x07' | '\x1B' | '\u{9C}')) {
|
||||
Some((_, end)) => end,
|
||||
None => self.text.len(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Consumes a BEL, U+009C or ESC `\` terminator; any other ESC is left for the next sequence.
|
||||
fn take_string_terminator(&mut self, start_terminator: usize) -> usize {
|
||||
match self.chars.peek() {
|
||||
Some(&(i, c @ ('\x07' | '\u{9C}'))) => {
|
||||
self.chars.next();
|
||||
i + c.len_utf8()
|
||||
}
|
||||
Some(&(i, '\x1B')) if self.text[i + 1..].starts_with('\\') => {
|
||||
self.chars.next();
|
||||
self.chars.next();
|
||||
i + 2
|
||||
}
|
||||
_ => start_terminator,
|
||||
}
|
||||
}
|
||||
|
||||
fn next_csi(&mut self, start_sequence: usize) -> Option<EscapeSequenceOffsets> {
|
||||
let (csi_open_index, csi_open_char) = self.chars.next().expect("to not be finished");
|
||||
debug_assert_eq!(csi_open_char, '[');
|
||||
Some(self.read_csi_body(start_sequence, csi_open_index + csi_open_char.len_utf8()))
|
||||
}
|
||||
|
||||
let start_parameters: usize = csi_open_index + csi_open_char.len_utf8();
|
||||
/// CSI body parser entered after the 8-bit introducer U+009B was consumed.
|
||||
fn next_csi_body(&mut self, start_sequence: usize) -> Option<EscapeSequenceOffsets> {
|
||||
let start_parameters = start_sequence + '\u{9B}'.len_utf8();
|
||||
Some(self.read_csi_body(start_sequence, start_parameters))
|
||||
}
|
||||
|
||||
fn read_csi_body(
|
||||
&mut self,
|
||||
start_sequence: usize,
|
||||
start_parameters: usize,
|
||||
) -> EscapeSequenceOffsets {
|
||||
// Keep iterating while within the range of `0x30-0x3F`.
|
||||
let mut start_intermediates: usize = start_parameters;
|
||||
if let Some((_, end)) = self.chars_take_while(|c| matches!(c, '\x30'..='\x3F')) {
|
||||
@@ -498,13 +535,13 @@ impl<'a> EscapeSequenceOffsetsIterator<'a> {
|
||||
Some((i, c)) => i + c.len_utf8(),
|
||||
};
|
||||
|
||||
Some(EscapeSequenceOffsets::CSI {
|
||||
EscapeSequenceOffsets::CSI {
|
||||
start_sequence,
|
||||
start_parameters,
|
||||
start_intermediates,
|
||||
start_final_byte,
|
||||
end: end_of_sequence,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn next_nf(&mut self, start_sequence: usize) -> Option<EscapeSequenceOffsets> {
|
||||
@@ -543,13 +580,25 @@ impl Iterator for EscapeSequenceOffsetsIterator<'_> {
|
||||
type Item = EscapeSequenceOffsets;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
match self.chars.peek() {
|
||||
Some((_, '\x1B')) => self.next_sequence(),
|
||||
Some((_, c)) if is_sequence_introducer(*c) => self.next_sequence(),
|
||||
Some((_, _)) => self.next_text(),
|
||||
None => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// True for ESC and the 8-bit C1 sequence introducers (DCS/SOS/CSI/OSC/PM/APC).
|
||||
#[inline]
|
||||
fn is_sequence_introducer(c: char) -> bool {
|
||||
if (c as u32) < 0x80 {
|
||||
return c == '\x1B';
|
||||
}
|
||||
matches!(
|
||||
c,
|
||||
'\u{90}' | '\u{98}' | '\u{9B}' | '\u{9D}' | '\u{9E}' | '\u{9F}'
|
||||
)
|
||||
}
|
||||
|
||||
/// An iterator over ANSI/VT escape sequences within a string.
|
||||
///
|
||||
/// ## Example
|
||||
@@ -717,6 +766,79 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_sequence_offsets_iterator_parses_8bit_csi() {
|
||||
let mut iter = EscapeSequenceOffsetsIterator::new("\u{9B}31m");
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::CSI {
|
||||
start_sequence: 0,
|
||||
start_parameters: 2,
|
||||
start_intermediates: 4,
|
||||
start_final_byte: 4,
|
||||
end: 5,
|
||||
})
|
||||
);
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_sequence_offsets_iterator_parses_8bit_osc_with_8bit_st() {
|
||||
let mut iter = EscapeSequenceOffsetsIterator::new("\u{9D}0;title\u{9C}");
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::OSC {
|
||||
start_sequence: 0,
|
||||
start_command: 2,
|
||||
start_terminator: 9,
|
||||
end: 11,
|
||||
})
|
||||
);
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_sequence_offsets_iterator_parses_7bit_dcs_consumes_body() {
|
||||
let mut iter = EscapeSequenceOffsetsIterator::new("\x1BP1;0;|payload\x1B\\rest");
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::Unknown { start: 0, end: 16 })
|
||||
);
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::Text { start: 16, end: 20 })
|
||||
);
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_sequence_offsets_iterator_8bit_dcs_consumes_body() {
|
||||
let mut iter = EscapeSequenceOffsetsIterator::new("\u{90}body\u{9C}rest");
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::Unknown { start: 0, end: 8 })
|
||||
);
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::Text { start: 8, end: 12 })
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_sequence_offsets_iterator_truncated_dcs_consumes_to_eof() {
|
||||
// Unterminated DCS must still be consumed, not emitted as `Text`.
|
||||
let input = "\x1BPno-terminator";
|
||||
let mut iter = EscapeSequenceOffsetsIterator::new(input);
|
||||
assert_eq!(
|
||||
iter.next(),
|
||||
Some(EscapeSequenceOffsets::Unknown {
|
||||
start: 0,
|
||||
end: input.len(),
|
||||
})
|
||||
);
|
||||
assert_eq!(iter.next(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape_sequence_offsets_iterator_parses_csi() {
|
||||
let mut iter = EscapeSequenceOffsetsIterator::new("\x1B[m");
|
||||
@@ -922,10 +1044,10 @@ mod tests {
|
||||
fn test_sgr_attributes_do_not_leak_into_wrong_field() {
|
||||
let mut attrs = crate::vscreen::Attributes::new();
|
||||
|
||||
// Bold, Dim, Italic, Underline, Foreground, Background
|
||||
// Bold, Dim, Italic, Underline, Strike, Foreground, Background
|
||||
attrs.update(EscapeSequence::CSI {
|
||||
raw_sequence: "\x1B[1;2;3;4;31;41m",
|
||||
parameters: "1;2;3;4;31;41",
|
||||
raw_sequence: "\x1B[1;2;3;4;9;31;41m",
|
||||
parameters: "1;2;3;4;9;31;41",
|
||||
intermediates: "",
|
||||
final_byte: "m",
|
||||
});
|
||||
@@ -934,6 +1056,7 @@ mod tests {
|
||||
assert_eq!(attrs.dim, "\x1B[2m");
|
||||
assert_eq!(attrs.italic, "\x1B[3m");
|
||||
assert_eq!(attrs.underline, "\x1B[4m");
|
||||
assert_eq!(attrs.strike, "\x1B[9m");
|
||||
assert_eq!(attrs.foreground, "\x1B[31m");
|
||||
assert_eq!(attrs.background, "\x1B[41m");
|
||||
|
||||
@@ -950,4 +1073,27 @@ mod tests {
|
||||
assert_eq!(attrs.foreground, "\x1B[94m");
|
||||
assert_eq!(attrs.background, "\x1B[103m");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_sgr_strike_is_tracked_and_cleared() {
|
||||
let mut attrs = crate::vscreen::Attributes::new();
|
||||
|
||||
// Strikethrough on (SGR 9) must be tracked so it can be re-emitted.
|
||||
attrs.update(EscapeSequence::CSI {
|
||||
raw_sequence: "\x1B[9m",
|
||||
parameters: "9",
|
||||
intermediates: "",
|
||||
final_byte: "m",
|
||||
});
|
||||
assert_eq!(attrs.strike, "\x1B[9m");
|
||||
|
||||
// Strikethrough off (SGR 29) must clear it, just like italic (23) and underline (24).
|
||||
attrs.update(EscapeSequence::CSI {
|
||||
raw_sequence: "\x1B[29m",
|
||||
parameters: "29",
|
||||
intermediates: "",
|
||||
final_byte: "m",
|
||||
});
|
||||
assert_eq!(attrs.strike, "");
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
pub enum WrappingMode {
|
||||
Character,
|
||||
Word,
|
||||
// The bool specifies whether wrapping has been explicitly disabled by the user via --wrap=never
|
||||
/// The bool specifies whether wrapping has been explicitly disabled by the user via --wrap=never
|
||||
NoWrapping(bool),
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
--show-all
|
||||
+1389
-16
File diff suppressed because it is too large.
Load diff
+184
@@ -0,0 +1,184 @@
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Package example demonstrates CUE syntax.[0m
|
||||
[38;2;249;38;114mpackage[0m[38;2;248;248;242m [0m[38;2;166;226;46mexample[0m
|
||||
|
||||
[38;2;249;38;114mimport[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mstrings[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mlist[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;166;226;46myamlpkg[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mencoding/yaml[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m)[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Definitions and constraints[0m
|
||||
[38;2;255;255;255m#Port[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242m [0m[38;2;249;38;114m>[0m[38;2;190;132;255m0[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242m [0m[38;2;249;38;114m<=[0m[38;2;190;132;255m65535[0m
|
||||
|
||||
[38;2;255;255;255m#Service[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mname[0m[38;2;249;38;114m![0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mstring[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242m [0m[38;2;249;38;114m=~[0m[38;2;248;248;242m"[0m[38;2;230;219;116m^[a-z][a-z0-9-]*$[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mimage[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mstring[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mreplicas[0m[38;2;248;248;242m?[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46muint[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;190;132;255m1[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mports[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;248;248;242m...[0m[38;2;255;255;255m#Port[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255menv[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[3;38;2;166;226;46mstring[0m[38;2;248;248;242m][0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mstring[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mlabels[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mapp[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mname[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m...[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255m_hidden[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255m#nested[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mbool[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Concrete values[0m
|
||||
[38;2;255;255;255mservices[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;255;255;255mName[0m[38;2;248;248;242m=[0m[3;38;2;166;226;46mstring[0m[38;2;248;248;242m][0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255m#Service[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;255;255mname[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mName[0m[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255mservices[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mfrontend[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mimage[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mnginx:1.25[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mreplicas[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mports[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m80[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m443[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255menv[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mLOG_LEVEL[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116minfo[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mTIMEOUT[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m30s[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255mservices[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mbackend[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mimage[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mregistry.example.com/backend:[0m[38;2;230;219;116m\([0m[38;2;255;255;255mversion[0m[38;2;230;219;116m)[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mports[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m8080[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255menv[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mDATABASE_URL[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mpostgres://db:5432/app[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255mversion[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mv1.2.3[0m[38;2;248;248;242m"[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Numbers[0m
|
||||
[38;2;255;255;255mnumbers[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mdecimal[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1_000_000[0m
|
||||
[38;2;248;248;242m [0m[3;38;2;166;226;46mfloat[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m3.14159[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mexponent[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m6.022e23[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mhex[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m0xFF_FF[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255moctal[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m0o755[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mbinary[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m0b1010_1010[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mmultiplier[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1.5Gi[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mkilo[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m4K[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Strings and bytes[0m
|
||||
[38;2;255;255;255mstrs[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255msimple[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mhello, world[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mescaped[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mtab[0m[38;2;190;132;255m\t[0m[38;2;230;219;116mnewline[0m[38;2;190;132;255m\n[0m[38;2;230;219;116municode[0m[38;2;190;132;255m\u00e9[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[3;38;2;166;226;46mbytes[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m'[0m[38;2;230;219;116mraw bytes [0m[38;2;190;132;255m\x00[0m[38;2;190;132;255m\xff[0m[38;2;248;248;242m'[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mraw[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m#"[0m[38;2;230;219;116mno \(interpolation) here[0m[38;2;248;248;242m"#[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mmultiline[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"""[0m
|
||||
[38;2;230;219;116m multiple[0m
|
||||
[38;2;230;219;116m lines with [0m[38;2;230;219;116m\([0m[38;2;255;255;255mversion[0m[38;2;230;219;116m)[0m
|
||||
[38;2;230;219;116m [0m[38;2;248;248;242m"""[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mmultiBytes[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m'''[0m
|
||||
[38;2;230;219;116m byte[0m
|
||||
[38;2;230;219;116m lines[0m
|
||||
[38;2;230;219;116m [0m[38;2;248;248;242m'''[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Builtin types and values[0m
|
||||
[38;2;255;255;255mtypes[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mn[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255mnull[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mb[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mbool[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;190;132;255mfalse[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mi[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint8[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint16[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint32[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint64[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mf[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mfloat32[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mfloat64[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255ms[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mstring[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255my[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mbytes[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mr[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mrune[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mt[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m_[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mx[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mnumber[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Bottom (error) value[0m
|
||||
[38;2;255;255;255mbottom[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m_|_[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Operators and builtins[0m
|
||||
[38;2;255;255;255mops[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255msum[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;249;38;114m*[0m[38;2;190;132;255m3[0m[38;2;248;248;242m [0m[38;2;249;38;114m-[0m[38;2;248;248;242m [0m[38;2;190;132;255m4[0m[38;2;249;38;114m/[0m[38;2;190;132;255m2[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mdivided[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mdiv[0m[38;2;248;248;242m([0m[38;2;190;132;255m7[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mmodulo[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mmod[0m[38;2;248;248;242m([0m[38;2;190;132;255m7[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mquotient[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mquo[0m[38;2;248;248;242m([0m[38;2;249;38;114m-[0m[38;2;190;132;255m7[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mrest[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mrem[0m[38;2;248;248;242m([0m[38;2;249;38;114m-[0m[38;2;190;132;255m7[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255meq[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114m==[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mne[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116ma[0m[38;2;248;248;242m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m!=[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mb[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mboth[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m[38;2;248;248;242m [0m[38;2;249;38;114m&&[0m[38;2;248;248;242m [0m[38;2;190;132;255mfalse[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255meither[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m[38;2;248;248;242m [0m[38;2;249;38;114m||[0m[38;2;248;248;242m [0m[38;2;190;132;255mfalse[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mnot[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;249;38;114m![0m[38;2;190;132;255mtrue[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mmatch[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mabc[0m[38;2;248;248;242m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m=~[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m^a[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mnomatch[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mabc[0m[38;2;248;248;242m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m!~[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m^z[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mlength[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mlen[0m[38;2;248;248;242m([0m[38;2;248;248;242m[[0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m[38;2;248;248;242m][0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mclosed[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mclose[0m[38;2;248;248;242m([0m[38;2;248;248;242m{[0m[38;2;255;255;255ma[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m}[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mupper[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242mstrings[0m[38;2;248;248;242m.[0m[38;2;102;217;239mToUpper[0m[38;2;248;248;242m([0m[38;2;248;248;242m"[0m[38;2;230;219;116mcue[0m[38;2;248;248;242m"[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255msorted[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242mlist[0m[38;2;248;248;242m.[0m[38;2;102;217;239mSort[0m[38;2;248;248;242m([0m[38;2;248;248;242m[[0m[38;2;190;132;255m3[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m][0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mlist[0m[38;2;248;248;242m.[0m[38;2;255;255;255mAscending[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mdisj[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mor[0m[38;2;248;248;242m([0m[38;2;248;248;242m[[0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m[38;2;248;248;242m][0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mconj[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mand[0m[38;2;248;248;242m([0m[38;2;248;248;242m[[0m[3;38;2;166;226;46mint[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;249;38;114m>[0m[38;2;190;132;255m0[0m[38;2;248;248;242m][0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255masYAML[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242myamlpkg[0m[38;2;248;248;242m.[0m[38;2;102;217;239mMarshal[0m[38;2;248;248;242m([0m[38;2;248;248;242m{[0m[38;2;255;255;255ma[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m}[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Nested calls, grouping and interpolated calls[0m
|
||||
[38;2;255;255;255mcalls[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mallPorts[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242mlist[0m[38;2;248;248;242m.[0m[38;2;102;217;239mConcat[0m[38;2;248;248;242m([0m[38;2;248;248;242m[[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m22[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m25[0m[38;2;248;248;242m][0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242mlist[0m[38;2;248;248;242m.[0m[38;2;102;217;239mConcat[0m[38;2;248;248;242m([0m[38;2;248;248;242m[[0m[38;2;249;38;114mfor[0m[38;2;248;248;242m [0m[38;2;255;255;255m_[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255ms[0m[38;2;248;248;242m [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;255;255;255mservices[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;255;255ms[0m[38;2;248;248;242m.[0m[38;2;255;255;255mports[0m[38;2;248;248;242m}[0m[38;2;248;248;242m][0m[38;2;248;248;242m)[0m[38;2;248;248;242m,[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m][0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mnested[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;102;217;239mlen[0m[38;2;248;248;242m([0m[38;2;248;248;242mstrings[0m[38;2;248;248;242m.[0m[38;2;102;217;239mSplit[0m[38;2;248;248;242m([0m[38;2;248;248;242m"[0m[38;2;230;219;116ma,b[0m[38;2;248;248;242m"[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m,[0m[38;2;248;248;242m"[0m[38;2;248;248;242m)[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mgrouped[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m([0m[38;2;248;248;242m([0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;248;248;242m [0m[38;2;190;132;255m3[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255minterp[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mx-[0m[38;2;230;219;116m\([0m[38;2;230;219;116mstrings[0m[38;2;230;219;116m.[0m[38;2;102;217;239mToUpper[0m[38;2;230;219;116m([0m[38;2;230;219;116m"[0m[38;2;230;219;116my[0m[38;2;230;219;116m"[0m[38;2;230;219;116m)[0m[38;2;230;219;116m)[0m[38;2;230;219;116m-[0m[38;2;230;219;116m\([0m[38;2;102;217;239mlen[0m[38;2;230;219;116m([0m[38;2;230;219;116m[[0m[38;2;190;132;255m1[0m[38;2;230;219;116m,[0m[38;2;230;219;116m [0m[38;2;190;132;255m2[0m[38;2;230;219;116m][0m[38;2;230;219;116m)[0m[38;2;230;219;116m)[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Comprehensions[0m
|
||||
[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mprefix[0m[38;2;248;248;242m [0m[38;2;248;248;242m=[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116msvc-[0m[38;2;248;248;242m"[0m
|
||||
|
||||
[38;2;255;255;255mserviceNames[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;249;38;114mfor[0m[38;2;248;248;242m [0m[38;2;255;255;255mk[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mv[0m[38;2;248;248;242m [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;255;255;255mservices[0m[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;255;255;255mv[0m[38;2;248;248;242m.[0m[38;2;255;255;255mreplicas[0m[38;2;248;248;242m [0m[38;2;249;38;114m>[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;255;255mprefix[0m[38;2;248;248;242m [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;255;255;255mk[0m[38;2;248;248;242m}[0m[38;2;248;248;242m][0m
|
||||
|
||||
[38;2;255;255;255mportMap[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m [0m[38;2;255;255;255mname[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255msvc[0m[38;2;248;248;242m [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;255;255;255mservices[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m [0m[38;2;255;255;255mi[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mp[0m[38;2;248;248;242m [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;255;255;255msvc[0m[38;2;248;248;242m.[0m[38;2;255;255;255mports[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m\([0m[38;2;255;255;255mname[0m[38;2;230;219;116m)[0m[38;2;230;219;116m-[0m[38;2;230;219;116m\([0m[38;2;255;255;255mi[0m[38;2;230;219;116m)[0m[38;2;248;248;242m"[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mp[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255mbyPort[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mfor[0m[38;2;248;248;242m [0m[38;2;255;255;255mname[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255msvc[0m[38;2;248;248;242m [0m[38;2;249;38;114min[0m[38;2;248;248;242m [0m[38;2;255;255;255mservices[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;102;217;239mlen[0m[38;2;248;248;242m([0m[38;2;255;255;255msvc[0m[38;2;248;248;242m.[0m[38;2;255;255;255mports[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;249;38;114m>[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m
|
||||
[38;2;248;248;242m [0m[38;2;249;38;114mlet[0m[38;2;248;248;242m [0m[38;2;255;255;255mfirst[0m[38;2;248;248;242m [0m[38;2;248;248;242m=[0m[38;2;248;248;242m [0m[38;2;255;255;255msvc[0m[38;2;248;248;242m.[0m[38;2;255;255;255mports[0m[38;2;248;248;242m[[0m[38;2;190;132;255m0[0m[38;2;248;248;242m][0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m\([0m[38;2;255;255;255mfirst[0m[38;2;230;219;116m)[0m[38;2;248;248;242m"[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mname[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m([0m[38;2;255;255;255mname[0m[38;2;248;248;242m [0m[38;2;249;38;114m+[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116m-image[0m[38;2;248;248;242m"[0m[38;2;248;248;242m)[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255msvc[0m[38;2;248;248;242m.[0m[38;2;255;255;255mimage[0m
|
||||
[38;2;248;248;242m [0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;249;38;114mif[0m[38;2;248;248;242m [0m[38;2;255;255;255mversion[0m[38;2;248;248;242m [0m[38;2;249;38;114m!=[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;248;248;242m"[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mhasVersion[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255mtrue[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Aliases, optional and required fields, pattern constraints[0m
|
||||
[38;2;255;255;255mX[0m[38;2;248;248;242m=[0m[38;2;255;255;255mouter[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255minner[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mref[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255mX[0m[38;2;248;248;242m.[0m[38;2;255;255;255minner[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255moptional[0m[38;2;248;248;242m?[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mstring[0m
|
||||
[38;2;255;255;255mrequired[0m[38;2;249;38;114m![0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint[0m
|
||||
[38;2;248;248;242m[[0m[38;2;249;38;114m=~[0m[38;2;248;248;242m"[0m[38;2;230;219;116m^x-[0m[38;2;248;248;242m"[0m[38;2;248;248;242m][0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mstring[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Attributes[0m
|
||||
[38;2;255;255;255mconfig[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mport[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mint[0m[38;2;248;248;242m [0m[38;2;248;248;242m@[0m[38;2;248;248;242mtag[0m[38;2;248;248;242m([0m[38;2;230;219;116mport[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mtype[0m[38;2;248;248;242m=[0m[38;2;230;219;116mint[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mdebug[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mbool[0m[38;2;248;248;242m [0m[38;2;248;248;242m@[0m[38;2;248;248;242mjson[0m[38;2;248;248;242m([0m[38;2;248;248;242m"[0m[38;2;230;219;116m,omitempty[0m[38;2;248;248;242m"[0m[38;2;248;248;242m)[0m[38;2;248;248;242m [0m[38;2;248;248;242m@[0m[38;2;248;248;242myaml[0m[38;2;248;248;242m([0m[38;2;248;248;242m"[0m[38;2;230;219;116mdebug[0m[38;2;248;248;242m"[0m[38;2;248;248;242m)[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Embedding and default values[0m
|
||||
[38;2;255;255;255m#Base[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mkind[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;248;248;242m"[0m[38;2;230;219;116mbase[0m[38;2;248;248;242m"[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mderived[0m[38;2;248;248;242m"[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255mderived[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;255;255;255m#Base[0m[38;2;248;248;242m [0m[38;2;249;38;114m&[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;255;255mkind[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m"[0m[38;2;230;219;116mderived[0m[38;2;248;248;242m"[0m[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;255;255;255m#Limits[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mcpu[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m{[0m[38;2;255;255;255mmin[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mnumber[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mmax[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[3;38;2;166;226;46mnumber[0m[38;2;248;248;242m}[0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;248;248;242m{[0m[38;2;255;255;255mmin[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m0[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;255;255;255mmax[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;190;132;255m1[0m[38;2;248;248;242m}[0m
|
||||
[38;2;248;248;242m [0m[38;2;255;255;255mtags[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;248;248;242m...[0m[3;38;2;166;226;46mstring[0m[38;2;248;248;242m][0m[38;2;248;248;242m [0m[38;2;249;38;114m|[0m[38;2;248;248;242m [0m[38;2;249;38;114m*[0m[38;2;248;248;242m[[0m[38;2;248;248;242m][0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;117;113;94m//[0m[38;2;117;113;94m Lists[0m
|
||||
[38;2;255;255;255memptyList[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;248;248;242m][0m
|
||||
[38;2;255;255;255mopenList[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242m...[0m[38;2;248;248;242m][0m
|
||||
[38;2;255;255;255mtypedList[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;248;248;242m...[0m[3;38;2;166;226;46mstring[0m[38;2;248;248;242m][0m
|
||||
[38;2;255;255;255mnestedList[0m[38;2;248;248;242m:[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;248;248;242m[[0m[38;2;190;132;255m1[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m][0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;248;248;242m[[0m[38;2;190;132;255m3[0m[38;2;248;248;242m,[0m[38;2;248;248;242m [0m[38;2;190;132;255m4[0m[38;2;248;248;242m][0m[38;2;248;248;242m][0m
|
||||
@@ -0,0 +1,5 @@
|
||||
[38;2;248;248;242m{[0m[38;2;255;255;255ma[0m
|
||||
[38;2;248;248;242m [0m[38;2;117;113;94m/*[0m[38;2;117;113;94m comment [0m[38;2;117;113;94m*/[0m
|
||||
[38;2;248;248;242m}[0m
|
||||
|
||||
[38;2;248;248;242m{[0m[38;2;255;255;255ma[0m[38;2;248;248;242m [0m[38;2;117;113;94m/*[0m[38;2;117;113;94m comment [0m[38;2;117;113;94m*/[0m[38;2;248;248;242m}[0m
|
||||
Vendored
File renamed without changes.
+184
@@ -0,0 +1,184 @@
|
||||
// Package example demonstrates CUE syntax.
|
||||
package example
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"list"
|
||||
yamlpkg "encoding/yaml"
|
||||
)
|
||||
|
||||
// Definitions and constraints
|
||||
#Port: int & >0 & <=65535
|
||||
|
||||
#Service: {
|
||||
name!: string & =~"^[a-z][a-z0-9-]*$"
|
||||
image: string
|
||||
replicas?: uint | *1
|
||||
ports: [...#Port]
|
||||
env: [string]: string
|
||||
labels: {
|
||||
app: name
|
||||
...
|
||||
}
|
||||
_hidden: true
|
||||
#nested: bool
|
||||
}
|
||||
|
||||
// Concrete values
|
||||
services: [Name=string]: #Service & {name: Name}
|
||||
|
||||
services: frontend: {
|
||||
image: "nginx:1.25"
|
||||
replicas: 3
|
||||
ports: [80, 443]
|
||||
env: {
|
||||
LOG_LEVEL: "info"
|
||||
TIMEOUT: "30s"
|
||||
}
|
||||
}
|
||||
|
||||
services: backend: {
|
||||
image: "registry.example.com/backend:\(version)"
|
||||
ports: [8080]
|
||||
env: DATABASE_URL: "postgres://db:5432/app"
|
||||
}
|
||||
|
||||
version: "v1.2.3"
|
||||
|
||||
// Numbers
|
||||
numbers: {
|
||||
decimal: 1_000_000
|
||||
float: 3.14159
|
||||
exponent: 6.022e23
|
||||
hex: 0xFF_FF
|
||||
octal: 0o755
|
||||
binary: 0b1010_1010
|
||||
multiplier: 1.5Gi
|
||||
kilo: 4K
|
||||
}
|
||||
|
||||
// Strings and bytes
|
||||
strs: {
|
||||
simple: "hello, world"
|
||||
escaped: "tab\tnewline\nunicode\u00e9"
|
||||
bytes: 'raw bytes \x00\xff'
|
||||
raw: #"no \(interpolation) here"#
|
||||
multiline: """
|
||||
multiple
|
||||
lines with \(version)
|
||||
"""
|
||||
multiBytes: '''
|
||||
byte
|
||||
lines
|
||||
'''
|
||||
}
|
||||
|
||||
// Builtin types and values
|
||||
types: {
|
||||
n: null
|
||||
b: bool | *false
|
||||
i: int8 | int16 | int32 | int64
|
||||
f: float32 | float64
|
||||
s: string
|
||||
y: bytes
|
||||
r: rune
|
||||
t: _
|
||||
x: number
|
||||
}
|
||||
|
||||
// Bottom (error) value
|
||||
bottom: _|_ | 1
|
||||
|
||||
// Operators and builtins
|
||||
ops: {
|
||||
sum: 1 + 2*3 - 4/2
|
||||
divided: div(7, 2)
|
||||
modulo: mod(7, 2)
|
||||
quotient: quo(-7, 2)
|
||||
rest: rem(-7, 2)
|
||||
eq: 1 == 1
|
||||
ne: "a" != "b"
|
||||
both: true && false
|
||||
either: true || false
|
||||
not: !true
|
||||
match: "abc" =~ "^a"
|
||||
nomatch: "abc" !~ "^z"
|
||||
length: len([1, 2, 3])
|
||||
closed: close({a: 1})
|
||||
upper: strings.ToUpper("cue")
|
||||
sorted: list.Sort([3, 1, 2], list.Ascending)
|
||||
disj: or([1, 2, 3])
|
||||
conj: and([int, >0])
|
||||
asYAML: yamlpkg.Marshal({a: 1})
|
||||
}
|
||||
|
||||
// Nested calls, grouping and interpolated calls
|
||||
calls: {
|
||||
allPorts: list.Concat([
|
||||
[22, 25],
|
||||
list.Concat([for _, s in services {s.ports}]),
|
||||
])
|
||||
nested: len(strings.Split("a,b", ","))
|
||||
grouped: ((1 + 2) * 3)
|
||||
interp: "x-\(strings.ToUpper("y"))-\(len([1, 2]))"
|
||||
}
|
||||
|
||||
// Comprehensions
|
||||
let prefix = "svc-"
|
||||
|
||||
serviceNames: [for k, v in services if v.replicas > 1 {prefix + k}]
|
||||
|
||||
portMap: {
|
||||
for name, svc in services {
|
||||
for i, p in svc.ports {
|
||||
"\(name)-\(i)": p
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
byPort: {
|
||||
for name, svc in services
|
||||
if len(svc.ports) > 0
|
||||
let first = svc.ports[0] {
|
||||
"\(first)": name
|
||||
(name + "-image"): svc.image
|
||||
}
|
||||
}
|
||||
|
||||
if version != "" {
|
||||
hasVersion: true
|
||||
}
|
||||
|
||||
// Aliases, optional and required fields, pattern constraints
|
||||
X=outer: {
|
||||
inner: 1
|
||||
ref: X.inner
|
||||
}
|
||||
|
||||
optional?: string
|
||||
required!: int
|
||||
[=~"^x-"]: string
|
||||
|
||||
// Attributes
|
||||
config: {
|
||||
port: int @tag(port, type=int)
|
||||
debug: bool @json(",omitempty") @yaml("debug")
|
||||
}
|
||||
|
||||
// Embedding and default values
|
||||
#Base: {
|
||||
kind: *"base" | "derived"
|
||||
}
|
||||
|
||||
derived: #Base & {kind: "derived"}
|
||||
|
||||
#Limits: {
|
||||
cpu: {min: number, max: number} | *{min: 0, max: 1}
|
||||
tags: [...string] | *[]
|
||||
}
|
||||
|
||||
// Lists
|
||||
emptyList: []
|
||||
openList: [1, 2, ...]
|
||||
typedList: [...string]
|
||||
nestedList: [[1, 2], [3, 4]]
|
||||
@@ -0,0 +1,5 @@
|
||||
{a
|
||||
/* comment */
|
||||
}
|
||||
|
||||
{a /* comment */}
|
||||
File renamed without changes.
Reference in new issue
Block a user