1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-02-12 07:58:52 +00:00

Merge remote-tracking branch 'origin/master' into fix-1063

This commit is contained in:
Martin Nordholts 2020-12-28 21:57:38 +01:00
commit cc0f8ca813
52 changed files with 422 additions and 710 deletions

View File

@ -22,6 +22,12 @@ jobs:
toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }} toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }}
default: true default: true
profile: minimal # minimal component installation (ie, no documentation) profile: minimal # minimal component installation (ie, no documentation)
components: clippy
- name: Run clippy (on minimum supported rust version to prevent warnings we can't fix)
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets --all-features
- name: Test - name: Test
uses: actions-rs/cargo@v1 uses: actions-rs/cargo@v1
with: with:
@ -152,6 +158,8 @@ jobs:
echo ::set-output name=PKG_NAME::${PKG_NAME} echo ::set-output name=PKG_NAME::${PKG_NAME}
# deployable tag? (ie, leading "vM" or "M"; M == version number) # deployable tag? (ie, leading "vM" or "M"; M == version number)
unset DEPLOY ; if [[ $REF_TAG =~ ^[vV]?[0-9].* ]]; then DEPLOY='true' ; fi unset DEPLOY ; if [[ $REF_TAG =~ ^[vV]?[0-9].* ]]; then DEPLOY='true' ; fi
# unset deploy on ubuntu-18.04 x64 - we will deploy the tarball/deb built on ubuntu-16.04 x64
if [ "${{ matrix.job.os }}" = "ubuntu-18.04" ] && [ "${{ matrix.job.target }}" = "x86_64-unknown-linux-gnu" ]; then unset DEPLOY; fi
echo set-output name=DEPLOY::${DEPLOY:-<empty>/false} echo set-output name=DEPLOY::${DEPLOY:-<empty>/false}
echo ::set-output name=DEPLOY::${DEPLOY} echo ::set-output name=DEPLOY::${DEPLOY}
# DPKG architecture? # DPKG architecture?
@ -274,6 +282,7 @@ jobs:
shell: bash shell: bash
run: | run: |
ARCHIVE_DIR='${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/' ARCHIVE_DIR='${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_BASENAME }}/'
COPYRIGHT_YEARS="2018 - "$(date "+%Y")
# Binary # Binary
cp 'target/${{ matrix.job.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}' "$ARCHIVE_DIR" cp 'target/${{ matrix.job.target }}/release/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}' "$ARCHIVE_DIR"
@ -283,8 +292,8 @@ jobs:
# Man page # Man page
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/manual/bat.1 "$ARCHIVE_DIR" cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/manual/bat.1 "$ARCHIVE_DIR"
# README and LICENSE files # README, LICENSE and CHANGELOG files
cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "$ARCHIVE_DIR" cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR"
# Autocompletion files # Autocompletion files
cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.fish "$ARCHIVE_DIR/autocomplete/${{ env.PROJECT_NAME }}.fish" cp 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.fish "$ARCHIVE_DIR/autocomplete/${{ env.PROJECT_NAME }}.fish"
@ -308,24 +317,27 @@ jobs:
# Man page # Man page
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/manual/bat.1 "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1" install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/manual/bat.1 "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"
gzip --best "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1" gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1"
# Autocompletion files # Autocompletion files
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.fish "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ env.PROJECT_NAME }}.fish" install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.fish "${DPKG_DIR}/usr/share/fish/vendor_completions.d/${{ env.PROJECT_NAME }}.fish"
install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.zsh "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ env.PROJECT_NAME }}" install -Dm644 'target/${{ matrix.job.target }}/release/build/${{ env.PROJECT_NAME }}'-*/out/assets/completions/bat.zsh "${DPKG_DIR}/usr/share/zsh/vendor-completions/_${{ env.PROJECT_NAME }}"
# README and LICENSE # README and LICENSE
install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${{ env.PROJECT_NAME }}/README.md" install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/README.md"
install -Dm644 "LICENSE-MIT" "${DPKG_DIR}/usr/share/doc/${{ env.PROJECT_NAME }}/LICENSE-MIT" install -Dm644 "LICENSE-MIT" "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/LICENSE-MIT"
install -Dm644 "LICENSE-APACHE" "${DPKG_DIR}/usr/share/doc/${{ env.PROJECT_NAME }}/LICENSE-APACHE" install -Dm644 "LICENSE-APACHE" "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/LICENSE-APACHE"
install -Dm644 "CHANGELOG.md" "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/changelog"
gzip -n --best "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/changelog"
cat > "${DPKG_DIR}/usr/share/doc/${{ env.PROJECT_NAME }}/copyright" <<EOF cat > "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/copyright" <<EOF
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: ${{ env.PROJECT_NAME }} Upstream-Name: ${{ env.PROJECT_NAME }}
Source: ${{ env.PROJECT_HOMEPAGE }} Source: ${{ env.PROJECT_HOMEPAGE }}
Files: * Files: *
Copyright: ${{ env.PROJECT_MAINTAINER }} Copyright: ${{ env.PROJECT_MAINTAINER }}
Copyright: $COPYRIGHT_YEARS ${{ env.PROJECT_MAINTAINER }}
License: Apache-2.0 or MIT License: Apache-2.0 or MIT
License: Apache-2.0 License: Apache-2.0
@ -357,6 +369,7 @@ jobs:
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
EOF EOF
chmod 644 "${DPKG_DIR}/usr/share/doc/${{ steps.vars.outputs.DPKG_BASENAME }}/copyright"
# control file # control file
mkdir -p "${DPKG_DIR}/DEBIAN" mkdir -p "${DPKG_DIR}/DEBIAN"
@ -370,7 +383,7 @@ jobs:
Architecture: ${{ steps.vars.outputs.DPKG_ARCH }} Architecture: ${{ steps.vars.outputs.DPKG_ARCH }}
Provides: ${{ env.PROJECT_NAME }} Provides: ${{ env.PROJECT_NAME }}
Conflicts: ${{ steps.vars.outputs.DPKG_CONFLICTS }} Conflicts: ${{ steps.vars.outputs.DPKG_CONFLICTS }}
Description: A cat(1) clone with wings. Description: cat(1) clone with wings.
A cat(1) clone with syntax highlighting and Git integration. A cat(1) clone with syntax highlighting and Git integration.
EOF EOF

7
.gitmodules vendored
View File

@ -185,9 +185,6 @@
[submodule "assets/syntaxes/02_Extra/AsciiDoc"] [submodule "assets/syntaxes/02_Extra/AsciiDoc"]
path = assets/syntaxes/02_Extra/AsciiDoc path = assets/syntaxes/02_Extra/AsciiDoc
url = https://github.com/asciidoctor/sublimetext-asciidoc.git url = https://github.com/asciidoctor/sublimetext-asciidoc.git
[submodule "assets/themes/gruvbox"]
path = assets/themes/gruvbox
url = https://github.com/peaceant/gruvbox.git
[submodule "assets/syntaxes/02_Extra/GLSL"] [submodule "assets/syntaxes/02_Extra/GLSL"]
path = assets/syntaxes/02_Extra/GLSL path = assets/syntaxes/02_Extra/GLSL
url = https://github.com/euler0/sublime-glsl url = https://github.com/euler0/sublime-glsl
@ -206,3 +203,7 @@
[submodule "assets/themes/Coldark"] [submodule "assets/themes/Coldark"]
path = assets/themes/Coldark path = assets/themes/Coldark
url = https://github.com/ArmandPhilippot/coldark-bat.git url = https://github.com/ArmandPhilippot/coldark-bat.git
[submodule "assets/themes/gruvbox"]
path = assets/themes/gruvbox
url = https://github.com/subnut/gruvbox-tmTheme.git
branch = bat-source

View File

@ -2,27 +2,41 @@
## Features ## Features
- Use a pager when `bat --list-languages` is called, see #1394 (@stku1985)
## Bugfixes ## Bugfixes
- If the last line doesn't end with a newline character, don't add it if `--style=plain`, see #1438 (@Enselic)
- Only print themes hint in interactive mode (`bat --list-themes`), see #1439 (@rsteube)
- Make ./tests/syntax-tests/regression_test.sh work on recent versions of macOS, see #1443 (@Enselic)
- VimL syntax highlighting fix, see #1450 (@esensar)
- Ignore PAGER=most by default with a warning to stderr, but allow override with BAT_PAGER or --config, see #1063 (@Enselic) - Ignore PAGER=most by default with a warning to stderr, but allow override with BAT_PAGER or --config, see #1063 (@Enselic)
## Other ## Other
- Performance improvements, see #1421 (@LovecraftianHorror)
## Syntaxes ## Syntaxes
## New themes ## New themes
- `ansi` replaces `ansi-dark` and `ansi-light`, see #1104 and #1412 (@mk12)
- The Gruvbox theme has been updated, see #1291 (@j0hnmeow). **Breaking change:** users that were previously usuing `gruvbox` or `gruvbox-white` should update and use `gruvbox-dark`/`gruvbox-light` instead.
## `bat` as a library ## `bat` as a library
## Packaging ## Packaging
- `bat` is now available on snapstore with package name called `batcat`, see #1401 (@purveshpatel511)
# v0.17.1 # v0.17.1
## Bugfixes ## Bugfixes
- Running `bat` without arguments fails ("output file is also an input"), see #1396 - Running `bat` without arguments fails ("output file is also an input"), see #1396
# v0.17.0 # v0.17.0
## Features ## Features

View File

@ -8,12 +8,12 @@ Thank you for considering to contribute to `bat`!
If your contribution changes the behavior of `bat` (as opposed to a typo-fix If your contribution changes the behavior of `bat` (as opposed to a typo-fix
in the documentation), please update the [`CHANGELOG.md`](CHANGELOG.md) file in the documentation), please update the [`CHANGELOG.md`](CHANGELOG.md) file
and describe your changes. This makes the release proess much easier and and describe your changes. This makes the release process much easier and
therefore helps to get your changes into a new `bat` release faster. therefore helps to get your changes into a new `bat` release faster.
The top of the `CHANGELOG` contains a *"unreleased"* section with a few The top of the `CHANGELOG` contains a *"unreleased"* section with a few
subsections (Features, Bugfixes, …). Please add your entry to the subsection subsections (Features, Bugfixes, …). Please add your entry to the subsection
that best describes your change that best describes your change.
Entries follow this format: Entries follow this format:
``` ```

4
Cargo.lock generated
View File

@ -56,9 +56,9 @@ checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
[[package]] [[package]]
name = "assert_cmd" name = "assert_cmd"
version = "1.0.1" version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c88b9ca26f9c16ec830350d309397e74ee9abdfd8eb1f71cb6ecc71a3fc818da" checksum = "3dc1679af9a1ab4bea16f228b05d18f8363f8327b1fa8db00d2760cfafc6b61e"
dependencies = [ dependencies = [
"doc-comment", "doc-comment",
"predicates", "predicates",

View File

@ -5,7 +5,6 @@ description="A cat(1) clone with wings."
homepage = "https://github.com/sharkdp/bat" homepage = "https://github.com/sharkdp/bat"
license = "MIT/Apache-2.0" license = "MIT/Apache-2.0"
name = "bat" name = "bat"
readme = "README.md"
repository = "https://github.com/sharkdp/bat" repository = "https://github.com/sharkdp/bat"
version = "0.17.1" version = "0.17.1"
exclude = [ exclude = [
@ -74,7 +73,7 @@ default-features = false
[dev-dependencies] [dev-dependencies]
tempdir = "0.3" tempdir = "0.3"
assert_cmd = "1.0.1" assert_cmd = "1.0.2"
predicates = "1.0.5" predicates = "1.0.5"
[build-dependencies] [build-dependencies]

View File

@ -196,7 +196,7 @@ If your Ubuntu/Debian installation is new enough you can simply run:
apt install bat apt install bat
``` ```
If you install `bat` this way, please note that the executable may be installed as `batcat` instead of `bat` (due to [a name **Important**: If you install `bat` this way, please note that the executable may be installed as `batcat` instead of `bat` (due to [a name
clash with another package](https://github.com/sharkdp/bat/issues/982)). You can set up a `bat -> batcat` symlink or alias to prevent any issues that may come up because of this and to be consistent with other distributions: clash with another package](https://github.com/sharkdp/bat/issues/982)). You can set up a `bat -> batcat` symlink or alias to prevent any issues that may come up because of this and to be consistent with other distributions:
``` bash ``` bash
mkdir -p ~/.local/bin mkdir -p ~/.local/bin
@ -256,6 +256,13 @@ You can install `bat` via xbps-install:
xbps-install -S bat xbps-install -S bat
``` ```
### On Termux
You can install `bat` via pkg:
```bash
pkg install bat
```
### On FreeBSD ### On FreeBSD
You can install a precompiled [`bat` package](https://www.freshports.org/textproc/bat) with pkg: You can install a precompiled [`bat` package](https://www.freshports.org/textproc/bat) with pkg:
@ -287,6 +294,15 @@ You can install `bat` with zypper:
zypper install bat zypper install bat
``` ```
### Via snap package
```
sudo snap install batcat
```
[Get it from the Snap Store](https://snapcraft.io/batcat)
### On macOS (or Linux) via Homebrew ### On macOS (or Linux) via Homebrew
You can install `bat` with [Homebrew on MacOS](https://formulae.brew.sh/formula/bat) or [Homebrew on Linux](https://formulae.brew.sh/formula-linux/bat): You can install `bat` with [Homebrew on MacOS](https://formulae.brew.sh/formula/bat) or [Homebrew on Linux](https://formulae.brew.sh/formula-linux/bat):
@ -374,12 +390,11 @@ You can also use a custom theme by following the
### 8-bit themes ### 8-bit themes
`bat` has four themes that always use [8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors), `bat` has three themes that always use [8-bit colors](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors),
even when truecolor support is available: even when truecolor support is available:
- `ansi-dark` looks decent on any terminal with a dark background. It uses 3-bit colors: black, red, - `ansi` looks decent on any terminal. It uses 3-bit colors: black, red, green,
green, yellow, blue, magenta, cyan, and white. yellow, blue, magenta, cyan, and white.
- `ansi-light` is like `ansi-dark`, but for terminals with a light background.
- `base16` is designed for [base16](https://github.com/chriskempson/base16) terminal themes. It uses - `base16` is designed for [base16](https://github.com/chriskempson/base16) terminal themes. It uses
4-bit colors (3-bit colors plus bright variants) in accordance with the 4-bit colors (3-bit colors plus bright variants) in accordance with the
[base16 styling guidelines](https://github.com/chriskempson/base16/blob/master/styling.md). [base16 styling guidelines](https://github.com/chriskempson/base16/blob/master/styling.md).

BIN
assets/syntaxes.bin vendored

Binary file not shown.

@ -1 +1 @@
Subproject commit e593eb6d42a5f1881ba6c75698bd0fb78a9b8871 Subproject commit e23926eca1b6a0bd0b572b7191aead9f77c748d1

@ -1 +1 @@
Subproject commit c9d84587eb1a6eb34457a875f21b9b1a29306be3 Subproject commit 59304d6c7b5019091b532a3197251e393e1db7b2

@ -1 +1 @@
Subproject commit bf92f5b7b69c8ea641d6822fd6d12cc2d9341956 Subproject commit aee0676f379c0503f9c557e24aa2816575e0a4d1

@ -1 +1 @@
Subproject commit ed40c3bc814cd0c8107dbbb8fcd95946b33217f0 Subproject commit 23afc890977bb1fd43fd05e7d983f994993d4982

View File

@ -75,10 +75,10 @@ contexts:
- match: '''(''''|\n[^\S\n]*\\|[^\n''])*''' - match: '''(''''|\n[^\S\n]*\\|[^\n''])*'''
scope: string.quoted.single.viml scope: string.quoted.single.viml
string_regex: string_regex:
- match: '/(\\\\|\\/|\n[^\S\n]*\\|[^\n/])*/' - match: '[gvs]{1}/(\\\\|\\/|\n[^\S\n]*\\|[^\n/])*/'
scope: string.regexp.viml scope: string.regexp.viml
support_function: support_function:
- match: \b(set(local|global)?|let|command|filetype|colorscheme|\w*map|\w*a(b|brev)?|syn|exe(c|cute)?|ec(ho|)?|au(tocmd|)?)\b - match: \b(set(local|global)?|let|command|filetype|syntax|colorscheme|\w*map|\w*a(b|brev)?|syn|exe(c|cute)?|ec(ho|)?|au(tocmd|)?)\b
scope: support.function.viml scope: support.function.viml
support_type: support_type:
- match: <.*?> - match: <.*?>

@ -1 +1 @@
Subproject commit 1ddcb320aca1bf31b0048a3109540475d5af64e2 Subproject commit 201816b609abf7ccf583f7e888f6dc4121410d70

BIN
assets/themes.bin vendored

Binary file not shown.

@ -1 +1 @@
Subproject commit b4a1c74d8d5bdd136ec530e5905b810272472545 Subproject commit e44750b2a9629dd12d8ed3ad9fd50c77232170b9

View File

@ -1,504 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!--
The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI
palette number from 00 to 0f, and AA is the special value 00 to indicate
that this encoding is being used.
-->
<key>author</key>
<string>Template: Chris Kempson, Scheme: Mitchell Kember</string>
<key>name</key>
<string>ANSI Light</string>
<key>colorSpaceName</key>
<string>sRGB</string>
<key>settings</key>
<array>
<dict>
<key>settings</key>
<dict>
<key>background</key>
<string>#07000000</string>
<key>caret</key>
<string>#00000000</string>
<key>foreground</key>
<string>#00000000</string>
<key>invisibles</key>
<string>#00000000</string>
<key>lineHighlight</key>
<string>#00000000</string>
<key>selection</key>
<string>#00000000</string>
<key>gutter</key>
<string>#07000000</string>
<key>gutterForeground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Text</string>
<key>scope</key>
<string>variable.parameter.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Comments</string>
<key>scope</key>
<string>comment, punctuation.definition.comment</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#02000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Punctuation</string>
<key>scope</key>
<string>punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Delimiters</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Operators</string>
<key>scope</key>
<string>keyword.operator</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Keywords</string>
<key>scope</key>
<string>keyword</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#05000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Variables</string>
<key>scope</key>
<string>variable</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Functions</string>
<key>scope</key>
<string>entity.name.function, meta.require, support.function.any-method</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#04000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Labels</string>
<key>scope</key>
<string>entity.name.label</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#06000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Classes</string>
<key>scope</key>
<string>support.class, entity.name.class, entity.name.type.class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Classes</string>
<key>scope</key>
<string>meta.class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Methods</string>
<key>scope</key>
<string>keyword.other.special-method</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#04000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Storage</string>
<key>scope</key>
<string>storage</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#05000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Support</string>
<key>scope</key>
<string>support.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#06000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Strings, Inherited Class</string>
<key>scope</key>
<string>string, constant.other.symbol, entity.other.inherited-class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#02000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Integers</string>
<key>scope</key>
<string>constant.numeric</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Floats</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Boolean</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Constants</string>
<key>scope</key>
<string>constant</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Tags</string>
<key>scope</key>
<string>entity.name.tag</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#01000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Attributes</string>
<key>scope</key>
<string>entity.other.attribute-name</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Attribute IDs</string>
<key>scope</key>
<string>entity.other.attribute-name.id, punctuation.definition.entity</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#04000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Selector</string>
<key>scope</key>
<string>meta.selector</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#05000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Values</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Headings</string>
<key>scope</key>
<string>markup.heading punctuation.definition.heading, entity.name.section</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string></string>
<key>foreground</key>
<string>#04000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Units</string>
<key>scope</key>
<string>keyword.other.unit</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Bold</string>
<key>scope</key>
<string>markup.bold, punctuation.definition.bold</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>bold</string>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Italic</string>
<key>scope</key>
<string>markup.italic, punctuation.definition.italic</string>
<key>settings</key>
<dict>
<key>fontStyle</key>
<string>italic</string>
<key>foreground</key>
<string>#05000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Code</string>
<key>scope</key>
<string>markup.raw.inline</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#02000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Link Text</string>
<key>scope</key>
<string>string.other.link, punctuation.definition.string.end.markdown, punctuation.definition.string.begin.markdown</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#01000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Link Url</string>
<key>scope</key>
<string>meta.link</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Quotes</string>
<key>scope</key>
<string>markup.quote</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#03000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Inserted</string>
<key>scope</key>
<string>markup.inserted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#02000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Deleted</string>
<key>scope</key>
<string>markup.deleted</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#01000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Changed</string>
<key>scope</key>
<string>markup.changed</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#05000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Colors</string>
<key>scope</key>
<string>constant.other.color</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#06000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Regular Expressions</string>
<key>scope</key>
<string>string.regexp</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#06000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Escape Characters</string>
<key>scope</key>
<string>constant.character.escape</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#06000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Embedded</string>
<key>scope</key>
<string>punctuation.section.embedded, variable.interpolation</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#05000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Illegal</string>
<key>scope</key>
<string>invalid.illegal</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#01000000</string>
<key>foreground</key>
<string>#00000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Broken</string>
<key>scope</key>
<string>invalid.broken</string>
<key>settings</key>
<dict>
<key>background</key>
<string>#03000000</string>
<key>foreground</key>
<string>#07000000</string>
</dict>
</dict>
</array>
<key>uuid</key>
<string>uuid</string>
</dict>
</plist>

View File

@ -3,14 +3,14 @@
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<!-- <!--
The colors in this theme are encoded as #RRGGBBAA where RR is an ANSI The colors in this theme are encoded as #RRGGBBAA where:
palette number from 00 to 0f, and AA is the special value 00 to indicate * If AA is 00, then RR is an ANSI palette number from 00 to 07.
that this encoding is being used. * If AA is 01, the terminal's default fg/bg color is used.
--> -->
<key>author</key> <key>author</key>
<string>Template: Chris Kempson, Scheme: Mitchell Kember</string> <string>Template: Chris Kempson, Scheme: Mitchell Kember</string>
<key>name</key> <key>name</key>
<string>ANSI Dark</string> <string>ANSI</string>
<key>colorSpaceName</key> <key>colorSpaceName</key>
<string>sRGB</string> <string>sRGB</string>
<key>settings</key> <key>settings</key>
@ -19,32 +19,17 @@
<key>settings</key> <key>settings</key>
<dict> <dict>
<key>background</key> <key>background</key>
<string>#00000000</string> <string>#00000001</string>
<key>caret</key>
<string>#07000000</string>
<key>foreground</key> <key>foreground</key>
<string>#07000000</string> <string>#00000001</string>
<key>invisibles</key> <!--
<string>#07000000</string> Explicitly set the gutter color since bat falls back to a
<key>lineHighlight</key> hardcoded DEFAULT_GUTTER_COLOR otherwise.
<string>#07000000</string> -->
<key>selection</key>
<string>#07000000</string>
<key>gutter</key> <key>gutter</key>
<string>#00000000</string> <string>#00000001</string>
<key>gutterForeground</key> <key>gutterForeground</key>
<string>#07000000</string> <string>#00000001</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Text</string>
<key>scope</key>
<string>variable.parameter.function</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -58,39 +43,6 @@
<string>#02000000</string> <string>#02000000</string>
</dict> </dict>
</dict> </dict>
<dict>
<key>name</key>
<string>Punctuation</string>
<key>scope</key>
<string>punctuation.definition.string, punctuation.definition.variable, punctuation.definition.string, punctuation.definition.parameters, punctuation.definition.string, punctuation.definition.array</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#07000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Delimiters</string>
<key>scope</key>
<string>none</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#07000000</string>
</dict>
</dict>
<dict>
<key>name</key>
<string>Operators</string>
<key>scope</key>
<string>keyword.operator</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#07000000</string>
</dict>
</dict>
<dict> <dict>
<key>name</key> <key>name</key>
<string>Keywords</string> <string>Keywords</string>
@ -102,17 +54,6 @@
<string>#05000000</string> <string>#05000000</string>
</dict> </dict>
</dict> </dict>
<dict>
<key>name</key>
<string>Variables</string>
<key>scope</key>
<string>variable</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#07000000</string>
</dict>
</dict>
<dict> <dict>
<key>name</key> <key>name</key>
<string>Functions</string> <string>Functions</string>
@ -146,17 +87,6 @@
<string>#03000000</string> <string>#03000000</string>
</dict> </dict>
</dict> </dict>
<dict>
<key>name</key>
<string>Classes</string>
<key>scope</key>
<string>meta.class</string>
<key>settings</key>
<dict>
<key>foreground</key>
<string>#07000000</string>
</dict>
</dict>
<dict> <dict>
<key>name</key> <key>name</key>
<string>Methods</string> <string>Methods</string>
@ -480,8 +410,6 @@
<dict> <dict>
<key>background</key> <key>background</key>
<string>#01000000</string> <string>#01000000</string>
<key>foreground</key>
<string>#07000000</string>
</dict> </dict>
</dict> </dict>
<dict> <dict>
@ -493,8 +421,6 @@
<dict> <dict>
<key>background</key> <key>background</key>
<string>#03000000</string> <string>#03000000</string>
<key>foreground</key>
<string>#00000000</string>
</dict> </dict>
</dict> </dict>
</array> </array>

@ -1 +1 @@
Subproject commit e3db74d0e5de7bc09cab76377723ccf6bcc64e8c Subproject commit 64c47250e54298b91e2cf8d401320009aba9f991

10
diagnostics/info.sh vendored
View File

@ -58,7 +58,8 @@ _bat_:run() {
_out "$BAT" --version _out "$BAT" --version
_out env | grep '^BAT_\|^PAGER=' _out env | grep '^BAT_\|^PAGER='
local cache_dir="$($BAT --cache-dir)" local cache_dir
cache_dir="$($BAT --cache-dir)"
if [[ -f "${cache_dir}/syntaxes.bin" ]]; then if [[ -f "${cache_dir}/syntaxes.bin" ]]; then
_print_command "$BAT" "--list-languages" _print_command "$BAT" "--list-languages"
echo "Found custom syntax set." echo "Found custom syntax set."
@ -79,8 +80,8 @@ _bat_config_:run() {
_bat_wrapper_:run() { _bat_wrapper_:run() {
_bat_wrapper_:detect_wrapper() { _bat_wrapper_:detect_wrapper() {
local bat="$1" local bat="$1"
if file "$(which "${bat}")" | grep "text executable" &> /dev/null; then if file "$(command -v "${bat}")" | grep "text executable" &> /dev/null; then
_out_fence cat "$(which "${bat}")" _out_fence cat "$(command -v "${bat}")"
return return
fi fi
@ -104,7 +105,8 @@ _bat_wrapper_function_:run() {
fi ;; fi ;;
*bash* | *zsh*) *bash* | *zsh*)
local type="$("$SHELL" --login -i -c "type ${command}" 2>&1)" local type
type="$("$SHELL" --login -i -c "type ${command}" 2>&1)"
if grep 'function' <<< "$type" &> /dev/null; then if grep 'function' <<< "$type" &> /dev/null; then
_out_fence "$SHELL" --login -i -c "declare -f ${command}" _out_fence "$SHELL" --login -i -c "declare -f ${command}"
return return

View File

@ -11,6 +11,7 @@ use syntect::parsing::{SyntaxReference, SyntaxSet, SyntaxSetBuilder};
use path_abs::PathAbs; use path_abs::PathAbs;
use crate::assets_metadata::AssetsMetadata; use crate::assets_metadata::AssetsMetadata;
use crate::bat_warning;
use crate::error::*; use crate::error::*;
use crate::input::{InputReader, OpenedInput, OpenedInputKind}; use crate::input::{InputReader, OpenedInput, OpenedInputKind};
use crate::syntax_mapping::{MappingTarget, SyntaxMapping}; use crate::syntax_mapping::{MappingTarget, SyntaxMapping};
@ -189,13 +190,12 @@ impl HighlightingAssets {
match self.theme_set.themes.get(theme) { match self.theme_set.themes.get(theme) {
Some(theme) => theme, Some(theme) => theme,
None => { None => {
if theme == "ansi-light" || theme == "ansi-dark" {
bat_warning!("Theme '{}' is deprecated, using 'ansi' instead.", theme);
return self.get_theme("ansi");
}
if theme != "" { if theme != "" {
use ansi_term::Colour::Yellow; bat_warning!("Unknown theme '{}', using default.", theme)
eprintln!(
"{}: Unknown theme '{}', using default.",
Yellow.paint("[bat warning]"),
theme
);
} }
&self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())] &self.theme_set.themes[self.fallback_theme.unwrap_or_else(|| Self::default_theme())]
} }

View File

@ -16,6 +16,7 @@ use console::Term;
use crate::input::{new_file_input, new_stdin_input}; use crate::input::{new_file_input, new_stdin_input};
use bat::{ use bat::{
assets::HighlightingAssets, assets::HighlightingAssets,
bat_warning,
config::{Config, VisibleLines}, config::{Config, VisibleLines},
error::*, error::*,
input::Input, input::Input,
@ -82,10 +83,9 @@ impl App {
Some("always") => PagingMode::Always, Some("always") => PagingMode::Always,
Some("never") => PagingMode::Never, Some("never") => PagingMode::Never,
Some("auto") | None => { Some("auto") | None => {
if self.matches.occurrences_of("plain") > 1 { // If we have -pp as an option when in auto mode, the pager should be disabled.
// If we have -pp as an option when in auto mode, the pager should be disabled. let extra_plain = self.matches.occurrences_of("plain") > 1;
PagingMode::Never if extra_plain || self.matches.is_present("no-paging") {
} else if self.matches.is_present("no-paging") {
PagingMode::Never PagingMode::Never
} else if inputs.iter().any(Input::is_stdin) { } else if inputs.iter().any(Input::is_stdin) {
// If we are reading from stdin, only enable paging if we write to an // If we are reading from stdin, only enable paging if we write to an
@ -323,11 +323,7 @@ impl App {
// If `grid` is set, remove `rule` as it is a subset of `grid`, and print a warning. // If `grid` is set, remove `rule` as it is a subset of `grid`, and print a warning.
if styled_components.grid() && styled_components.0.remove(&StyleComponent::Rule) { if styled_components.grid() && styled_components.0.remove(&StyleComponent::Rule) {
use ansi_term::Colour::Yellow; bat_warning!("Style 'rule' is a subset of style 'grid', 'rule' will not be visible.");
eprintln!(
"{}: Style 'rule' is a subset of style 'grid', 'rule' will not be visible.",
Yellow.paint("[bat warning]"),
);
} }
Ok(styled_components) Ok(styled_components)

View File

@ -36,6 +36,7 @@ use bat::{
input::Input, input::Input,
style::{StyleComponent, StyleComponents}, style::{StyleComponent, StyleComponents},
MappingTarget, MappingTarget,
PagingMode,
}; };
const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs"); const THEME_PREVIEW_DATA: &[u8] = include_bytes!("../../../assets/theme_preview.rs");
@ -78,7 +79,9 @@ fn get_syntax_mapping_to_paths<'a>(
map map
} }
pub fn list_languages(config: &Config) -> Result<()> { pub fn get_languages(config: &Config) -> Result<String> {
let mut result: String = String::new();
let assets = assets_from_cache_or_binary()?; let assets = assets_from_cache_or_binary()?;
let mut languages = assets let mut languages = assets
.syntaxes() .syntaxes()
@ -119,12 +122,9 @@ pub fn list_languages(config: &Config) -> Result<()> {
} }
} }
let stdout = io::stdout();
let mut stdout = stdout.lock();
if config.loop_through { if config.loop_through {
for lang in languages { for lang in languages {
writeln!(stdout, "{}:{}", lang.name, lang.file_extensions.join(","))?; result += &format!("{}:{}\n", lang.name, lang.file_extensions.join(","));
} }
} else { } else {
let longest = languages let longest = languages
@ -145,7 +145,7 @@ pub fn list_languages(config: &Config) -> Result<()> {
}; };
for lang in languages { for lang in languages {
write!(stdout, "{:width$}{}", lang.name, separator, width = longest)?; result += &format!("{:width$}{}", lang.name, separator, width = longest);
// Number of characters on this line so far, wrap before `desired_width` // Number of characters on this line so far, wrap before `desired_width`
let mut num_chars = 0; let mut num_chars = 0;
@ -156,20 +156,20 @@ pub fn list_languages(config: &Config) -> Result<()> {
let new_chars = word.len() + comma_separator.len(); let new_chars = word.len() + comma_separator.len();
if num_chars + new_chars >= desired_width { if num_chars + new_chars >= desired_width {
num_chars = 0; num_chars = 0;
write!(stdout, "\n{:width$}{}", "", separator, width = longest)?; result += &format!("\n{:width$}{}", "", separator, width = longest);
} }
num_chars += new_chars; num_chars += new_chars;
write!(stdout, "{}", style.paint(&word[..]))?; result += &format!("{}", style.paint(&word[..]));
if extension.peek().is_some() { if extension.peek().is_some() {
write!(stdout, "{}", comma_separator)?; result += comma_separator;
} }
} }
writeln!(stdout)?; result += "\n";
} }
} }
Ok(()) Ok(result)
} }
fn theme_preview_file<'a>() -> Input<'a> { fn theme_preview_file<'a>() -> Input<'a> {
@ -200,19 +200,19 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
.ok(); .ok();
writeln!(stdout)?; writeln!(stdout)?;
} }
writeln!(
stdout,
"Further themes can be installed to '{}', \
and are added to the cache with `bat cache --build`. \
For more information, see:\n\n \
https://github.com/sharkdp/bat#adding-new-themes",
config_file().join("themes").to_string_lossy()
)?;
} else { } else {
for theme in assets.themes() { for theme in assets.themes() {
writeln!(stdout, "{}", theme)?; writeln!(stdout, "{}", theme)?;
} }
} }
writeln!(
stdout,
"Further themes can be installed to '{}', \
and are added to the cache with `bat cache --build`. \
For more information, see:\n\n \
https://github.com/sharkdp/bat#adding-new-themes",
config_file().join("themes").to_string_lossy()
)?;
Ok(()) Ok(())
} }
@ -248,8 +248,14 @@ fn run() -> Result<bool> {
let config = app.config(&inputs)?; let config = app.config(&inputs)?;
if app.matches.is_present("list-languages") { if app.matches.is_present("list-languages") {
list_languages(&config)?; let languages: String = get_languages(&config)?;
Ok(true) 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)
} else if app.matches.is_present("list-themes") { } else if app.matches.is_present("list-themes") {
list_themes(&config)?; list_themes(&config)?;
Ok(true) Ok(true)

View File

@ -197,6 +197,8 @@ impl<'b> Controller<'b> {
let mut first_range: bool = true; let mut first_range: bool = true;
let mut mid_range: bool = false; let mut mid_range: bool = false;
let style_snip = self.config.style_components.snip();
while reader.read_line(&mut line_buffer)? { while reader.read_line(&mut line_buffer)? {
match line_ranges.check(line_number) { match line_ranges.check(line_number) {
RangeCheckResult::BeforeOrBetweenRanges => { RangeCheckResult::BeforeOrBetweenRanges => {
@ -207,7 +209,7 @@ impl<'b> Controller<'b> {
} }
RangeCheckResult::InRange => { RangeCheckResult::InRange => {
if self.config.style_components.snip() { if style_snip {
if first_range { if first_range {
first_range = false; first_range = false;
mid_range = true; mid_range = true;

View File

@ -19,6 +19,8 @@
//! .unwrap(); //! .unwrap();
//! ``` //! ```
mod macros;
pub mod assets; pub mod assets;
pub mod assets_metadata; pub mod assets_metadata;
pub mod config; pub mod config;

7
src/macros.rs Normal file
View File

@ -0,0 +1,7 @@
#[macro_export]
macro_rules! bat_warning {
($($arg:tt)*) => ({
use ansi_term::Colour::Yellow;
eprintln!("{}: {}", Yellow.paint("[bat warning]"), format!($($arg)*));
})
}

View File

@ -72,7 +72,7 @@ pub fn replace_nonprintable(input: &[u8], tab_width: usize) -> String {
} }
} }
// line feed // line feed
'\x0A' => output.push('␊'), '\x0A' => output.push_str("\x0A"),
// carriage return // carriage return
'\x0D' => output.push('␍'), '\x0D' => output.push('␍'),
// null // null

View File

@ -91,9 +91,6 @@ impl<'a> Printer for SimplePrinter<'a> {
if self.config.show_nonprintable { if self.config.show_nonprintable {
let line = replace_nonprintable(line_buffer, self.config.tab_width); let line = replace_nonprintable(line_buffer, self.config.tab_width);
write!(handle, "{}", line)?; write!(handle, "{}", line)?;
if line_buffer.last() == Some(&b'\n') {
writeln!(handle)?;
}
} else { } else {
handle.write_all(line_buffer)? handle.write_all(line_buffer)?
}; };
@ -451,7 +448,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
if text.len() != text_trimmed.len() { if text.len() != text_trimmed.len() {
if let Some(background_color) = background_color { if let Some(background_color) = background_color {
let mut ansi_style = Style::default(); let mut ansi_style = Style::default();
ansi_style.background = Some(to_ansi_color(background_color, true_color)); ansi_style.background = to_ansi_color(background_color, true_color);
let width = if cursor_total <= cursor_max { let width = if cursor_total <= cursor_max {
cursor_max - cursor_total + 1 cursor_max - cursor_total + 1
} else { } else {
@ -463,7 +460,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
} }
} }
if line.bytes().next_back() != Some(b'\n') { if !self.config.style_components.plain() && line.bytes().next_back() != Some(b'\n') {
writeln!(handle)?; writeln!(handle)?;
} }
} else { } else {
@ -592,8 +589,7 @@ impl<'a> Printer for InteractivePrinter<'a> {
if let Some(background_color) = background_color { if let Some(background_color) = background_color {
let mut ansi_style = Style::default(); let mut ansi_style = Style::default();
ansi_style.background = ansi_style.background = to_ansi_color(background_color, self.config.true_color);
Some(to_ansi_color(background_color, self.config.true_color));
write!( write!(
handle, handle,
@ -627,20 +623,27 @@ impl Colors {
} }
fn colored(theme: &Theme, true_color: bool) -> Self { fn colored(theme: &Theme, true_color: bool) -> Self {
let gutter_color = theme let gutter_style = Style {
.settings foreground: match theme.settings.gutter_foreground {
.gutter_foreground // If the theme provides a gutter foreground color, use it.
.map(|c| to_ansi_color(c, true_color)) // Note: It might be the special value #00000001, in which case
.unwrap_or(Fixed(DEFAULT_GUTTER_COLOR)); // to_ansi_color returns None and we use an empty Style
// (resulting in the terminal's default foreground color).
Some(c) => to_ansi_color(c, true_color),
// Otherwise, use a specific fallback color.
None => Some(Fixed(DEFAULT_GUTTER_COLOR)),
},
..Style::default()
};
Colors { Colors {
grid: gutter_color.normal(), grid: gutter_style,
rule: gutter_color.normal(), rule: gutter_style,
filename: Style::new().bold(), filename: Style::new().bold(),
git_added: Green.normal(), git_added: Green.normal(),
git_removed: Red.normal(), git_removed: Red.normal(),
git_modified: Yellow.normal(), git_modified: Yellow.normal(),
line_number: gutter_color.normal(), line_number: gutter_style,
} }
} }
} }

View File

@ -3,13 +3,13 @@ use ansi_term::{self, Style};
use syntect::highlighting::{self, FontStyle}; use syntect::highlighting::{self, FontStyle};
pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Color { pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> Option<ansi_term::Color> {
if color.a == 0 { if color.a == 0 {
// Themes can specify one of the user-configurable terminal colors by // Themes can specify one of the user-configurable terminal colors by
// encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set // encoding them as #RRGGBBAA with AA set to 00 (transparent) and RR set
// to the 8-bit color palette number. The built-in themes ansi-light, // to the 8-bit color palette number. The built-in themes ansi, base16,
// ansi-dark, base16, and base16-256 use this. // and base16-256 use this.
match color.r { Some(match color.r {
// For the first 8 colors, use the Color enum to produce ANSI escape // For the first 8 colors, use the Color enum to produce ANSI escape
// sequences using codes 30-37 (foreground) and 40-47 (background). // sequences using codes 30-37 (foreground) and 40-47 (background).
// For example, red foreground is \x1b[31m. This works on terminals // For example, red foreground is \x1b[31m. This works on terminals
@ -31,11 +31,18 @@ pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term:
// 90-97 (foreground) and 100-107 (background), we should use those // 90-97 (foreground) and 100-107 (background), we should use those
// for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff. // for values 0x08 to 0x0f and only use Fixed for 0x10 to 0xff.
n => Fixed(n), n => Fixed(n),
} })
} else if color.a == 1 {
// Themes can specify the terminal's default foreground/background color
// (i.e. no escape sequence) using the encoding #RRGGBBAA with AA set to
// 01. The built-in theme ansi uses this.
None
} else if true_color { } else if true_color {
RGB(color.r, color.g, color.b) Some(RGB(color.r, color.g, color.b))
} else { } else {
Fixed(ansi_colours::ansi256_from_rgb((color.r, color.g, color.b))) Some(Fixed(ansi_colours::ansi256_from_rgb((
color.r, color.g, color.b,
))))
} }
} }
@ -54,7 +61,10 @@ pub fn as_terminal_escaped(
let mut style = if !colored { let mut style = if !colored {
Style::default() Style::default()
} else { } else {
let mut color = Style::from(to_ansi_color(style.foreground, true_color)); let mut color = Style {
foreground: to_ansi_color(style.foreground, true_color),
..Style::default()
};
if style.font_style.contains(FontStyle::BOLD) { if style.font_style.contains(FontStyle::BOLD) {
color = color.bold(); color = color.bold();
} }
@ -67,6 +77,6 @@ pub fn as_terminal_escaped(
color color
}; };
style.background = background_color.map(|c| to_ansi_color(c, true_color)); style.background = background_color.and_then(|c| to_ansi_color(c, true_color));
style.paint(text).to_string() style.paint(text).to_string()
} }

View File

@ -30,13 +30,11 @@ fn all_themes_are_present() {
"Solarized (light)", "Solarized (light)",
"Sublime Snazzy", "Sublime Snazzy",
"TwoDark", "TwoDark",
"ansi-dark", "ansi",
"ansi-light",
"base16", "base16",
"base16-256", "base16-256",
"gruvbox", "gruvbox-dark",
"gruvbox-light", "gruvbox-light",
"gruvbox-white",
"zenburn" "zenburn"
] ]
); );

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")" cd "$(dirname "${BASH_SOURCE[0]}")" || exit
if ! which hyperfine > /dev/null 2>&1; then if ! command -v hyperfine > /dev/null 2>&1; then
echo "'hyperfine' does not seem to be installed." echo "'hyperfine' does not seem to be installed."
echo "You can get it here: https://github.com/sharkdp/hyperfine" echo "You can get it here: https://github.com/sharkdp/hyperfine"
exit 1 exit 1

View File

@ -1,8 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")" cd "$(dirname "${BASH_SOURCE[0]}")" || exit
if ! which hyperfine > /dev/null 2>&1; then if ! command -v hyperfine > /dev/null 2>&1; then
echo "'hyperfine' does not seem to be installed." echo "'hyperfine' does not seem to be installed."
echo "You can get it here: https://github.com/sharkdp/hyperfine" echo "You can get it here: https://github.com/sharkdp/hyperfine"
exit 1 exit 1

View File

@ -837,3 +837,41 @@ fn show_all_mode() {
.stdout("hello·world␊\n├──┤␍␀␇␈␛") .stdout("hello·world␊\n├──┤␍␀␇␈␛")
.stderr(""); .stderr("");
} }
#[test]
fn plain_mode_does_not_add_nonexisting_newline() {
bat()
.arg("--paging=never")
.arg("--color=never")
.arg("--decorations=always")
.arg("--style=plain")
.arg("single-line.txt")
.assert()
.success()
.stdout("Single Line");
}
// Regression test for https://github.com/sharkdp/bat/issues/299
#[test]
fn grid_for_file_without_newline() {
bat()
.arg("--paging=never")
.arg("--color=never")
.arg("--terminal-width=80")
.arg("--wrap=never")
.arg("--decorations=always")
.arg("--style=full")
.arg("single-line.txt")
.assert()
.success()
.stdout(
"\
File: single-line.txt
1 Single Line
",
)
.stderr("");
}

View File

@ -175,4 +175,4 @@
\u{ad}␊ \u{ad}␊
\u{ae}␊ \u{ae}␊
␊ ␊
Here's·a·line·with·multiple·characters. Here's·a·line·with·multiple·characters.␊

View File

@ -0,0 +1,92 @@
if &compatible
 set nocompatible
endif
if has('win32') || has ('win64')
 let $VIMHOME = $HOME . "/vimfiles"
elseif v:false && v:true
 echo "Can't get here"
else
 let $VIMHOME = $HOME . "/.vim"
endif
" show existing tab with 2 spaces width
set tabstop=2
" when indenting with '>', use 2 spaces width
set shiftwidth=2
" always set autoindenting on
set autoindent
autocmd VimEnter * echo "Hello Vim"
" Allow :W and :Wq to save too
command! Wq :wq
command! W :w
augroup vimrc
 autocmd!
 autocmd FileType * echo "New filetype"
augroup END
function! s:echo(what)
 return a:what
endfunction
function! HelloWorld(name)
 let l:function_local = "function_local_var"
 let l:parts = split(l:function_local, "_")
 let l:greeting = "Hello " . a:name
 return s:echo(l:greeting)
endfunction
function! source#Hello()
 return "Hello from namespace"
endfunction
function! EchoFunc(...)
 for s in a:000
 echon ' ' . s
 endfor
endfunction
imap <C-h> <C-r>=HelloWorld("World")<CR>
command! -nargs=? Echo :call EchoFunc(<args>)
" TODO test stuff
let g:global = "global var"
let s:script_var = "script var"
let w:window_var = "window war"
let b:buffer_var = "buffer war"
let t:tab_var = "tab war"
echo v:false
3 + 5
echo "Hello" ==# "Hello2"
echo "Hello" ==? "Hello2"
echo "Hello" == "Hello2"
echo "Hello" is "Hello2"
echo "Hello" isnot "Hello2"
echo "Hello" =~ 'xx*'
echo "Hello" !~ "Hello2"
echo "Hello" !~ "Hello2"
echo "/This/should/not/be/a/regex"
" Error case from issue #1604 (https://github.com/sharkdp/bat/issues/1064)
set runtimepath=~/foo/bar
silent g/Aap/p
let g:dict = {}
let g:dict.item = ['l1', 'l2']
let g:dict2 = {'dict_item': ['l1', 'l2'], 'di2': 'x'}
silent g/regex/
silent v/regex/
silent %s/regex/not_regex/
filetype plugin indent on
syntax enable

View File

@ -4,7 +4,7 @@ set -eou pipefail
script_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" script_directory="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
output_directory=$(mktemp -d --suffix=.bat-syntax-regression-test) output_directory=$(mktemp -d)
"$script_directory"/create_highlighted_versions.py --output="$output_directory" "$script_directory"/create_highlighted_versions.py --output="$output_directory"

View File

@ -0,0 +1,92 @@
if &compatible
set nocompatible
endif
if has('win32') || has ('win64')
let $VIMHOME = $HOME . "/vimfiles"
elseif v:false && v:true
echo "Can't get here"
else
let $VIMHOME = $HOME . "/.vim"
endif
" show existing tab with 2 spaces width
set tabstop=2
" when indenting with '>', use 2 spaces width
set shiftwidth=2
" always set autoindenting on
set autoindent
autocmd VimEnter * echo "Hello Vim"
" Allow :W and :Wq to save too
command! Wq :wq
command! W :w
augroup vimrc
autocmd!
autocmd FileType * echo "New filetype"
augroup END
function! s:echo(what)
return a:what
endfunction
function! HelloWorld(name)
let l:function_local = "function_local_var"
let l:parts = split(l:function_local, "_")
let l:greeting = "Hello " . a:name
return s:echo(l:greeting)
endfunction
function! source#Hello()
return "Hello from namespace"
endfunction
function! EchoFunc(...)
for s in a:000
echon ' ' . s
endfor
endfunction
imap <C-h> <C-r>=HelloWorld("World")<CR>
command! -nargs=? Echo :call EchoFunc(<args>)
" TODO test stuff
let g:global = "global var"
let s:script_var = "script var"
let w:window_var = "window war"
let b:buffer_var = "buffer war"
let t:tab_var = "tab war"
echo v:false
3 + 5
echo "Hello" ==# "Hello2"
echo "Hello" ==? "Hello2"
echo "Hello" == "Hello2"
echo "Hello" is "Hello2"
echo "Hello" isnot "Hello2"
echo "Hello" =~ 'xx*'
echo "Hello" !~ "Hello2"
echo "Hello" !~ "Hello2"
echo "/This/should/not/be/a/regex"
" Error case from issue #1604 (https://github.com/sharkdp/bat/issues/1064)
set runtimepath=~/foo/bar
silent g/Aap/p
let g:dict = {}
let g:dict.item = ['l1', 'l2']
let g:dict2 = {'dict_item': ['l1', 'l2'], 'di2': 'x'}
silent g/regex/
silent v/regex/
silent %s/regex/not_regex/
filetype plugin indent on
syntax enable

View File

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
cd "$(dirname "${BASH_SOURCE[0]}")" cd "$(dirname "${BASH_SOURCE[0]}")" || exit
python="python3" python="python3"
if ! command -v python3 &>/dev/null; then python="python"; fi if ! command -v python3 &>/dev/null; then python="python"; fi