mirror of
https://github.com/sharkdp/bat
synced 2026-08-04 19:01:44 +00:00
Compare commits
97 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ba4d5a2e7d | |||
| 026273a05c | |||
| 8903b64830 | |||
| 194155f062 | |||
| a6ff3b900d | |||
| 8a52bcf92d | |||
| 0b1535f63b | |||
| 0a5b3eaf3e | |||
| 11294249f8 | |||
| 35a1236ad0 | |||
| af8da50c2c | |||
| 649d1e3df2 | |||
| 199cfd4519 | |||
| c7cce0752b | |||
| 3a89486189 | |||
| 720a2fb7a5 | |||
| e3c990f11e | |||
| 90c7d0c365 | |||
| 56002267d2 | |||
| 84734eac9d | |||
| acdea97e71 | |||
| 839e4ee611 | |||
| c7afcdebf8 | |||
| 08e6db1581 | |||
| 4d08ecd828 | |||
| 28e1d0e613 | |||
| d11839ad03 | |||
| 8cacd9b432 | |||
| 6f67444c99 | |||
| fd2b376ea0 | |||
| cda54e4f61 | |||
| 3b90ada735 | |||
| 1837d364fe | |||
| 4ea3e6bbb7 | |||
| 38544ed735 | |||
| 5444b0dfed | |||
| f3dde0185d | |||
| 2e3784aa30 | |||
| 1088455702 | |||
| 4f812c32ab | |||
| b6c59a5bd4 | |||
| b682679776 | |||
| 81771432fb | |||
| 627181bcb6 | |||
| 226d9a573a | |||
| 246cf79dbd | |||
| ea955c734d | |||
| 6223ad6d52 | |||
| 31a9335bd5 | |||
| 9316f2a758 | |||
| c884c3cc12 | |||
| 08850f0474 | |||
| 8e6c5bc562 | |||
| 052425b12f | |||
| 2df3305b94 | |||
| 6882fc1512 | |||
| 2508323264 | |||
| 297afad337 | |||
| 1dddce3aa1 | |||
| 76be0d3933 | |||
| e5b8c4471a | |||
| b191691767 | |||
| 5c95b8803b | |||
| 5b421b455d | |||
| a6d6c28723 | |||
| 2966939e38 | |||
| d179693d1d | |||
| 268577c6f9 | |||
| 037861e588 | |||
| 94ccc646e8 | |||
| 0cc5d1dab6 | |||
| 28397b8f78 | |||
| c899849101 | |||
| bf53b64125 | |||
| c68aa0f424 | |||
| 6b57f4eebc | |||
| 0ddd388a29 | |||
| 34811b8161 | |||
| 8b92aae23f | |||
| 3a0941cabe | |||
| 52877c6d67 | |||
| 455de98a89 | |||
| 8c6a74a6c5 | |||
| 3f8b340ed8 | |||
| 65e6970907 | |||
| 90cc019482 | |||
| eaf0b99d25 | |||
| 3b1dcca5d0 | |||
| 26dbdf4fa0 | |||
| 6691786d82 | |||
| 50209bfe21 | |||
| c91511cca1 | |||
| c9f7a0c126 | |||
| 69c798eafd | |||
| 195d5e0e16 | |||
| 86c1777205 | |||
| 16874ab016 |
+22
-1
@@ -24,7 +24,7 @@
|
|||||||
url = https://github.com/clintberry/sublime-text-2-ini
|
url = https://github.com/clintberry/sublime-text-2-ini
|
||||||
[submodule "assets/syntaxes/CMake"]
|
[submodule "assets/syntaxes/CMake"]
|
||||||
path = assets/syntaxes/CMake
|
path = assets/syntaxes/CMake
|
||||||
url = https://github.com/sharkdp/Sublime-CMakeLists
|
url = https://github.com/zyxar/Sublime-CMakeLists
|
||||||
[submodule "assets/syntaxes/LESS"]
|
[submodule "assets/syntaxes/LESS"]
|
||||||
path = assets/syntaxes/LESS
|
path = assets/syntaxes/LESS
|
||||||
url = https://github.com/danro/LESS-sublime
|
url = https://github.com/danro/LESS-sublime
|
||||||
@@ -40,3 +40,24 @@
|
|||||||
[submodule "assets/themes/TwoDark"]
|
[submodule "assets/themes/TwoDark"]
|
||||||
path = assets/themes/TwoDark
|
path = assets/themes/TwoDark
|
||||||
url = https://github.com/erremauro/TwoDark
|
url = https://github.com/erremauro/TwoDark
|
||||||
|
[submodule "assets/syntaxes/AWK"]
|
||||||
|
path = assets/syntaxes/AWK
|
||||||
|
url = https://github.com/JohnNilsson/awk-sublime
|
||||||
|
[submodule "assets/syntaxes/Nix"]
|
||||||
|
path = assets/syntaxes/Nix
|
||||||
|
url = https://github.com/wmertens/sublime-nix
|
||||||
|
[submodule "assets/themes/zenburn"]
|
||||||
|
path = assets/themes/zenburn
|
||||||
|
url = https://github.com/colinta/zenburn.git
|
||||||
|
[submodule "assets/syntaxes/Kotlin"]
|
||||||
|
path = assets/syntaxes/Kotlin
|
||||||
|
url = https://github.com/vkostyukov/kotlin-sublime-package
|
||||||
|
[submodule "assets/syntaxes/Elm"]
|
||||||
|
path = assets/syntaxes/Elm
|
||||||
|
url = https://github.com/elm-community/SublimeElmLanguageSupport
|
||||||
|
[submodule "assets/syntaxes/TypeScript"]
|
||||||
|
path = assets/syntaxes/TypeScript
|
||||||
|
url = https://github.com/Microsoft/TypeScript-Sublime-Plugin
|
||||||
|
[submodule "assets/syntaxes/Puppet"]
|
||||||
|
path = assets/syntaxes/Puppet
|
||||||
|
url = https://github.com/russCloak/SublimePuppet
|
||||||
|
|||||||
+14
-17
@@ -17,18 +17,24 @@ matrix:
|
|||||||
- os: osx
|
- os: osx
|
||||||
rust: stable
|
rust: stable
|
||||||
env: TARGET=x86_64-apple-darwin
|
env: TARGET=x86_64-apple-darwin
|
||||||
|
- os: linux
|
||||||
|
rust: stable
|
||||||
|
env:
|
||||||
|
- TARGET=arm-unknown-linux-gnueabihf
|
||||||
|
- CC_arm_unknown_linux_gnueabihf=/usr/bin/arm-linux-gnueabihf-gcc-4.8
|
||||||
|
- CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc-4.8
|
||||||
|
|
||||||
# Minimum Rust supported channel.
|
# Minimum Rust supported channel.
|
||||||
- os: linux
|
- os: linux
|
||||||
rust: 1.24.0
|
rust: 1.26.0
|
||||||
env: TARGET=x86_64-unknown-linux-gnu
|
env: TARGET=x86_64-unknown-linux-gnu
|
||||||
- os: linux
|
- os: linux
|
||||||
rust: 1.24.0
|
rust: 1.26.0
|
||||||
env:
|
env:
|
||||||
- TARGET=x86_64-unknown-linux-musl
|
- TARGET=x86_64-unknown-linux-musl
|
||||||
- CC_x86_64_unknown_linux_musl=/usr/bin/musl-gcc
|
- CC_x86_64_unknown_linux_musl=/usr/bin/musl-gcc
|
||||||
- os: osx
|
- os: osx
|
||||||
rust: 1.24.0
|
rust: 1.26.0
|
||||||
env: TARGET=x86_64-apple-darwin
|
env: TARGET=x86_64-apple-darwin
|
||||||
|
|
||||||
# Code formatting check
|
# Code formatting check
|
||||||
@@ -39,15 +45,10 @@ matrix:
|
|||||||
- cargo install --debug --force rustfmt-nightly
|
- cargo install --debug --force rustfmt-nightly
|
||||||
script: cargo fmt -- --check
|
script: cargo fmt -- --check
|
||||||
|
|
||||||
addons:
|
sudo: required
|
||||||
apt:
|
|
||||||
packages:
|
before_install:
|
||||||
# needed for i686-unknown-linux-gnu target
|
- ci/before_install.bash
|
||||||
- gcc-multilib
|
|
||||||
# needed for musl targets
|
|
||||||
- musl-tools
|
|
||||||
# needed to build deb packages
|
|
||||||
- fakeroot
|
|
||||||
|
|
||||||
env:
|
env:
|
||||||
global:
|
global:
|
||||||
@@ -62,11 +63,7 @@ install:
|
|||||||
- if [[ $TRAVIS_OS_NAME = linux && $HOST != $TARGET ]]; then rustup target add $TARGET; fi
|
- if [[ $TRAVIS_OS_NAME = linux && $HOST != $TARGET ]]; then rustup target add $TARGET; fi
|
||||||
|
|
||||||
script:
|
script:
|
||||||
# Incorporate TARGET env var to the build and test process
|
- ci/script.bash
|
||||||
- cargo build --target $TARGET --verbose
|
|
||||||
- cargo test --target $TARGET --verbose
|
|
||||||
# Run 'bat' on its own source code and the README
|
|
||||||
- cargo run --target $TARGET -- src/main.rs README.md --paging=never
|
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- bash ci/before_deploy.bash
|
- bash ci/before_deploy.bash
|
||||||
|
|||||||
Generated
+273
-301
File diff suppressed because it is too large
Load Diff
+12
-5
@@ -7,13 +7,17 @@ license = "MIT/Apache-2.0"
|
|||||||
name = "bat"
|
name = "bat"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/sharkdp/bat"
|
repository = "https://github.com/sharkdp/bat"
|
||||||
version = "0.4.0"
|
version = "0.6.1"
|
||||||
|
exclude = [
|
||||||
|
"assets/syntaxes/*",
|
||||||
|
"assets/themes/*",
|
||||||
|
]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atty = "0.2.2"
|
atty = "0.2.2"
|
||||||
ansi_term = "0.10"
|
ansi_term = "0.11"
|
||||||
console = "0.6"
|
console = "0.6"
|
||||||
directories = "0.10"
|
directories = "1.0"
|
||||||
lazy_static = "1.0"
|
lazy_static = "1.0"
|
||||||
|
|
||||||
[dependencies.git2]
|
[dependencies.git2]
|
||||||
@@ -27,11 +31,14 @@ default-features = false
|
|||||||
features = ["parsing", "yaml-load", "dump-load", "dump-create"]
|
features = ["parsing", "yaml-load", "dump-load", "dump-create"]
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "2"
|
version = "2.32"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = ["suggestions", "color", "wrap_help"]
|
features = ["suggestions", "color", "wrap_help"]
|
||||||
|
|
||||||
[dependencies.error-chain]
|
[dependencies.error-chain]
|
||||||
version = "0.11"
|
version = "0.12"
|
||||||
default-features = false
|
default-features = false
|
||||||
features = []
|
features = []
|
||||||
|
|
||||||
|
[dev-dependencies]
|
||||||
|
tempdir = "0.3"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="doc/logo-header.svg" alt="bat - a cat clone with wings"><br>
|
<img src="doc/logo-header.svg" alt="bat - a cat clone with wings"><br>
|
||||||
<a href="Version info"><img src="https://travis-ci.org/sharkdp/bat.svg?branch=master" alt="Build Status"></a>
|
<a href="https://travis-ci.org/sharkdp/bat"><img src="https://travis-ci.org/sharkdp/bat.svg?branch=master" alt="Build Status"></a>
|
||||||
|
<a href="https://ci.appveyor.com/project/sharkdp/bat"><img src="https://ci.appveyor.com/api/projects/status/cptsmtbiwbnr2vhf?svg=true"></a>
|
||||||
<img src="https://img.shields.io/crates/l/bat.svg" alt="license">
|
<img src="https://img.shields.io/crates/l/bat.svg" alt="license">
|
||||||
<a href="https://crates.io/crates/bat"><img src="https://img.shields.io/crates/v/bat.svg?colorB=319e8c" alt="Version info"></a><br>
|
<a href="https://crates.io/crates/bat"><img src="https://img.shields.io/crates/v/bat.svg?colorB=319e8c" alt="Version info"></a><br>
|
||||||
A <i>cat(1)</i> clone with syntax highlighting and Git integration.
|
A <i>cat(1)</i> clone with syntax highlighting and Git integration.
|
||||||
@@ -71,28 +72,37 @@ bat header.md content.md footer.md > document.md
|
|||||||
|
|
||||||
bat -n main.rs # show line numbers (only)
|
bat -n main.rs # show line numbers (only)
|
||||||
|
|
||||||
cat f - g # output 'f', then stdin, then 'g'.
|
bat f - g # output 'f', then stdin, then 'g'.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### From binaries
|
### On Ubuntu
|
||||||
|
*... and other Debian-based Linux distributions.*
|
||||||
|
|
||||||
Check out the [Release page](https://github.com/sharkdp/bat/releases) for
|
Download the latest `.deb` package from the [release page](https://github.com/sharkdp/bat/releases)
|
||||||
binary builds and Debian packages.
|
and install it via:
|
||||||
|
``` bash
|
||||||
#### On Arch Linux
|
sudo dpkg -i bat_0.6.1_amd64.deb # adapt version number and architecture
|
||||||
|
|
||||||
You can install [the AUR package](https://aur.archlinux.org/packages/bat/)
|
|
||||||
via yaourt, or manually:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://aur.archlinux.org/bat.git
|
|
||||||
cd bat
|
|
||||||
makepkg -si
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### On FreeBSD
|
### On Arch Linux
|
||||||
|
|
||||||
|
You can install [the `bat` package](https://www.archlinux.org/packages/community/x86_64/bat/)
|
||||||
|
from the official sources:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
pacman -S bat
|
||||||
|
```
|
||||||
|
|
||||||
|
### On Void Linux
|
||||||
|
|
||||||
|
You can install `bat` via xbps-install:
|
||||||
|
```
|
||||||
|
xbps-install -S bat
|
||||||
|
```
|
||||||
|
|
||||||
|
### 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:
|
||||||
|
|
||||||
@@ -107,7 +117,7 @@ cd /usr/ports/textproc/bat
|
|||||||
make install
|
make install
|
||||||
```
|
```
|
||||||
|
|
||||||
#### On macOS
|
### On macOS
|
||||||
|
|
||||||
You can install `bat` with [Homebrew](http://braumeister.org/formula/bat):
|
You can install `bat` with [Homebrew](http://braumeister.org/formula/bat):
|
||||||
|
|
||||||
@@ -115,9 +125,14 @@ You can install `bat` with [Homebrew](http://braumeister.org/formula/bat):
|
|||||||
brew install bat
|
brew install bat
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### From binaries
|
||||||
|
|
||||||
|
Check out the [Release page](https://github.com/sharkdp/bat/releases) for
|
||||||
|
prebuilt versions of `bat` for many different architectures.
|
||||||
|
|
||||||
### From source
|
### From source
|
||||||
|
|
||||||
If you want to build to compile `bat` from source, you need Rust 1.24 or
|
If you want to build `bat` from source, you need Rust 1.26 or
|
||||||
higher. You can then use `cargo` to build everything:
|
higher. You can then use `cargo` to build everything:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@@ -132,9 +147,10 @@ some dependencies to be built.
|
|||||||
### Highlighting theme
|
### Highlighting theme
|
||||||
|
|
||||||
Use `bat --list-themes` to get a list of all available themes for syntax
|
Use `bat --list-themes` to get a list of all available themes for syntax
|
||||||
highlighting. To select the `TwoDark` theme, for example, call `bat` with
|
highlighting. To select the `TwoDark` theme, call `bat` with the
|
||||||
the `--theme=TwoDark` option. Use `alias bat="bat --theme=TwoDark"` in your
|
`--theme=TwoDark` option or set the `BAT_THEME` environment variable to
|
||||||
shells startup file to make the change permanent.
|
`TwoDark`. Use `export BAT_THEME="TwoDark"` in your shells startup file to
|
||||||
|
make the change permanent.
|
||||||
|
|
||||||
### Output style
|
### Output style
|
||||||
|
|
||||||
@@ -142,55 +158,107 @@ You can use the `--style` option to control the appearance of `bat`s output.
|
|||||||
You can use `--style=numbers,changes`, for example, to show only Git changes
|
You can use `--style=numbers,changes`, for example, to show only Git changes
|
||||||
and line numbers but no grid and no file header.
|
and line numbers but no grid and no file header.
|
||||||
|
|
||||||
### Add new syntaxes and highlighting themes
|
### Adding new syntaxes / language definitions
|
||||||
|
|
||||||
`bat` uses the excellent [`syntect`](https://github.com/trishume/syntect/)
|
`bat` uses the excellent [`syntect`](https://github.com/trishume/syntect/)
|
||||||
library for syntax highlighting. `syntect` can read any
|
library for syntax highlighting. `syntect` can read any
|
||||||
[Sublime Text `.sublime-syntax` file](https://www.sublimetext.com/docs/3/syntax.html)
|
[Sublime Text `.sublime-syntax` file](https://www.sublimetext.com/docs/3/syntax.html)
|
||||||
and theme.
|
and theme. To add new syntax definitions, do the following.
|
||||||
|
|
||||||
To build your own language-set and theme, follow these steps:
|
Create a folder with syntax definition files:
|
||||||
|
|
||||||
Create a folder with a syntax highlighting theme:
|
```bash
|
||||||
|
BAT_CONFIG_DIR="$(bat cache --config-dir)"
|
||||||
|
|
||||||
|
mkdir -p "$BAT_CONFIG_DIR/syntaxes"
|
||||||
|
cd "$BAT_CONFIG_DIR/syntaxes"
|
||||||
|
|
||||||
|
# Put new '.sublime-syntax' language definition files
|
||||||
|
# in this folder (or its subdirectories), for example:
|
||||||
|
git clone https://github.com/tellnobody1/sublime-purescript-syntax
|
||||||
|
```
|
||||||
|
|
||||||
|
Now use the following command to parse these files into a binary cache:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bat cache --init
|
||||||
|
```
|
||||||
|
|
||||||
|
Finally, use `bat --list-languages` to check if the new languages are available.
|
||||||
|
|
||||||
|
If you ever want to go back to the default settings, call:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
bat cache --clear
|
||||||
|
```
|
||||||
|
|
||||||
|
### Adding new themes
|
||||||
|
|
||||||
|
This works very similar to how we add new syntax definitions.
|
||||||
|
|
||||||
|
First, create a folder with the new syntax highlighting themes:
|
||||||
```bash
|
```bash
|
||||||
BAT_CONFIG_DIR="$(bat cache --config-dir)"
|
BAT_CONFIG_DIR="$(bat cache --config-dir)"
|
||||||
|
|
||||||
mkdir -p "$BAT_CONFIG_DIR/themes"
|
mkdir -p "$BAT_CONFIG_DIR/themes"
|
||||||
cd "$BAT_CONFIG_DIR/themes"
|
cd "$BAT_CONFIG_DIR/themes"
|
||||||
|
|
||||||
# Download a theme, for example:
|
# Download a theme in '.tmTheme' format, for example:
|
||||||
git clone https://github.com/greggb/sublime-snazzy
|
git clone https://github.com/greggb/sublime-snazzy
|
||||||
|
|
||||||
# Create a link for the default theme
|
# Update the binary cache
|
||||||
ln -sf "sublime-snazzy/Sublime Snazzy.tmTheme" Default.tmTheme
|
|
||||||
```
|
|
||||||
|
|
||||||
Create a folder with language definition files:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
mkdir -p "$BAT_CONFIG_DIR/syntaxes"
|
|
||||||
cd "$BAT_CONFIG_DIR/syntaxes"
|
|
||||||
|
|
||||||
# Download some language definition files, for example:
|
|
||||||
git clone https://github.com/sublimehq/Packages
|
|
||||||
git clone https://github.com/danro/LESS-sublime
|
|
||||||
```
|
|
||||||
|
|
||||||
Finally, use the following command to parse all these files into a binary
|
|
||||||
cache:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
bat cache --init
|
bat cache --init
|
||||||
```
|
```
|
||||||
|
|
||||||
Use `bat --list-languages` and `bat --list-themes` to check if all languages and themes are
|
Finally, use `bat --list-themes` to check if the new themes are available.
|
||||||
available.
|
|
||||||
|
|
||||||
If you ever want to go back to the default settings, call:
|
### Using a different pager
|
||||||
|
|
||||||
|
`bat` uses the pager that is specified in the `PAGER` environment variable. If this variable is not
|
||||||
|
set, `less` is used by default. If you want to use a different pager, you can either modify the
|
||||||
|
`PAGER` variable or set the `BAT_PAGER` environment variable to override what is specified in
|
||||||
|
`PAGER`. If you want to pass command-line arguments to the pager, you need to create a small shell
|
||||||
|
script as a wrapper, for example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
bat cache --clear
|
#!/bin/bash
|
||||||
|
|
||||||
|
less --tabs 4 -RF "$@"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Terminals & colors
|
||||||
|
|
||||||
|
`bat` handles terminals *with* and *without* truecolor support. However, the colors in the syntax
|
||||||
|
highlighting themes are not optimized for 8-bit colors and it is therefore strongly recommended
|
||||||
|
that you use a terminal with 24-bit truecolor support (`terminator`, `konsole`, `iTerm2`, ...).
|
||||||
|
See [this article](https://gist.github.com/XVilka/8346728) for more details and a full list of
|
||||||
|
terminals with truecolor support.
|
||||||
|
|
||||||
|
Make sure that your truecolor terminal sets the `COLORTERM` variable to either `truecolor` or
|
||||||
|
`24bit`. Otherwise, `bat` will not be able to determine whether or not 24-bit escape sequences
|
||||||
|
are supported (and fall back to 8-bit colors).
|
||||||
|
|
||||||
|
## Development
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Recursive clone to retrieve all submodules
|
||||||
|
git clone --recursive https://github.com/sharkdp/bat
|
||||||
|
|
||||||
|
# Build (debug version)
|
||||||
|
cd bat
|
||||||
|
cargo build
|
||||||
|
|
||||||
|
# Run unit tests and integration tests
|
||||||
|
cargo test
|
||||||
|
|
||||||
|
# Install (release version)
|
||||||
|
cargo install
|
||||||
|
|
||||||
|
# Build a bat binary with modified syntaxes and themes
|
||||||
|
bash assets/create.sh
|
||||||
|
cargo install -f
|
||||||
```
|
```
|
||||||
|
|
||||||
## Project goals and alternatives
|
## Project goals and alternatives
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
environment:
|
||||||
|
global:
|
||||||
|
TARGET: x86_64-pc-windows-msvc
|
||||||
|
RUST_VERSION: stable
|
||||||
|
CRATE_NAME: bat
|
||||||
|
CARGO_HOME: "c:\\cargo"
|
||||||
|
RUSTUP_HOME: "c:\\rustup"
|
||||||
|
|
||||||
|
install:
|
||||||
|
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
||||||
|
- rustup-init.exe -y --default-host %TARGET%
|
||||||
|
- set PATH=%PATH%;C:\cargo\bin
|
||||||
|
- rustc -Vv
|
||||||
|
- cargo -V
|
||||||
|
|
||||||
|
build: false
|
||||||
|
test_script:
|
||||||
|
- cargo test --target %TARGET% --verbose
|
||||||
|
- cargo run --target %TARGET% -- src/main.rs README.md --paging=never
|
||||||
|
|
||||||
|
before_deploy:
|
||||||
|
# Generate artifacts for release
|
||||||
|
- cargo build --release --verbose
|
||||||
|
- ps: ci\before_deploy.ps1
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
description: 'Automatically deployed release'
|
||||||
|
artifact: /.*\.zip/
|
||||||
|
# Here's how:
|
||||||
|
# - Go to 'https://github.com/settings/tokens/new' and generate a Token with only the
|
||||||
|
# `public_repo` scope enabled
|
||||||
|
# - Then go to 'https://ci.appveyor.com/tools/encrypt' and enter the newly generated token.
|
||||||
|
# - Enter the "encrypted value" below
|
||||||
|
auth_token:
|
||||||
|
secure: oO4/J+hcFXgXcEqEc8gzlQNqLG0IxU78s4EyH+uczGdsyWajb3yipxPR6nXUvmoj
|
||||||
|
provider: GitHub
|
||||||
|
on:
|
||||||
|
RUST_VERSION: stable
|
||||||
|
appveyor_repo_tag: true
|
||||||
|
|
||||||
|
cache:
|
||||||
|
- C:\Users\appveyor\.cargo\registry
|
||||||
|
- target
|
||||||
|
|
||||||
|
notifications:
|
||||||
|
- provider: Email
|
||||||
|
on_build_success: false
|
||||||
|
on_build_failure: false
|
||||||
|
on_build_status_changed: false
|
||||||
+1
-1
@@ -2,4 +2,4 @@
|
|||||||
|
|
||||||
ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
ASSET_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
|
|
||||||
bat cache --init --source="$ASSET_DIR" --target="$ASSET_DIR"
|
bat cache --init --blank --source="$ASSET_DIR" --target="$ASSET_DIR"
|
||||||
|
|||||||
Binary file not shown.
Submodule
+1
Submodule assets/syntaxes/AWK added at 1ce5f90d44
+1
-1
Submodule assets/syntaxes/CMake updated: a71f52a390...aba96a0862
Submodule
+1
Submodule assets/syntaxes/Elm added at dfbb8bdc9a
Submodule
+1
Submodule assets/syntaxes/Kotlin added at aeeed2780b
@@ -0,0 +1,398 @@
|
|||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
# http://www.sublimetext.com/docs/3/syntax.html
|
||||||
|
name: Kotlin
|
||||||
|
file_extensions:
|
||||||
|
- kt
|
||||||
|
- kts
|
||||||
|
scope: source.Kotlin
|
||||||
|
contexts:
|
||||||
|
main:
|
||||||
|
- include: comments
|
||||||
|
- match: '^\s*(package)\b(?:\s*([^ ;$]+)\s*)?'
|
||||||
|
captures:
|
||||||
|
1: keyword.other.kotlin
|
||||||
|
2: entity.name.package.kotlin
|
||||||
|
- include: imports
|
||||||
|
- include: statements
|
||||||
|
classes:
|
||||||
|
- match: (?<!::)(?=\b(?:companion|class|object|interface)\b)
|
||||||
|
push:
|
||||||
|
- match: '(?=$|\})'
|
||||||
|
pop: true
|
||||||
|
- include: comments
|
||||||
|
- match: \b(companion\s*)?(class|object|interface)\b
|
||||||
|
captures:
|
||||||
|
1: storage.modifier.kotlin
|
||||||
|
2: storage.modifier.kotlin
|
||||||
|
push:
|
||||||
|
- match: '(?=<|\{|\(|:|$)'
|
||||||
|
pop: true
|
||||||
|
- include: comments
|
||||||
|
- match: \w+
|
||||||
|
scope: entity.name.type.class.kotlin
|
||||||
|
- match: <
|
||||||
|
push:
|
||||||
|
- match: ">"
|
||||||
|
pop: true
|
||||||
|
- include: generics
|
||||||
|
- match: \(
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
pop: true
|
||||||
|
- include: parameters
|
||||||
|
- match: (:)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.declaration.kotlin
|
||||||
|
push:
|
||||||
|
- match: "(?={|$)"
|
||||||
|
pop: true
|
||||||
|
- match: \w+
|
||||||
|
scope: entity.other.inherited-class.kotlin
|
||||||
|
- match: \(
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
pop: true
|
||||||
|
- include: statements
|
||||||
|
comments:
|
||||||
|
- match: /\*
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.comment.kotlin
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.block.kotlin
|
||||||
|
- match: \*/
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.comment.kotlin
|
||||||
|
pop: true
|
||||||
|
- match: \s*((//).*$\n?)
|
||||||
|
captures:
|
||||||
|
1: comment.line.double-slash.kotlin
|
||||||
|
2: punctuation.definition.comment.kotlin
|
||||||
|
constants:
|
||||||
|
- match: \b(true|false|null|this|super)\b
|
||||||
|
scope: constant.language.kotlin
|
||||||
|
- match: '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)([LlFf])?\b'
|
||||||
|
scope: constant.numeric.kotlin
|
||||||
|
- match: '\b([A-Z][A-Z0-9_]+)\b'
|
||||||
|
scope: constant.other.kotlin
|
||||||
|
expressions:
|
||||||
|
- match: \(
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- include: types
|
||||||
|
- include: strings
|
||||||
|
- include: constants
|
||||||
|
- include: comments
|
||||||
|
- include: keywords
|
||||||
|
functions:
|
||||||
|
- match: (?=\s*\b(?:fun)\b)
|
||||||
|
push:
|
||||||
|
- match: '(?=$|\})'
|
||||||
|
pop: true
|
||||||
|
- match: \b(fun)\b
|
||||||
|
captures:
|
||||||
|
1: keyword.other.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=\()
|
||||||
|
pop: true
|
||||||
|
- match: <
|
||||||
|
push:
|
||||||
|
- match: ">"
|
||||||
|
pop: true
|
||||||
|
- include: generics
|
||||||
|
- match: '([\.<\?>\w]+\.)?(\w+)'
|
||||||
|
captures:
|
||||||
|
2: entity.name.function.kotlin
|
||||||
|
- match: \(
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
pop: true
|
||||||
|
- include: parameters
|
||||||
|
- match: (:)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.declaration.kotlin
|
||||||
|
push:
|
||||||
|
- match: "(?={|=|$)"
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '(?=\})'
|
||||||
|
pop: true
|
||||||
|
- include: statements
|
||||||
|
- match: (=)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.assignment.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=$)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
generics:
|
||||||
|
- match: (:)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.declaration.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=,|>)
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- include: keywords
|
||||||
|
- match: \w+
|
||||||
|
scope: storage.type.generic.kotlin
|
||||||
|
getters-and-setters:
|
||||||
|
- match: \b(get)\b\s*\(\s*\)
|
||||||
|
captures:
|
||||||
|
1: entity.name.function.kotlin
|
||||||
|
push:
|
||||||
|
- match: '\}|(?=\bset\b)|$'
|
||||||
|
pop: true
|
||||||
|
- match: (=)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.assignment.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=$|\bset\b)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- match: \b(set)\b\s*(?=\()
|
||||||
|
captures:
|
||||||
|
1: entity.name.function.kotlin
|
||||||
|
push:
|
||||||
|
- match: '\}|(?=\bget\b)|$'
|
||||||
|
pop: true
|
||||||
|
- match: \(
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
pop: true
|
||||||
|
- include: parameters
|
||||||
|
- match: (=)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.assignment.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=$|\bset\b)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
imports:
|
||||||
|
- match: '^\s*(import)\s+[^ $]+\s+(as)?'
|
||||||
|
captures:
|
||||||
|
1: keyword.other.kotlin
|
||||||
|
2: keyword.other.kotlin
|
||||||
|
keywords:
|
||||||
|
- match: \b(var|val|public|private|protected|abstract|final|sealed|enum|open|attribute|annotation|override|inline|vararg|in|out|internal|data|tailrec|operator|infix|const|yield|typealias|typeof|reified|suspend)\b
|
||||||
|
scope: storage.modifier.kotlin
|
||||||
|
- match: \b(try|catch|finally|throw)\b
|
||||||
|
scope: keyword.control.catch-exception.kotlin
|
||||||
|
- match: \b(if|else|while|for|do|return|when|where|break|continue)\b
|
||||||
|
scope: keyword.control.kotlin
|
||||||
|
- match: \b(in|is|!in|!is|as|as\?|assert)\b
|
||||||
|
scope: keyword.operator.kotlin
|
||||||
|
- match: (==|!=|===|!==|<=|>=|<|>)
|
||||||
|
scope: keyword.operator.comparison.kotlin
|
||||||
|
- match: (=)
|
||||||
|
scope: keyword.operator.assignment.kotlin
|
||||||
|
- match: (::)
|
||||||
|
scope: keyword.operator.kotlin
|
||||||
|
- match: (:)
|
||||||
|
scope: keyword.operator.declaration.kotlin
|
||||||
|
- match: \b(by)\b
|
||||||
|
scope: keyword.other.by.kotlin
|
||||||
|
- match: (\?\.)
|
||||||
|
scope: keyword.operator.safenav.kotlin
|
||||||
|
- match: (\.)
|
||||||
|
scope: keyword.operator.dot.kotlin
|
||||||
|
- match: (\?:)
|
||||||
|
scope: keyword.operator.elvis.kotlin
|
||||||
|
- match: (\-\-|\+\+)
|
||||||
|
scope: keyword.operator.increment-decrement.kotlin
|
||||||
|
- match: (\+=|\-=|\*=|\/=)
|
||||||
|
scope: keyword.operator.arithmetic.assign.kotlin
|
||||||
|
- match: (\.\.)
|
||||||
|
scope: keyword.operator.range.kotlin
|
||||||
|
- match: (\-|\+|\*|\/|%)
|
||||||
|
scope: keyword.operator.arithmetic.kotlin
|
||||||
|
- match: (!|&&|\|\|)
|
||||||
|
scope: keyword.operator.logical.kotlin
|
||||||
|
- match: (;)
|
||||||
|
scope: punctuation.terminator.kotlin
|
||||||
|
namespaces:
|
||||||
|
- match: \b(namespace)\b
|
||||||
|
scope: keyword.other.kotlin
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
pop: true
|
||||||
|
- include: statements
|
||||||
|
parameters:
|
||||||
|
- match: (:)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.declaration.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=,|\)|=)
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- match: (=)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.declaration.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=,|\))
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- include: keywords
|
||||||
|
- match: \w+
|
||||||
|
scope: variable.parameter.function.kotlin
|
||||||
|
statements:
|
||||||
|
- include: namespaces
|
||||||
|
- include: typedefs
|
||||||
|
- include: classes
|
||||||
|
- include: functions
|
||||||
|
- include: variables
|
||||||
|
- include: getters-and-setters
|
||||||
|
- include: expressions
|
||||||
|
strings:
|
||||||
|
- match: '"""'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.begin.kotlin
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.third.kotlin
|
||||||
|
- match: '"""'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.end.kotlin
|
||||||
|
pop: true
|
||||||
|
- match: '(\$\w+|\$\{[^\}]+\})'
|
||||||
|
scope: variable.parameter.template.kotlin
|
||||||
|
- match: \\.
|
||||||
|
scope: constant.character.escape.kotlin
|
||||||
|
- match: '"'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.begin.kotlin
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.double.kotlin
|
||||||
|
- match: '"'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.end.kotlin
|
||||||
|
pop: true
|
||||||
|
- match: '(\$\w+|\$\{[^\}]+\})'
|
||||||
|
scope: variable.parameter.template.kotlin
|
||||||
|
- match: \\.
|
||||||
|
scope: constant.character.escape.kotlin
|
||||||
|
- match: "'"
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.begin.kotlin
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.single.kotlin
|
||||||
|
- match: "'"
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.end.kotlin
|
||||||
|
pop: true
|
||||||
|
- match: \\.
|
||||||
|
scope: constant.character.escape.kotlin
|
||||||
|
- match: "`"
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.begin.kotlin
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.single.kotlin
|
||||||
|
- match: "`"
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.end.kotlin
|
||||||
|
pop: true
|
||||||
|
typedefs:
|
||||||
|
- match: (?=\s*(?:type))
|
||||||
|
push:
|
||||||
|
- match: (?=$)
|
||||||
|
pop: true
|
||||||
|
- match: \b(type)\b
|
||||||
|
scope: keyword.other.kotlin
|
||||||
|
- match: <
|
||||||
|
push:
|
||||||
|
- match: ">"
|
||||||
|
pop: true
|
||||||
|
- include: generics
|
||||||
|
- include: expressions
|
||||||
|
types:
|
||||||
|
- match: \b(Nothing|Any|Unit|String|CharSequence|Int|Boolean|Char|Long|Double|Float|Short|Byte|dynamic)\b
|
||||||
|
scope: storage.type.buildin.kotlin
|
||||||
|
- match: \b(IntArray|BooleanArray|CharArray|LongArray|DoubleArray|FloatArray|ShortArray|ByteArray)\b
|
||||||
|
scope: storage.type.buildin.array.kotlin
|
||||||
|
- match: \b(Array|Collection|List|Map|Set|MutableList|MutableMap|MutableSet|Sequence)<\b
|
||||||
|
captures:
|
||||||
|
1: storage.type.buildin.collection.kotlin
|
||||||
|
push:
|
||||||
|
- match: ">"
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- include: keywords
|
||||||
|
- match: \w+<
|
||||||
|
push:
|
||||||
|
- match: ">"
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- include: keywords
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
pop: true
|
||||||
|
- include: statements
|
||||||
|
- match: \(
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- match: (->)
|
||||||
|
scope: keyword.operator.declaration.kotlin
|
||||||
|
variables:
|
||||||
|
- match: (?=\s*\b(?:var|val)\b)
|
||||||
|
push:
|
||||||
|
- match: (?=:|=|(\b(by)\b)|$)
|
||||||
|
pop: true
|
||||||
|
- match: \b(var|val)\b
|
||||||
|
captures:
|
||||||
|
1: keyword.other.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=:|=|(\b(by)\b)|$)
|
||||||
|
pop: true
|
||||||
|
- match: <
|
||||||
|
push:
|
||||||
|
- match: ">"
|
||||||
|
pop: true
|
||||||
|
- include: generics
|
||||||
|
- match: '([\.<\?>\w]+\.)?(\w+)'
|
||||||
|
captures:
|
||||||
|
2: entity.name.variable.kotlin
|
||||||
|
- match: (:)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.declaration.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?==|$)
|
||||||
|
pop: true
|
||||||
|
- include: types
|
||||||
|
- include: getters-and-setters
|
||||||
|
- match: \b(by)\b
|
||||||
|
captures:
|
||||||
|
1: keyword.other.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=$)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- match: (=)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.assignment.kotlin
|
||||||
|
push:
|
||||||
|
- match: (?=$)
|
||||||
|
pop: true
|
||||||
|
- include: expressions
|
||||||
|
- include: getters-and-setters
|
||||||
+1
-1
Submodule assets/syntaxes/LESS updated: 46694c86b9...d3ddfe7b51
Submodule
+1
Submodule assets/syntaxes/Nix added at ebf06571f3
@@ -0,0 +1,609 @@
|
|||||||
|
%YAML 1.2
|
||||||
|
---
|
||||||
|
# http://www.sublimetext.com/docs/3/syntax.html
|
||||||
|
name: Nix
|
||||||
|
file_extensions:
|
||||||
|
- nix
|
||||||
|
scope: source.nix
|
||||||
|
contexts:
|
||||||
|
main:
|
||||||
|
- include: expression
|
||||||
|
comment:
|
||||||
|
- match: '/\*([^*]|\*[^\/])*'
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.block.nix
|
||||||
|
- match: \*\/
|
||||||
|
pop: true
|
||||||
|
- include: comment-remark
|
||||||
|
- match: '\#'
|
||||||
|
push:
|
||||||
|
- meta_scope: comment.line.number-sign.nix
|
||||||
|
- match: $
|
||||||
|
pop: true
|
||||||
|
- include: comment-remark
|
||||||
|
attribute-bind:
|
||||||
|
- include: attribute-name
|
||||||
|
- include: attribute-bind-from-equals
|
||||||
|
attribute-bind-from-equals:
|
||||||
|
- match: \=
|
||||||
|
captures:
|
||||||
|
0: keyword.operator.bind.nix
|
||||||
|
push:
|
||||||
|
- match: \;
|
||||||
|
captures:
|
||||||
|
0: punctuation.terminator.bind.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
attribute-inherit:
|
||||||
|
- match: \binherit\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.inherit.nix
|
||||||
|
push:
|
||||||
|
- match: \;
|
||||||
|
captures:
|
||||||
|
0: punctuation.terminator.inherit.nix
|
||||||
|
pop: true
|
||||||
|
- match: \(
|
||||||
|
captures:
|
||||||
|
0: punctuation.section.function.arguments.nix
|
||||||
|
push:
|
||||||
|
- match: (?=\;)
|
||||||
|
pop: true
|
||||||
|
- match: \)
|
||||||
|
captures:
|
||||||
|
0: punctuation.section.function.arguments.nix
|
||||||
|
push:
|
||||||
|
- match: (?=\;)
|
||||||
|
pop: true
|
||||||
|
- include: bad-reserved
|
||||||
|
- include: attribute-name-single
|
||||||
|
- include: others
|
||||||
|
- include: expression
|
||||||
|
- match: '(?=[a-zA-Z\_])'
|
||||||
|
push:
|
||||||
|
- match: (?=\;)
|
||||||
|
pop: true
|
||||||
|
- include: bad-reserved
|
||||||
|
- include: attribute-name-single
|
||||||
|
- include: others
|
||||||
|
- include: others
|
||||||
|
attribute-name:
|
||||||
|
- match: '\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*'
|
||||||
|
scope: entity.other.attribute-name.multipart.nix
|
||||||
|
- match: \.
|
||||||
|
- include: string-quoted
|
||||||
|
- include: interpolation
|
||||||
|
attribute-name-single:
|
||||||
|
- match: '\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*'
|
||||||
|
scope: entity.other.attribute-name.single.nix
|
||||||
|
attrset-contents:
|
||||||
|
- include: attribute-inherit
|
||||||
|
- include: bad-reserved
|
||||||
|
- include: attribute-bind
|
||||||
|
- include: others
|
||||||
|
attrset-definition:
|
||||||
|
- match: '(?=\{)'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: '(\{)'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.attrset.nix
|
||||||
|
push:
|
||||||
|
- match: '(\})'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.attrset.nix
|
||||||
|
pop: true
|
||||||
|
- include: attrset-contents
|
||||||
|
- match: '(?<=\})'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
attrset-definition-brace-opened:
|
||||||
|
- match: '(?<=\})'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.attrset.nix
|
||||||
|
pop: true
|
||||||
|
- include: attrset-contents
|
||||||
|
attrset-for-sure:
|
||||||
|
- match: (?=\brec\b)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: \brec\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=\{)'
|
||||||
|
pop: true
|
||||||
|
- include: others
|
||||||
|
- include: attrset-definition
|
||||||
|
- include: others
|
||||||
|
- match: '(?=\{\s*(\}|[^,?]*(=|;)))'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: attrset-definition
|
||||||
|
- include: others
|
||||||
|
attrset-or-function:
|
||||||
|
- match: '\{'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.attrset-or-function.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: '(?=(\s*\}|\"|\binherit\b|\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*(\s*\.|\s*=[^=])))'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: attrset-definition-brace-opened
|
||||||
|
- match: '(?=(\.\.\.|\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*\s*[,?]))'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-definition-brace-opened
|
||||||
|
- include: bad-reserved
|
||||||
|
- match: '\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*'
|
||||||
|
captures:
|
||||||
|
0: variable.parameter.function.maybe.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: (?=\.)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: attrset-definition-brace-opened
|
||||||
|
- match: \s*(\,)
|
||||||
|
captures:
|
||||||
|
1: keyword.operator.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-definition-brace-opened
|
||||||
|
- match: (?=\=)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: attribute-bind-from-equals
|
||||||
|
- include: attrset-definition-brace-opened
|
||||||
|
- match: (?=\?)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-parameter-default
|
||||||
|
- match: \,
|
||||||
|
captures:
|
||||||
|
0: keyword.operator.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-definition-brace-opened
|
||||||
|
- include: others
|
||||||
|
- include: others
|
||||||
|
bad-reserved:
|
||||||
|
- match: '(?<![\w''-])(if|then|else|assert|with|let|in|rec|inherit)(?![\w''-])'
|
||||||
|
scope: invalid.illegal.reserved.nix
|
||||||
|
comment-remark:
|
||||||
|
- match: (TODO|FIXME|BUG|\!\!\!):?
|
||||||
|
captures:
|
||||||
|
1: markup.bold.comment.nix
|
||||||
|
constants:
|
||||||
|
- match: \b(builtins|true|false|null)\b
|
||||||
|
captures:
|
||||||
|
0: constant.language.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
- match: \b(scopedImport|import|isNull|abort|throw|baseNameOf|dirOf|removeAttrs|map|toString|derivationStrict|derivation)\b
|
||||||
|
captures:
|
||||||
|
0: support.function.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
- match: '\b[0-9]+\b'
|
||||||
|
captures:
|
||||||
|
0: constant.numeric.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
expression:
|
||||||
|
- include: parens-and-cont
|
||||||
|
- include: list-and-cont
|
||||||
|
- include: string
|
||||||
|
- include: interpolation
|
||||||
|
- include: with-assert
|
||||||
|
- include: function-for-sure
|
||||||
|
- include: attrset-for-sure
|
||||||
|
- include: attrset-or-function
|
||||||
|
- include: let
|
||||||
|
- include: if
|
||||||
|
- include: operator-unary
|
||||||
|
- include: constants
|
||||||
|
- include: bad-reserved
|
||||||
|
- include: parameter-name-and-cont
|
||||||
|
- include: others
|
||||||
|
expression-cont:
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: parens
|
||||||
|
- include: list
|
||||||
|
- include: string
|
||||||
|
- include: interpolation
|
||||||
|
- include: function-for-sure
|
||||||
|
- include: attrset-for-sure
|
||||||
|
- include: attrset-or-function
|
||||||
|
- match: '(\bor\b|\.|==|!=|!|\<\=|\<|\>\=|\>|&&|\|\||-\>|//|\?|\+\+|-|\*|/(?=([^*]|$))|\+)'
|
||||||
|
scope: keyword.operator.nix
|
||||||
|
- include: constants
|
||||||
|
- include: bad-reserved
|
||||||
|
- include: parameter-name
|
||||||
|
- include: others
|
||||||
|
function-body:
|
||||||
|
- match: '(@\s*([a-zA-Z\_][a-zA-Z0-9\_\''\-]*)\s*)?(\:)'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
function-body-from-colon:
|
||||||
|
- match: (\:)
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.function.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
function-contents:
|
||||||
|
- include: bad-reserved
|
||||||
|
- include: function-parameter
|
||||||
|
- include: others
|
||||||
|
function-definition:
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-body-from-colon
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- match: '(\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*)'
|
||||||
|
captures:
|
||||||
|
0: variable.parameter.function.4.nix
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- match: \@
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: function-header-until-colon-no-arg
|
||||||
|
- include: others
|
||||||
|
- include: others
|
||||||
|
- match: '(?=\{)'
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: function-header-until-colon-with-arg
|
||||||
|
- include: others
|
||||||
|
function-definition-brace-opened:
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-body-from-colon
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: function-header-close-brace-with-arg
|
||||||
|
- match: (?=.?)
|
||||||
|
push:
|
||||||
|
- match: '(?=\})'
|
||||||
|
pop: true
|
||||||
|
- include: function-contents
|
||||||
|
- include: others
|
||||||
|
function-for-sure:
|
||||||
|
- match: '(?=(\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*\s*[:@]|\{[^}]*\}\s*:|\{[^#}"''/=]*[,\?]))'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: function-definition
|
||||||
|
function-header-close-brace-no-arg:
|
||||||
|
- match: '\}'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.entity.function.nix
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: others
|
||||||
|
function-header-close-brace-with-arg:
|
||||||
|
- match: '\}'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.entity.function.nix
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: function-header-terminal-arg
|
||||||
|
- include: others
|
||||||
|
function-header-open-brace:
|
||||||
|
- match: '\{'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.entity.function.2.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=\})'
|
||||||
|
pop: true
|
||||||
|
- include: function-contents
|
||||||
|
function-header-terminal-arg:
|
||||||
|
- match: (?=@)
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- match: \@
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- match: '(\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*)'
|
||||||
|
push:
|
||||||
|
- meta_scope: variable.parameter.function.3.nix
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: others
|
||||||
|
- include: others
|
||||||
|
function-header-until-colon-no-arg:
|
||||||
|
- match: '(?=\{)'
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: function-header-open-brace
|
||||||
|
- include: function-header-close-brace-no-arg
|
||||||
|
function-header-until-colon-with-arg:
|
||||||
|
- match: '(?=\{)'
|
||||||
|
push:
|
||||||
|
- match: (?=\:)
|
||||||
|
pop: true
|
||||||
|
- include: function-header-open-brace
|
||||||
|
- include: function-header-close-brace-with-arg
|
||||||
|
function-parameter:
|
||||||
|
- match: (\.\.\.)
|
||||||
|
push:
|
||||||
|
- meta_scope: keyword.operator.nix
|
||||||
|
- match: '(,|(?=\}))'
|
||||||
|
pop: true
|
||||||
|
- include: others
|
||||||
|
- match: '\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*'
|
||||||
|
captures:
|
||||||
|
0: variable.parameter.function.1.nix
|
||||||
|
push:
|
||||||
|
- match: '(,|(?=\}))'
|
||||||
|
captures:
|
||||||
|
0: keyword.operator.nix
|
||||||
|
pop: true
|
||||||
|
- include: whitespace
|
||||||
|
- include: comment
|
||||||
|
- include: function-parameter-default
|
||||||
|
- include: expression
|
||||||
|
- include: others
|
||||||
|
function-parameter-default:
|
||||||
|
- match: \?
|
||||||
|
captures:
|
||||||
|
0: keyword.operator.nix
|
||||||
|
push:
|
||||||
|
- match: "(?=[,}])"
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
if:
|
||||||
|
- match: (?=\bif\b)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: \bif\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: \bth(?=en\b)
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
- match: (?<=th)en\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: \bel(?=se\b)
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
- match: (?<=el)se\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
illegal:
|
||||||
|
- match: .
|
||||||
|
scope: invalid.illegal
|
||||||
|
interpolation:
|
||||||
|
- match: '\$\{'
|
||||||
|
captures:
|
||||||
|
0: punctuation.section.embedded.begin.nix
|
||||||
|
push:
|
||||||
|
- meta_scope: markup.italic
|
||||||
|
- match: '\}'
|
||||||
|
captures:
|
||||||
|
0: punctuation.section.embedded.end.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
let:
|
||||||
|
- match: (?=\blet\b)
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: \blet\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(in|else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: '(?=\{)'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: '\{'
|
||||||
|
push:
|
||||||
|
- match: '\}'
|
||||||
|
pop: true
|
||||||
|
- include: attrset-contents
|
||||||
|
- match: '(^|(?<=\}))'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
- include: others
|
||||||
|
- include: attrset-contents
|
||||||
|
- include: others
|
||||||
|
- match: \bin\b
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
list:
|
||||||
|
- match: '\['
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.list.nix
|
||||||
|
push:
|
||||||
|
- match: '\]'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.list.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
list-and-cont:
|
||||||
|
- match: '(?=\[)'
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: list
|
||||||
|
- include: expression-cont
|
||||||
|
operator-unary:
|
||||||
|
- match: (!|-)
|
||||||
|
scope: keyword.operator.unary.nix
|
||||||
|
others:
|
||||||
|
- include: whitespace
|
||||||
|
- include: comment
|
||||||
|
- include: illegal
|
||||||
|
parameter-name:
|
||||||
|
- match: '\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*'
|
||||||
|
captures:
|
||||||
|
0: variable.parameter.name.nix
|
||||||
|
parameter-name-and-cont:
|
||||||
|
- match: '\b[a-zA-Z\_][a-zA-Z0-9\_\''\-]*'
|
||||||
|
captures:
|
||||||
|
0: variable.parameter.name.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
parens:
|
||||||
|
- match: \(
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.expression.nix
|
||||||
|
push:
|
||||||
|
- match: \)
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.expression.nix
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
|
parens-and-cont:
|
||||||
|
- match: (?=\()
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: parens
|
||||||
|
- include: expression-cont
|
||||||
|
string:
|
||||||
|
- match: (?=\'\')
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- match: \'\'
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.other.start.nix
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.other.nix
|
||||||
|
- match: \'\'(?!\$|\'|\\.)
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.other.end.nix
|
||||||
|
pop: true
|
||||||
|
- match: \'\'(\$|\'|\\.)
|
||||||
|
scope: constant.character.escape.nix
|
||||||
|
- include: interpolation
|
||||||
|
- include: expression-cont
|
||||||
|
- match: (?=\")
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: string-quoted
|
||||||
|
- include: expression-cont
|
||||||
|
- match: '([a-zA-Z0-9\.\_\-\+]*(\/[a-zA-Z0-9\.\_\-\+]+)+)'
|
||||||
|
captures:
|
||||||
|
0: string.unquoted.path.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
- match: '(\<[a-zA-Z0-9\.\_\-\+]+(\/[a-zA-Z0-9\.\_\-\+]+)*\>)'
|
||||||
|
captures:
|
||||||
|
0: string.unquoted.spath.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
- match: '([a-zA-Z][a-zA-Z0-9\+\-\.]*\:[a-zA-Z0-9\%\/\?\:\@\&\=\+\$\,\-\_\.\!\~\*\'']+)'
|
||||||
|
captures:
|
||||||
|
0: string.unquoted.url.nix
|
||||||
|
push:
|
||||||
|
- match: '(?=([\])};,]|\b(else|then)\b))'
|
||||||
|
pop: true
|
||||||
|
- include: expression-cont
|
||||||
|
string-quoted:
|
||||||
|
- match: \"
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.double.start.nix
|
||||||
|
push:
|
||||||
|
- meta_scope: string.quoted.double.nix
|
||||||
|
- match: \"
|
||||||
|
captures:
|
||||||
|
0: punctuation.definition.string.double.end.nix
|
||||||
|
pop: true
|
||||||
|
- match: \\.
|
||||||
|
scope: constant.character.escape.nix
|
||||||
|
- include: interpolation
|
||||||
|
whitespace:
|
||||||
|
- match: \s+
|
||||||
|
with-assert:
|
||||||
|
- match: '(?<![\w''-])(with|assert)(?![\w''-])'
|
||||||
|
captures:
|
||||||
|
0: keyword.other.nix
|
||||||
|
push:
|
||||||
|
- match: \;
|
||||||
|
pop: true
|
||||||
|
- include: expression
|
||||||
+1
-1
Submodule assets/syntaxes/Packages updated: 1cb4c3ec36...289782ff2e
Submodule
+1
Submodule assets/syntaxes/Puppet added at 2a224343d2
Submodule
+1
Submodule assets/syntaxes/TypeScript added at 19a599ad0e
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,5 @@
|
|||||||
|
// Output the square of a number.
|
||||||
|
fn print_square(num: f64) {
|
||||||
|
let result = f64::powf(num, 2.0);
|
||||||
|
println!("The square of {:.2} is {:.2}.", num, result);
|
||||||
|
}
|
||||||
Binary file not shown.
Submodule assets/themes/1337-Scheme updated: 82db0222c3...ca6a329cfd
@@ -1 +0,0 @@
|
|||||||
sublime-monokai-extended/Monokai Extended.tmTheme
|
|
||||||
Submodule
+1
Submodule assets/themes/zenburn added at b7f27e2f65
+17
-4
@@ -11,19 +11,27 @@ pack() {
|
|||||||
local tempdir
|
local tempdir
|
||||||
local out_dir
|
local out_dir
|
||||||
local package_name
|
local package_name
|
||||||
|
local gcc_prefix
|
||||||
|
|
||||||
tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
|
tempdir=$(mktemp -d 2>/dev/null || mktemp -d -t tmp)
|
||||||
out_dir=$(pwd)
|
out_dir=$(pwd)
|
||||||
package_name="$PROJECT_NAME-$TRAVIS_TAG-$TARGET"
|
package_name="$PROJECT_NAME-$TRAVIS_TAG-$TARGET"
|
||||||
|
|
||||||
|
if [[ $TARGET == "arm-unknown-linux-gnueabihf" ]]; then
|
||||||
|
gcc_prefix="arm-linux-gnueabihf-"
|
||||||
|
else
|
||||||
|
gcc_prefix=""
|
||||||
|
fi
|
||||||
|
|
||||||
# create a "staging" directory
|
# create a "staging" directory
|
||||||
mkdir "$tempdir/$package_name"
|
mkdir "$tempdir/$package_name"
|
||||||
|
|
||||||
# copying the main binary
|
# copying the main binary
|
||||||
cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/"
|
cp "target/$TARGET/release/$PROJECT_NAME" "$tempdir/$package_name/"
|
||||||
strip "$tempdir/$package_name/$PROJECT_NAME"
|
"${gcc_prefix}"strip "$tempdir/$package_name/$PROJECT_NAME"
|
||||||
|
|
||||||
# readme and license
|
# manpage, readme and license
|
||||||
|
cp "doc/$PROJECT_NAME.1" "$tempdir/$package_name"
|
||||||
cp README.md "$tempdir/$package_name"
|
cp README.md "$tempdir/$package_name"
|
||||||
cp LICENSE-MIT "$tempdir/$package_name"
|
cp LICENSE-MIT "$tempdir/$package_name"
|
||||||
cp LICENSE-APACHE "$tempdir/$package_name"
|
cp LICENSE-APACHE "$tempdir/$package_name"
|
||||||
@@ -50,8 +58,8 @@ make_deb() {
|
|||||||
architecture=i386
|
architecture=i386
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "ERROR: unknown target" >&2
|
echo "make_deb: skipping target '${TARGET}'" >&2
|
||||||
return 1
|
return 0
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
version=${TRAVIS_TAG#v}
|
version=${TRAVIS_TAG#v}
|
||||||
@@ -69,6 +77,10 @@ make_deb() {
|
|||||||
install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
|
install -Dm755 "target/$TARGET/release/$PROJECT_NAME" "$tempdir/usr/bin/$PROJECT_NAME"
|
||||||
strip "$tempdir/usr/bin/$PROJECT_NAME"
|
strip "$tempdir/usr/bin/$PROJECT_NAME"
|
||||||
|
|
||||||
|
# manpage
|
||||||
|
install -Dm644 "doc/$PROJECT_NAME.1" "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
|
||||||
|
gzip --best "$tempdir/usr/share/man/man1/$PROJECT_NAME.1"
|
||||||
|
|
||||||
# readme and license
|
# readme and license
|
||||||
install -Dm644 README.md "$tempdir/usr/share/doc/$PROJECT_NAME/README.md"
|
install -Dm644 README.md "$tempdir/usr/share/doc/$PROJECT_NAME/README.md"
|
||||||
install -Dm644 LICENSE-MIT "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-MIT"
|
install -Dm644 LICENSE-MIT "$tempdir/usr/share/doc/$PROJECT_NAME/LICENSE-MIT"
|
||||||
@@ -86,6 +98,7 @@ Architecture: $architecture
|
|||||||
Provides: $PROJECT_NAME
|
Provides: $PROJECT_NAME
|
||||||
Conflicts: $conflictname
|
Conflicts: $conflictname
|
||||||
Description: A cat(1) clone with wings.
|
Description: A cat(1) clone with wings.
|
||||||
|
A cat(1) clone with syntax highlighting and Git integration.
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
fakeroot dpkg-deb --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb"
|
fakeroot dpkg-deb --build "$tempdir" "${dpkgname}_${version}_${architecture}.deb"
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
# This script takes care of packaging the build artifacts that will go in the
|
||||||
|
# release zipfile
|
||||||
|
|
||||||
|
$SRC_DIR = $PWD.Path
|
||||||
|
$STAGE = [System.Guid]::NewGuid().ToString()
|
||||||
|
|
||||||
|
Set-Location $ENV:Temp
|
||||||
|
New-Item -Type Directory -Name $STAGE
|
||||||
|
Set-Location $STAGE
|
||||||
|
|
||||||
|
$ZIP = "$SRC_DIR\$($Env:CRATE_NAME)-$($Env:APPVEYOR_REPO_TAG_NAME)-$($Env:TARGET).zip"
|
||||||
|
|
||||||
|
Copy-Item "$SRC_DIR\target\release\bat.exe" '.\'
|
||||||
|
|
||||||
|
# readme and license
|
||||||
|
Copy-Item $SRC_DIR\README.md '.\'
|
||||||
|
Copy-Item $SRC_DIR\LICENSE-MIT '.\'
|
||||||
|
Copy-Item $SRC_DIR\LICENSE-APACHE '.\'
|
||||||
|
|
||||||
|
7z a "$ZIP" *
|
||||||
|
|
||||||
|
Push-AppveyorArtifact "$ZIP"
|
||||||
|
|
||||||
|
Set-Location ..
|
||||||
|
Remove-Item $STAGE -Force -Recurse
|
||||||
|
Set-Location $SRC_DIR
|
||||||
Executable
+29
@@ -0,0 +1,29 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
if [ "$TRAVIS_OS_NAME" != linux ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
sudo apt-get update
|
||||||
|
|
||||||
|
# needed for musl targets
|
||||||
|
sudo apt-get install -y musl-tools
|
||||||
|
|
||||||
|
# needed to build deb packages
|
||||||
|
sudo apt-get install -y fakeroot
|
||||||
|
|
||||||
|
# needed for i686 linux gnu target
|
||||||
|
if [[ $TARGET == i686-unknown-linux-gnu ]]; then
|
||||||
|
sudo apt-get install -y gcc-multilib
|
||||||
|
fi
|
||||||
|
|
||||||
|
# needed for cross-compiling for arm
|
||||||
|
if [[ $TARGET == arm-unknown-linux-gnueabihf ]]; then
|
||||||
|
sudo apt-get install -y \
|
||||||
|
gcc-4.8-arm-linux-gnueabihf \
|
||||||
|
binutils-arm-linux-gnueabihf \
|
||||||
|
libc6-armhf-cross \
|
||||||
|
libc6-dev-armhf-cross
|
||||||
|
fi
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Incorporate TARGET env var to the build and test process
|
||||||
|
cargo build --target "$TARGET" --verbose
|
||||||
|
|
||||||
|
# We cannot run arm executables on linux
|
||||||
|
if [[ $TARGET != arm-unknown-linux-gnueabihf ]]; then
|
||||||
|
cargo test --target "$TARGET" --verbose
|
||||||
|
|
||||||
|
# Run 'bat' on its own source code and the README
|
||||||
|
cargo run --target "$TARGET" -- src/main.rs README.md --paging=never
|
||||||
|
fi
|
||||||
+1
-1
@@ -6,7 +6,7 @@ if you are not looking for a program like `bat`, this comparison might not be fo
|
|||||||
|
|
||||||
| | bat | [pygments](http://pygments.org/) | [highlight](http://www.andre-simon.de/doku/highlight/highlight.php) | [ccat](https://github.com/jingweno/ccat) | [source-highlight](https://www.gnu.org/software/src-highlite/) | [hicat](https://github.com/rstacruz/hicat) | [coderay](https://github.com/rubychan/coderay) | [rouge](https://github.com/jneen/rouge) |
|
| | bat | [pygments](http://pygments.org/) | [highlight](http://www.andre-simon.de/doku/highlight/highlight.php) | [ccat](https://github.com/jingweno/ccat) | [source-highlight](https://www.gnu.org/software/src-highlite/) | [hicat](https://github.com/rstacruz/hicat) | [coderay](https://github.com/rubychan/coderay) | [rouge](https://github.com/jneen/rouge) |
|
||||||
|----------------------------------------------|---------------------------------------------------------------------|----------------------------------|---------------------------------------------------------------------|------------------------------------------|----------------------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|
|
|----------------------------------------------|---------------------------------------------------------------------|----------------------------------|---------------------------------------------------------------------|------------------------------------------|----------------------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|-----------------------------------------------------|
|
||||||
| Drop-in `cat` replacement | (:heavy_check_mark:) [*](https://github.com/sharkdp/bat/issues/134) | :x: | :x: | (:heavy_check_mark:) | :x: | :x: [*](https://github.com/rstacruz/hicat/issues/6) | :x: | :x: |
|
| Drop-in `cat` replacement | :heavy_check_mark: [*](https://github.com/sharkdp/bat/issues/134) | :x: | :x: | (:heavy_check_mark:) | :x: | :x: [*](https://github.com/rstacruz/hicat/issues/6) | :x: | :x: |
|
||||||
| Git integration | :heavy_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: |
|
| Git integration | :heavy_check_mark: | :x: | :x: | :x: | :x: | :x: | :x: | :x: |
|
||||||
| Automatic paging | :heavy_check_mark: | :x: | :x: | :x: | :x: | :heavy_check_mark: | :x: | :x: |
|
| Automatic paging | :heavy_check_mark: | :x: | :x: | :x: | :x: | :heavy_check_mark: | :x: | :x: |
|
||||||
| Languages (circa) | 60 | 300 | 200 | 7 | 80 | 130 | 30 | 130 |
|
| Languages (circa) | 60 | 300 | 200 | 7 | 80 | 130 | 30 | 130 |
|
||||||
|
|||||||
@@ -0,0 +1,109 @@
|
|||||||
|
.TH BAT "1"
|
||||||
|
.SH NAME
|
||||||
|
bat \- manual page for bat
|
||||||
|
.SH DESCRIPTION
|
||||||
|
bat - a cat(1) clone with syntax highlighting and Git integration.
|
||||||
|
.SH "USAGE"
|
||||||
|
.IP
|
||||||
|
bat [OPTIONS] [FILE]...
|
||||||
|
.IP
|
||||||
|
bat <SUBCOMMAND>
|
||||||
|
.SH "OPTIONS"
|
||||||
|
.HP
|
||||||
|
\fB\-l\fR, \fB\-\-language\fR <language>
|
||||||
|
.IP
|
||||||
|
Explicitly set the language for syntax highlighting. The language can be
|
||||||
|
specified as a name (like 'C++' or 'LaTeX') or possible file extension (like
|
||||||
|
\&'cpp', 'hpp' or 'md'). Use '\-\-list\-languages' to show all supported language
|
||||||
|
names and file extensions.
|
||||||
|
.HP
|
||||||
|
\fB\-\-list\-languages\fR
|
||||||
|
.IP
|
||||||
|
Display a list of supported languages for syntax highlighting.
|
||||||
|
.HP
|
||||||
|
\fB\-\-theme\fR <theme>
|
||||||
|
.IP
|
||||||
|
Set the theme for syntax highlighting. Use '\-\-list\-themes' to see all
|
||||||
|
available themes. To set a default theme, export the BAT_THEME environment
|
||||||
|
variable (e.g.: export BAT_THEME="TwoDark").
|
||||||
|
.HP
|
||||||
|
\fB\-\-list\-themes\fR
|
||||||
|
.IP
|
||||||
|
Display a list of supported themes for syntax highlighting.
|
||||||
|
.HP
|
||||||
|
\fB\-\-style\fR <style\-components>
|
||||||
|
.IP
|
||||||
|
Configure which elements (line numbers, file headers, grid borders, Git
|
||||||
|
modifications, ..) to display in addition to the file contents. The argument
|
||||||
|
is a comma\-separated list of components to display (e.g.
|
||||||
|
\&'numbers,changes,grid') or a pre\-defined style ('full') [default: auto]
|
||||||
|
[possible values: auto, full, plain, changes, header, grid, numbers]
|
||||||
|
.HP
|
||||||
|
\fB\-p\fR
|
||||||
|
.IP
|
||||||
|
Only show plain style, no decorations. This is an alias for '\-\-style=plain'
|
||||||
|
.HP
|
||||||
|
\fB\-n\fR, \fB\-\-number\fR
|
||||||
|
.IP
|
||||||
|
Only show line numbers, no other decorations. This is an alias for
|
||||||
|
\&'\-\-style=numbers'
|
||||||
|
.HP
|
||||||
|
\fB\-\-line\-range\fR <N:M>
|
||||||
|
.IP
|
||||||
|
Only print the specified range of lines for each file. For example:
|
||||||
|
.RS
|
||||||
|
.IP "\-\-line\-range 30:40"
|
||||||
|
prints lines 30 to 40
|
||||||
|
.IP "\-\-line\-range :40"
|
||||||
|
prints lines 1 to 40
|
||||||
|
.IP "\-\-line\-range 40:"
|
||||||
|
prints lines 40 to the end of the file
|
||||||
|
.RE
|
||||||
|
.HP
|
||||||
|
\fB\-\-color\fR <when>
|
||||||
|
.IP
|
||||||
|
Specify when to use colored output. The automatic mode only enables colors if
|
||||||
|
an interactive terminal is detected. [default: auto] [possible values: auto,
|
||||||
|
never, always]
|
||||||
|
.HP
|
||||||
|
\fB\-\-decorations\fR <when>
|
||||||
|
.IP
|
||||||
|
Specify when to use the decorations that have been specified via '\-\-style'.
|
||||||
|
The automatic mode only enables decorations if an interactive terminal is
|
||||||
|
detected. [default: auto] [possible values: auto, never, always]
|
||||||
|
.HP
|
||||||
|
\fB\-\-paging\fR <when>
|
||||||
|
.IP
|
||||||
|
Specify when to use the pager. To control which pager is used, set the PAGER
|
||||||
|
or BAT_PAGER environment variables (the latter takes precedence). The default
|
||||||
|
pager is 'less'. To disable the pager permanently, set BAT_PAGER to an empty
|
||||||
|
string. [default: auto] [possible values: auto, never, always]
|
||||||
|
.HP
|
||||||
|
\fB\-\-wrap\fR <mode>
|
||||||
|
.IP
|
||||||
|
Specify the text\-wrapping mode. [default: character]
|
||||||
|
[possible values: character, never]
|
||||||
|
.HP
|
||||||
|
\fB\-u\fR
|
||||||
|
.IP
|
||||||
|
This option exists for POSIX\-compliance reasons ('u' is for 'unbuffered'). The
|
||||||
|
output is always unbuffered \- this option is simply ignored.
|
||||||
|
.HP
|
||||||
|
\fB\-h\fR, \fB\-\-help\fR
|
||||||
|
.IP
|
||||||
|
Print this help message.
|
||||||
|
.HP
|
||||||
|
\fB\-V\fR, \fB\-\-version\fR
|
||||||
|
.IP
|
||||||
|
Show version information.
|
||||||
|
.SH "ARGS"
|
||||||
|
.IP
|
||||||
|
<FILE>...
|
||||||
|
.IP
|
||||||
|
File(s) to print / concatenate. Use a dash ('\-') or no argument at all to read
|
||||||
|
from standard input.
|
||||||
|
.SH "SUBCOMMANDS"
|
||||||
|
.IP
|
||||||
|
cache
|
||||||
|
.IP
|
||||||
|
Modify the syntax\-definition and theme cache. See "bat cache --help" for more information
|
||||||
+254
-149
@@ -1,14 +1,82 @@
|
|||||||
use atty::{self, Stream};
|
|
||||||
use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand};
|
|
||||||
use console::Term;
|
|
||||||
use errors::*;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::env;
|
use std::env;
|
||||||
use style::{OutputComponent, OutputComponents, OutputWrap};
|
|
||||||
|
use atty::{self, Stream};
|
||||||
|
|
||||||
|
use clap::{App as ClapApp, AppSettings, Arg, ArgGroup, ArgMatches, SubCommand};
|
||||||
|
|
||||||
|
use console::Term;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use ansi_term;
|
use ansi_term;
|
||||||
|
|
||||||
|
use assets::BAT_THEME_DEFAULT;
|
||||||
|
use errors::*;
|
||||||
|
use line_range::LineRange;
|
||||||
|
use style::{OutputComponent, OutputComponents, OutputWrap};
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
pub enum PagingMode {
|
||||||
|
Always,
|
||||||
|
QuitIfOneScreen,
|
||||||
|
Never,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
|
pub enum InputFile<'a> {
|
||||||
|
StdIn,
|
||||||
|
Ordinary(&'a str),
|
||||||
|
ThemePreviewFile,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct Config<'a> {
|
||||||
|
/// List of files to print
|
||||||
|
pub files: Vec<InputFile<'a>>,
|
||||||
|
|
||||||
|
/// The explicitly configured language, if any
|
||||||
|
pub language: Option<&'a str>,
|
||||||
|
|
||||||
|
/// The character width of the terminal
|
||||||
|
pub term_width: usize,
|
||||||
|
|
||||||
|
/// Whether or not to simply loop through all input (`cat` mode)
|
||||||
|
pub loop_through: bool,
|
||||||
|
|
||||||
|
/// Whether or not the output should be colorized
|
||||||
|
pub colored_output: bool,
|
||||||
|
|
||||||
|
/// Whether or not the output terminal supports true color
|
||||||
|
pub true_color: bool,
|
||||||
|
|
||||||
|
/// Style elements (grid, line numbers, ...)
|
||||||
|
pub output_components: OutputComponents,
|
||||||
|
|
||||||
|
/// Text wrapping mode
|
||||||
|
pub output_wrap: OutputWrap,
|
||||||
|
|
||||||
|
/// Pager or STDOUT
|
||||||
|
pub paging_mode: PagingMode,
|
||||||
|
|
||||||
|
/// The range lines that should be printed, if specified
|
||||||
|
pub line_range: Option<LineRange>,
|
||||||
|
|
||||||
|
/// The syntax highlighting theme
|
||||||
|
pub theme: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_truecolor_terminal() -> bool {
|
||||||
|
env::var("COLORTERM")
|
||||||
|
.map(|colorterm| colorterm == "truecolor" || colorterm == "24bit")
|
||||||
|
.unwrap_or(false)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Helper function that should might appear in Rust stable at some point
|
||||||
|
/// (https://doc.rust-lang.org/stable/std/option/enum.Option.html#method.transpose)
|
||||||
|
fn transpose<T>(opt: Option<Result<T>>) -> Result<Option<T>> {
|
||||||
|
opt.map_or(Ok(None), |res| res.map(Some))
|
||||||
|
}
|
||||||
|
|
||||||
pub struct App {
|
pub struct App {
|
||||||
pub matches: ArgMatches<'static>,
|
pub matches: ArgMatches<'static>,
|
||||||
interactive_output: bool,
|
interactive_output: bool,
|
||||||
@@ -48,33 +116,52 @@ impl App {
|
|||||||
.about(
|
.about(
|
||||||
"A cat(1) clone with wings.\n\n\
|
"A cat(1) clone with wings.\n\n\
|
||||||
Use '--help' instead of '-h' to see a more detailed version of the help text.",
|
Use '--help' instead of '-h' to see a more detailed version of the help text.",
|
||||||
)
|
).long_about("A cat(1) clone with syntax highlighting and Git integration.")
|
||||||
.long_about("A cat(1) clone with syntax highlighting and Git integration.")
|
.arg(
|
||||||
|
Arg::with_name("FILE")
|
||||||
|
.help("File(s) to print / concatenate. Use '-' for standard input.")
|
||||||
|
.long_help(
|
||||||
|
"File(s) to print / concatenate. Use a dash ('-') or no argument at all \
|
||||||
|
to read from standard input.",
|
||||||
|
).multiple(true)
|
||||||
|
.empty_values(false),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("language")
|
Arg::with_name("language")
|
||||||
.short("l")
|
.short("l")
|
||||||
.long("language")
|
.long("language")
|
||||||
.overrides_with("language")
|
.overrides_with("language")
|
||||||
.help("Set the language for highlighting")
|
.help("Set the language for syntax highlighting.")
|
||||||
.long_help(
|
.long_help(
|
||||||
"Set the language for syntax highlighting. The language can be \
|
"Explicitly set the language for syntax highlighting. The language can be \
|
||||||
specified as a name (like 'C++' or 'LaTeX') or possible file \
|
specified as a name (like 'C++' or 'LaTeX') or possible file extension \
|
||||||
extension (like 'cpp', 'hpp' or 'md'). Use '--list-languages' \
|
(like 'cpp', 'hpp' or 'md'). Use '--list-languages' to show all supported \
|
||||||
to show all supported language names and file extensions",
|
language names and file extensions."
|
||||||
)
|
).takes_value(true),
|
||||||
.takes_value(true),
|
).arg(
|
||||||
)
|
Arg::with_name("list-languages")
|
||||||
.arg(
|
.long("list-languages")
|
||||||
Arg::with_name("FILE")
|
.conflicts_with("list-themes")
|
||||||
.help("File(s) to print / concatenate. Use '-' for standard input.")
|
.help("Display all supported languages.")
|
||||||
|
.long_help("Display a list of supported languages for syntax highlighting."),
|
||||||
|
).arg(
|
||||||
|
Arg::with_name("theme")
|
||||||
|
.long("theme")
|
||||||
|
.overrides_with("theme")
|
||||||
|
.takes_value(true)
|
||||||
|
.help("Set the color theme for syntax highlighting.")
|
||||||
.long_help(
|
.long_help(
|
||||||
"File(s) to print. Use no argument or '-' to read from standard \
|
"Set the theme for syntax highlighting. Use '--list-themes' to \
|
||||||
input",
|
see all available themes. To set a default theme, export the \
|
||||||
)
|
BAT_THEME environment variable (e.g.: export \
|
||||||
.multiple(true)
|
BAT_THEME=\"TwoDark\").",
|
||||||
.empty_values(false),
|
),
|
||||||
)
|
).arg(
|
||||||
.arg(
|
Arg::with_name("list-themes")
|
||||||
|
.long("list-themes")
|
||||||
|
.help("Display all supported highlighting themes.")
|
||||||
|
.long_help("Display a list of supported themes for syntax highlighting."),
|
||||||
|
).arg(
|
||||||
Arg::with_name("style")
|
Arg::with_name("style")
|
||||||
.long("style")
|
.long("style")
|
||||||
.value_name("style-components")
|
.value_name("style-components")
|
||||||
@@ -82,9 +169,8 @@ impl App {
|
|||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.possible_values(&[
|
.possible_values(&[
|
||||||
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
"auto", "full", "plain", "changes", "header", "grid", "numbers",
|
||||||
])
|
]).default_value("auto")
|
||||||
.default_value("auto")
|
.help("Comma-separated list of style elements to display.")
|
||||||
.help("Comma-separated list of style elements to display")
|
|
||||||
.long_help(
|
.long_help(
|
||||||
"Configure which elements (line numbers, file headers, grid \
|
"Configure which elements (line numbers, file headers, grid \
|
||||||
borders, Git modifications, ..) to display in addition to the \
|
borders, Git modifications, ..) to display in addition to the \
|
||||||
@@ -92,8 +178,44 @@ impl App {
|
|||||||
components to display (e.g. 'numbers,changes,grid') or a \
|
components to display (e.g. 'numbers,changes,grid') or a \
|
||||||
pre-defined style ('full')",
|
pre-defined style ('full')",
|
||||||
),
|
),
|
||||||
)
|
).arg(
|
||||||
.arg(
|
Arg::with_name("plain")
|
||||||
|
.overrides_with("plain")
|
||||||
|
.short("p")
|
||||||
|
.long("plain")
|
||||||
|
.conflicts_with("style")
|
||||||
|
.conflicts_with("number")
|
||||||
|
.help("Show plain style (alias for '--style=plain').")
|
||||||
|
.long_help(
|
||||||
|
"Only show plain style, no decorations. This is an alias for \
|
||||||
|
'--style=plain'",
|
||||||
|
),
|
||||||
|
).arg(
|
||||||
|
Arg::with_name("number")
|
||||||
|
.long("number")
|
||||||
|
.overrides_with("number")
|
||||||
|
.short("n")
|
||||||
|
.conflicts_with("style")
|
||||||
|
.help("Show line numbers (alias for '--style=numbers').")
|
||||||
|
.long_help(
|
||||||
|
"Only show line numbers, no other decorations. This is an alias for \
|
||||||
|
'--style=numbers'",
|
||||||
|
),
|
||||||
|
).arg(
|
||||||
|
Arg::with_name("line-range")
|
||||||
|
.long("line-range")
|
||||||
|
.overrides_with("line-range")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("N:M")
|
||||||
|
.help("Only print the lines from N to M.")
|
||||||
|
.long_help(
|
||||||
|
"Only print the specified range of lines for each file. \
|
||||||
|
For example:\n \
|
||||||
|
'--line-range 30:40' prints lines 30 to 40\n \
|
||||||
|
'--line-range :40' prints lines 1 to 40\n \
|
||||||
|
'--line-range 40:' prints lines 40 to the end of the file",
|
||||||
|
),
|
||||||
|
).arg(
|
||||||
Arg::with_name("color")
|
Arg::with_name("color")
|
||||||
.long("color")
|
.long("color")
|
||||||
.overrides_with("color")
|
.overrides_with("color")
|
||||||
@@ -101,9 +223,22 @@ impl App {
|
|||||||
.value_name("when")
|
.value_name("when")
|
||||||
.possible_values(&["auto", "never", "always"])
|
.possible_values(&["auto", "never", "always"])
|
||||||
.default_value("auto")
|
.default_value("auto")
|
||||||
.help("When to use colors"),
|
.help("When to use colors.")
|
||||||
)
|
.long_help("Specify when to use colored output. The automatic mode \
|
||||||
.arg(
|
only enables colors if an interactive terminal is detected."),
|
||||||
|
).arg(
|
||||||
|
Arg::with_name("decorations")
|
||||||
|
.long("decorations")
|
||||||
|
.overrides_with("decorations")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("when")
|
||||||
|
.possible_values(&["auto", "never", "always"])
|
||||||
|
.default_value("auto")
|
||||||
|
.help("When to show the decorations specified by '--style'.")
|
||||||
|
.long_help("Specify when to use the decorations that have been specified \
|
||||||
|
via '--style'. The automatic mode only enables decorations if \
|
||||||
|
an interactive terminal is detected."),
|
||||||
|
).arg(
|
||||||
Arg::with_name("paging")
|
Arg::with_name("paging")
|
||||||
.long("paging")
|
.long("paging")
|
||||||
.overrides_with("paging")
|
.overrides_with("paging")
|
||||||
@@ -111,10 +246,13 @@ impl App {
|
|||||||
.value_name("when")
|
.value_name("when")
|
||||||
.possible_values(&["auto", "never", "always"])
|
.possible_values(&["auto", "never", "always"])
|
||||||
.default_value("auto")
|
.default_value("auto")
|
||||||
.help("When to use the pager")
|
.help("Specify when to use the pager.")
|
||||||
.long_help("Specify when to use the pager (less)"),
|
.long_help("Specify when to use the pager. To control which pager \
|
||||||
)
|
is used, set the PAGER or BAT_PAGER environment \
|
||||||
.arg(
|
variables (the latter takes precedence). The default \
|
||||||
|
pager is 'less'. To disable the pager permanently, set \
|
||||||
|
BAT_PAGER to an empty string."),
|
||||||
|
).arg(
|
||||||
Arg::with_name("wrap")
|
Arg::with_name("wrap")
|
||||||
.long("wrap")
|
.long("wrap")
|
||||||
.overrides_with("wrap")
|
.overrides_with("wrap")
|
||||||
@@ -122,104 +260,74 @@ impl App {
|
|||||||
.value_name("mode")
|
.value_name("mode")
|
||||||
.possible_values(&["character", "never"])
|
.possible_values(&["character", "never"])
|
||||||
.default_value("character")
|
.default_value("character")
|
||||||
.help("When to wrap text"),
|
.help("Specify the text-wrapping mode.")
|
||||||
)
|
.long_help("Specify the text-wrapping mode."),
|
||||||
.arg(
|
).arg(
|
||||||
Arg::with_name("list-languages")
|
|
||||||
.long("list-languages")
|
|
||||||
.help("Displays supported languages")
|
|
||||||
.long_help("Display a list of supported languages"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("theme")
|
|
||||||
.long("theme")
|
|
||||||
.overrides_with("theme")
|
|
||||||
.takes_value(true)
|
|
||||||
.help("Set the theme for highlighting")
|
|
||||||
.long_help(
|
|
||||||
"Set the theme for syntax highlighting. Use '--list-themes' to \
|
|
||||||
see all available themes",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("list-themes")
|
|
||||||
.long("list-themes")
|
|
||||||
.help("Displays supported themes")
|
|
||||||
.help("Display a list of supported themes for syntax highlighting"),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("number")
|
|
||||||
.long("number")
|
|
||||||
.overrides_with("number")
|
|
||||||
.short("n")
|
|
||||||
.conflicts_with("style")
|
|
||||||
.help("Show line numbers (alias for '--style=numbers')")
|
|
||||||
.long_help(
|
|
||||||
"Show line numbers (no other decorations). This is an alias for \
|
|
||||||
'--style=numbers'",
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.arg(
|
|
||||||
Arg::with_name("unbuffered")
|
Arg::with_name("unbuffered")
|
||||||
.short("u")
|
.short("u")
|
||||||
.help("(ignored)")
|
.hidden_short_help(true)
|
||||||
// TODO: use '.hidden_short_help(true)' when the next clap version is released
|
|
||||||
.long_help(
|
.long_help(
|
||||||
"This option exists for POSIX-compliance reasons ('u' is for \
|
"This option exists for POSIX-compliance reasons ('u' is for \
|
||||||
'unbuffered'). The output is always unbuffered - this option \
|
'unbuffered'). The output is always unbuffered - this option \
|
||||||
it simply ignored.",
|
is simply ignored.",
|
||||||
),
|
),
|
||||||
)
|
).arg(
|
||||||
.subcommand(
|
Arg::with_name("terminal-width")
|
||||||
|
.long("terminal-width")
|
||||||
|
.takes_value(true)
|
||||||
|
.value_name("width")
|
||||||
|
.hidden(true)
|
||||||
|
.help("Set the width of the terminal"),
|
||||||
|
).subcommand(
|
||||||
SubCommand::with_name("cache")
|
SubCommand::with_name("cache")
|
||||||
.about("Modify the syntax-definition and theme cache")
|
.about("Modify the syntax-definition and theme cache")
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("init")
|
Arg::with_name("init")
|
||||||
.long("init")
|
.long("init")
|
||||||
.short("i")
|
.short("i")
|
||||||
.help("Initialize the syntax/theme cache")
|
.help("Initialize the syntax/theme cache.")
|
||||||
.long_help(
|
.long_help(
|
||||||
"Initialize the syntax/theme cache by loading from the \
|
"Initialize the syntax/theme cache by loading from the \
|
||||||
source directory (default: the configuration directory)",
|
source directory (default: the configuration directory).",
|
||||||
),
|
),
|
||||||
)
|
).arg(
|
||||||
.arg(
|
|
||||||
Arg::with_name("clear")
|
Arg::with_name("clear")
|
||||||
.long("clear")
|
.long("clear")
|
||||||
.short("c")
|
.short("c")
|
||||||
.help("Reset the cache"),
|
.help("Remove the cached syntax definitions and themes."),
|
||||||
)
|
).arg(
|
||||||
.arg(
|
|
||||||
Arg::with_name("config-dir")
|
Arg::with_name("config-dir")
|
||||||
.long("config-dir")
|
.long("config-dir")
|
||||||
.short("d")
|
.short("d")
|
||||||
.help("Show the configuration directory"),
|
.help("Show bat's configuration directory."),
|
||||||
)
|
).group(
|
||||||
.group(
|
|
||||||
ArgGroup::with_name("cache-actions")
|
ArgGroup::with_name("cache-actions")
|
||||||
.args(&["init", "clear", "config-dir"])
|
.args(&["init", "clear", "config-dir"])
|
||||||
.required(true),
|
.required(true),
|
||||||
)
|
).arg(
|
||||||
.arg(
|
|
||||||
Arg::with_name("source")
|
Arg::with_name("source")
|
||||||
.long("source")
|
.long("source")
|
||||||
.requires("init")
|
.requires("init")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("dir")
|
.value_name("dir")
|
||||||
.help("Use a different source for loading syntaxes and themes from"),
|
.help("Use a different directory to load syntaxes and themes from."),
|
||||||
)
|
).arg(
|
||||||
.arg(
|
|
||||||
Arg::with_name("target")
|
Arg::with_name("target")
|
||||||
.long("target")
|
.long("target")
|
||||||
.requires("init")
|
.requires("init")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("dir")
|
.value_name("dir")
|
||||||
.help(
|
.help(
|
||||||
"Use a different source to store the cached syntax and theme set",
|
"Use a different directory to store the cached syntax and theme set.",
|
||||||
),
|
),
|
||||||
|
).arg(
|
||||||
|
Arg::with_name("blank")
|
||||||
|
.long("blank")
|
||||||
|
.requires("init")
|
||||||
|
.help("Create completely new syntax and theme sets \
|
||||||
|
(instead of appending to the default sets).")
|
||||||
),
|
),
|
||||||
)
|
).help_message("Print this help message.")
|
||||||
.help_message("Print this help message.")
|
|
||||||
.version_message("Show version information.")
|
.version_message("Show version information.")
|
||||||
.get_matches()
|
.get_matches()
|
||||||
}
|
}
|
||||||
@@ -227,6 +335,15 @@ impl App {
|
|||||||
pub fn config(&self) -> Result<Config> {
|
pub fn config(&self) -> Result<Config> {
|
||||||
let files = self.files();
|
let files = self.files();
|
||||||
|
|
||||||
|
let colored_output = match self.matches.value_of("color") {
|
||||||
|
Some("always") => true,
|
||||||
|
Some("never") => false,
|
||||||
|
Some("auto") | _ => self.interactive_output,
|
||||||
|
};
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
let colored_output = colored_output && ansi_term::enable_ansi_support().is_ok();
|
||||||
|
|
||||||
Ok(Config {
|
Ok(Config {
|
||||||
true_color: is_truecolor_terminal(),
|
true_color: is_truecolor_terminal(),
|
||||||
output_components: self.output_components()?,
|
output_components: self.output_components()?,
|
||||||
@@ -241,15 +358,11 @@ impl App {
|
|||||||
Some("never") | _ => OutputWrap::None,
|
Some("never") | _ => OutputWrap::None,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
colored_output: match self.matches.value_of("color") {
|
colored_output,
|
||||||
Some("always") => true,
|
|
||||||
Some("never") => false,
|
|
||||||
Some("auto") | _ => self.interactive_output,
|
|
||||||
},
|
|
||||||
paging_mode: match self.matches.value_of("paging") {
|
paging_mode: match self.matches.value_of("paging") {
|
||||||
Some("always") => PagingMode::Always,
|
Some("always") => PagingMode::Always,
|
||||||
Some("never") => PagingMode::Never,
|
Some("never") => PagingMode::Never,
|
||||||
Some("auto") | _ => if files.contains(&None) {
|
Some("auto") | _ => if files.contains(&InputFile::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
|
||||||
// interactive terminal and if we do not *read* from an interactive
|
// interactive terminal and if we do not *read* from an interactive
|
||||||
// terminal.
|
// terminal.
|
||||||
@@ -266,66 +379,58 @@ impl App {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
term_width: Term::stdout().size().1 as usize,
|
term_width: self
|
||||||
|
.matches
|
||||||
|
.value_of("terminal-width")
|
||||||
|
.and_then(|w| w.parse().ok())
|
||||||
|
.unwrap_or(Term::stdout().size().1 as usize),
|
||||||
|
loop_through: !(self.interactive_output
|
||||||
|
|| self.matches.value_of("color") == Some("always")
|
||||||
|
|| self.matches.value_of("decorations") == Some("always")),
|
||||||
files,
|
files,
|
||||||
theme: self.matches.value_of("theme"),
|
theme: self
|
||||||
|
.matches
|
||||||
|
.value_of("theme")
|
||||||
|
.map(String::from)
|
||||||
|
.or_else(|| env::var("BAT_THEME").ok())
|
||||||
|
.unwrap_or(String::from(BAT_THEME_DEFAULT)),
|
||||||
|
line_range: transpose(self.matches.value_of("line-range").map(LineRange::from))?,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn files(&self) -> Vec<Option<&str>> {
|
fn files(&self) -> Vec<InputFile> {
|
||||||
self.matches
|
self.matches
|
||||||
.values_of("FILE")
|
.values_of("FILE")
|
||||||
.map(|values| {
|
.map(|values| {
|
||||||
values
|
values
|
||||||
.map(|filename| {
|
.map(|filename| {
|
||||||
if filename == "-" {
|
if filename == "-" {
|
||||||
None
|
InputFile::StdIn
|
||||||
} else {
|
} else {
|
||||||
Some(filename)
|
InputFile::Ordinary(filename)
|
||||||
}
|
}
|
||||||
})
|
}).collect()
|
||||||
.collect()
|
}).unwrap_or_else(|| vec![InputFile::StdIn])
|
||||||
})
|
|
||||||
.unwrap_or_else(|| vec![None]) // read from stdin (None) if no args are given
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn output_components(&self) -> Result<OutputComponents> {
|
fn output_components(&self) -> Result<OutputComponents> {
|
||||||
let matches = &self.matches;
|
let matches = &self.matches;
|
||||||
Ok(OutputComponents(if matches.is_present("number") {
|
Ok(OutputComponents(
|
||||||
[OutputComponent::Numbers].iter().cloned().collect()
|
if matches.value_of("decorations") == Some("never") {
|
||||||
} else {
|
HashSet::new()
|
||||||
values_t!(matches.values_of("style"), OutputComponent)?
|
} else if matches.is_present("number") {
|
||||||
.into_iter()
|
[OutputComponent::Numbers].iter().cloned().collect()
|
||||||
.map(|style| style.components(self.interactive_output))
|
} else if matches.is_present("plain") {
|
||||||
.fold(HashSet::new(), |mut acc, components| {
|
[OutputComponent::Plain].iter().cloned().collect()
|
||||||
acc.extend(components.iter().cloned());
|
} else {
|
||||||
acc
|
values_t!(matches.values_of("style"), OutputComponent)?
|
||||||
})
|
.into_iter()
|
||||||
}))
|
.map(|style| style.components(self.interactive_output))
|
||||||
|
.fold(HashSet::new(), |mut acc, components| {
|
||||||
|
acc.extend(components.iter().cloned());
|
||||||
|
acc
|
||||||
|
})
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
|
||||||
pub enum PagingMode {
|
|
||||||
Always,
|
|
||||||
QuitIfOneScreen,
|
|
||||||
Never,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Config<'a> {
|
|
||||||
pub true_color: bool,
|
|
||||||
pub output_wrap: OutputWrap,
|
|
||||||
pub output_components: OutputComponents,
|
|
||||||
pub language: Option<&'a str>,
|
|
||||||
pub colored_output: bool,
|
|
||||||
pub paging_mode: PagingMode,
|
|
||||||
pub term_width: usize,
|
|
||||||
pub files: Vec<Option<&'a str>>,
|
|
||||||
pub theme: Option<&'a str>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_truecolor_terminal() -> bool {
|
|
||||||
env::var("COLORTERM")
|
|
||||||
.map(|colorterm| colorterm == "truecolor" || colorterm == "24bit")
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
|||||||
+85
-35
@@ -1,8 +1,8 @@
|
|||||||
use directories::ProjectDirs;
|
use directories::ProjectDirs;
|
||||||
use errors::*;
|
use errors::*;
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::collections::BTreeMap;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
use syntect::dumps::{dump_to_file, from_binary, from_reader};
|
||||||
use syntect::highlighting::{Theme, ThemeSet};
|
use syntect::highlighting::{Theme, ThemeSet};
|
||||||
@@ -11,10 +11,15 @@ use syntect::parsing::{SyntaxDefinition, SyntaxSet};
|
|||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use std::os::unix::fs::FileTypeExt;
|
use std::os::unix::fs::FileTypeExt;
|
||||||
|
|
||||||
|
use app::InputFile;
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref PROJECT_DIRS: ProjectDirs = ProjectDirs::from("", "", crate_name!());
|
static ref PROJECT_DIRS: ProjectDirs =
|
||||||
|
ProjectDirs::from("", "", crate_name!()).expect("Could not get home directory");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const BAT_THEME_DEFAULT: &str = "Monokai Extended";
|
||||||
|
|
||||||
pub struct HighlightingAssets {
|
pub struct HighlightingAssets {
|
||||||
pub syntax_set: SyntaxSet,
|
pub syntax_set: SyntaxSet,
|
||||||
pub theme_set: ThemeSet,
|
pub theme_set: ThemeSet,
|
||||||
@@ -25,31 +30,49 @@ impl HighlightingAssets {
|
|||||||
Self::from_cache().unwrap_or_else(|_| Self::from_binary())
|
Self::from_cache().unwrap_or_else(|_| Self::from_binary())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_files(dir: Option<&Path>) -> Result<Self> {
|
fn empty() -> Self {
|
||||||
let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
|
|
||||||
|
|
||||||
let theme_dir = source_dir.join("themes");
|
|
||||||
let theme_set = ThemeSet::load_from_folder(&theme_dir).chain_err(|| {
|
|
||||||
format!(
|
|
||||||
"Could not load themes from '{}'",
|
|
||||||
theme_dir.to_string_lossy()
|
|
||||||
)
|
|
||||||
})?;
|
|
||||||
let mut syntax_set = SyntaxSet::new();
|
let mut syntax_set = SyntaxSet::new();
|
||||||
let syntax_dir = source_dir.join("syntaxes");
|
|
||||||
if !syntax_dir.exists() {
|
|
||||||
return Err(format!(
|
|
||||||
"Could not load syntaxes from '{}'",
|
|
||||||
syntax_dir.to_string_lossy()
|
|
||||||
).into());
|
|
||||||
}
|
|
||||||
syntax_set.load_syntaxes(syntax_dir, true)?;
|
|
||||||
syntax_set.load_plain_text_syntax();
|
syntax_set.load_plain_text_syntax();
|
||||||
|
|
||||||
Ok(HighlightingAssets {
|
let theme_set = ThemeSet {
|
||||||
|
themes: BTreeMap::new(),
|
||||||
|
};
|
||||||
|
HighlightingAssets {
|
||||||
syntax_set,
|
syntax_set,
|
||||||
theme_set,
|
theme_set,
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn from_files(dir: Option<&Path>, start_empty: bool) -> Result<Self> {
|
||||||
|
let source_dir = dir.unwrap_or_else(|| PROJECT_DIRS.config_dir());
|
||||||
|
|
||||||
|
let mut assets = if start_empty {
|
||||||
|
Self::empty()
|
||||||
|
} else {
|
||||||
|
Self::from_binary_unlinked()
|
||||||
|
};
|
||||||
|
|
||||||
|
let theme_dir = source_dir.join("themes");
|
||||||
|
|
||||||
|
let res = extend_theme_set(&mut assets.theme_set, &theme_dir);
|
||||||
|
if !res.is_ok() {
|
||||||
|
println!(
|
||||||
|
"No themes were found in '{}', using the default set",
|
||||||
|
theme_dir.to_string_lossy()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let syntax_dir = source_dir.join("syntaxes");
|
||||||
|
if syntax_dir.exists() {
|
||||||
|
assets.syntax_set.load_syntaxes(syntax_dir, true)?;
|
||||||
|
} else {
|
||||||
|
println!(
|
||||||
|
"No syntaxes were found in '{}', using the default set.",
|
||||||
|
syntax_dir.to_string_lossy()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(assets)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_cache() -> Result<Self> {
|
fn from_cache() -> Result<Self> {
|
||||||
@@ -79,9 +102,8 @@ impl HighlightingAssets {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_binary() -> Self {
|
fn from_binary_unlinked() -> Self {
|
||||||
let mut syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntaxes.bin"));
|
let syntax_set: SyntaxSet = from_binary(include_bytes!("../assets/syntaxes.bin"));
|
||||||
syntax_set.link_syntaxes();
|
|
||||||
let theme_set: ThemeSet = from_binary(include_bytes!("../assets/themes.bin"));
|
let theme_set: ThemeSet = from_binary(include_bytes!("../assets/themes.bin"));
|
||||||
|
|
||||||
HighlightingAssets {
|
HighlightingAssets {
|
||||||
@@ -90,6 +112,12 @@ impl HighlightingAssets {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn from_binary() -> Self {
|
||||||
|
let mut assets = Self::from_binary_unlinked();
|
||||||
|
assets.syntax_set.link_syntaxes();
|
||||||
|
assets
|
||||||
|
}
|
||||||
|
|
||||||
pub fn save(&self, dir: Option<&Path>) -> Result<()> {
|
pub fn save(&self, dir: Option<&Path>) -> Result<()> {
|
||||||
let target_dir = dir.unwrap_or_else(|| PROJECT_DIRS.cache_dir());
|
let target_dir = dir.unwrap_or_else(|| PROJECT_DIRS.cache_dir());
|
||||||
let _ = fs::create_dir(target_dir);
|
let _ = fs::create_dir(target_dir);
|
||||||
@@ -123,19 +151,25 @@ impl HighlightingAssets {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_theme(&self, theme: &str) -> Result<&Theme> {
|
pub fn get_theme(&self, theme: &str) -> &Theme {
|
||||||
Ok(self.theme_set.themes.get(theme).ok_or_else(|| {
|
match self.theme_set.themes.get(theme) {
|
||||||
io::Error::new(
|
Some(theme) => theme,
|
||||||
io::ErrorKind::Other,
|
None => {
|
||||||
format!("Could not find '{}' theme", theme),
|
use ansi_term::Colour::Yellow;
|
||||||
)
|
eprintln!(
|
||||||
})?)
|
"{}: Unknown theme '{}', using default.",
|
||||||
|
Yellow.paint("[bat warning]"),
|
||||||
|
theme
|
||||||
|
);
|
||||||
|
&self.theme_set.themes[BAT_THEME_DEFAULT]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_syntax(&self, language: Option<&str>, filename: Option<&str>) -> &SyntaxDefinition {
|
pub fn get_syntax(&self, language: Option<&str>, filename: InputFile) -> &SyntaxDefinition {
|
||||||
let syntax = match (language, filename) {
|
let syntax = match (language, filename) {
|
||||||
(Some(language), _) => self.syntax_set.find_syntax_by_token(language),
|
(Some(language), _) => self.syntax_set.find_syntax_by_token(language),
|
||||||
(None, Some(filename)) => {
|
(None, InputFile::Ordinary(filename)) => {
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
let may_read_from_file = true;
|
let may_read_from_file = true;
|
||||||
|
|
||||||
@@ -154,13 +188,29 @@ impl HighlightingAssets {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(None, None) => None,
|
(None, InputFile::StdIn) => None,
|
||||||
|
(_, InputFile::ThemePreviewFile) => self.syntax_set.find_syntax_by_name("Rust"),
|
||||||
};
|
};
|
||||||
|
|
||||||
syntax.unwrap_or_else(|| self.syntax_set.find_syntax_plain_text())
|
syntax.unwrap_or_else(|| self.syntax_set.find_syntax_plain_text())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: this function will soon be part of syntect's `ThemeSet`.
|
||||||
|
fn extend_theme_set<P: AsRef<Path>>(theme_set: &mut ThemeSet, folder: P) -> Result<()> {
|
||||||
|
let paths = ThemeSet::discover_theme_paths(folder)?;
|
||||||
|
for p in &paths {
|
||||||
|
let theme = ThemeSet::get_theme(p)?;
|
||||||
|
let basename = p
|
||||||
|
.file_stem()
|
||||||
|
.and_then(|x| x.to_str())
|
||||||
|
.ok_or("Could not get theme basename")?;
|
||||||
|
theme_set.themes.insert(basename.to_owned(), theme);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn theme_set_path() -> PathBuf {
|
fn theme_set_path() -> PathBuf {
|
||||||
PROJECT_DIRS.cache_dir().join("themes.bin")
|
PROJECT_DIRS.cache_dir().join("themes.bin")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,104 @@
|
|||||||
|
use std::fs::File;
|
||||||
|
use std::io::{self, BufRead, BufReader, Write};
|
||||||
|
|
||||||
|
use app::{Config, InputFile};
|
||||||
|
use assets::HighlightingAssets;
|
||||||
|
use errors::*;
|
||||||
|
use line_range::LineRange;
|
||||||
|
use output::OutputType;
|
||||||
|
use printer::{InteractivePrinter, Printer, SimplePrinter};
|
||||||
|
|
||||||
|
const THEME_PREVIEW_FILE: &[u8] = include_bytes!("../assets/theme_preview.rs");
|
||||||
|
|
||||||
|
pub struct Controller<'a> {
|
||||||
|
config: &'a Config<'a>,
|
||||||
|
assets: &'a HighlightingAssets,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'b> Controller<'b> {
|
||||||
|
pub fn new<'a>(config: &'a Config, assets: &'a HighlightingAssets) -> Controller<'a> {
|
||||||
|
Controller { config, assets }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn run(&self) -> Result<bool> {
|
||||||
|
let mut output_type = OutputType::from_mode(self.config.paging_mode);
|
||||||
|
let writer = output_type.handle()?;
|
||||||
|
let mut no_errors: bool = true;
|
||||||
|
|
||||||
|
for filename in &self.config.files {
|
||||||
|
let result = if self.config.loop_through {
|
||||||
|
let mut printer = SimplePrinter::new();
|
||||||
|
self.print_file(&mut printer, writer, *filename)
|
||||||
|
} else {
|
||||||
|
let mut printer = InteractivePrinter::new(&self.config, &self.assets, *filename);
|
||||||
|
self.print_file(&mut printer, writer, *filename)
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(error) = result {
|
||||||
|
handle_error(&error);
|
||||||
|
no_errors = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(no_errors)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_file<'a, P: Printer>(
|
||||||
|
&self,
|
||||||
|
printer: &mut P,
|
||||||
|
writer: &mut Write,
|
||||||
|
filename: InputFile<'a>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let stdin = io::stdin();
|
||||||
|
{
|
||||||
|
let reader: Box<BufRead> = match filename {
|
||||||
|
InputFile::StdIn => Box::new(stdin.lock()),
|
||||||
|
InputFile::Ordinary(filename) => Box::new(BufReader::new(File::open(filename)?)),
|
||||||
|
InputFile::ThemePreviewFile => Box::new(THEME_PREVIEW_FILE),
|
||||||
|
};
|
||||||
|
|
||||||
|
printer.print_header(writer, filename)?;
|
||||||
|
self.print_file_ranges(printer, writer, reader, &self.config.line_range)?;
|
||||||
|
printer.print_footer(writer)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_file_ranges<'a, P: Printer>(
|
||||||
|
&self,
|
||||||
|
printer: &mut P,
|
||||||
|
writer: &mut Write,
|
||||||
|
mut reader: Box<BufRead + 'a>,
|
||||||
|
line_ranges: &Option<LineRange>,
|
||||||
|
) -> Result<()> {
|
||||||
|
let mut line_buffer = Vec::new();
|
||||||
|
|
||||||
|
let mut line_number: usize = 1;
|
||||||
|
|
||||||
|
while reader.read_until(b'\n', &mut line_buffer)? > 0 {
|
||||||
|
{
|
||||||
|
match line_ranges {
|
||||||
|
&Some(ref range) => {
|
||||||
|
if line_number < range.lower {
|
||||||
|
// Call the printer in case we need to call the syntax highlighter
|
||||||
|
// for this line. However, set `out_of_range` to `true`.
|
||||||
|
printer.print_line(true, writer, line_number, &line_buffer)?;
|
||||||
|
} else if line_number > range.upper {
|
||||||
|
// no more lines in range, exit early
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
|
printer.print_line(false, writer, line_number, &line_buffer)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
&None => {
|
||||||
|
printer.print_line(false, writer, line_number, &line_buffer)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
line_number += 1;
|
||||||
|
}
|
||||||
|
line_buffer.clear();
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
+10
-9
@@ -1,6 +1,6 @@
|
|||||||
use ansi_term::Style;
|
use ansi_term::Style;
|
||||||
use diff::LineChange;
|
use diff::LineChange;
|
||||||
use printer::{Colors, Printer};
|
use printer::{Colors, InteractivePrinter};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct DecorationText {
|
pub struct DecorationText {
|
||||||
@@ -9,12 +9,15 @@ pub struct DecorationText {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait Decoration {
|
pub trait Decoration {
|
||||||
fn generate(&self, line_number: usize, continuation: bool, printer: &Printer)
|
fn generate(
|
||||||
-> DecorationText;
|
&self,
|
||||||
|
line_number: usize,
|
||||||
|
continuation: bool,
|
||||||
|
printer: &InteractivePrinter,
|
||||||
|
) -> DecorationText;
|
||||||
fn width(&self) -> usize;
|
fn width(&self) -> usize;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Line number decoration.
|
|
||||||
pub struct LineNumberDecoration {
|
pub struct LineNumberDecoration {
|
||||||
color: Style,
|
color: Style,
|
||||||
cached_wrap: DecorationText,
|
cached_wrap: DecorationText,
|
||||||
@@ -39,7 +42,7 @@ impl Decoration for LineNumberDecoration {
|
|||||||
&self,
|
&self,
|
||||||
line_number: usize,
|
line_number: usize,
|
||||||
continuation: bool,
|
continuation: bool,
|
||||||
_printer: &Printer,
|
_printer: &InteractivePrinter,
|
||||||
) -> DecorationText {
|
) -> DecorationText {
|
||||||
if continuation {
|
if continuation {
|
||||||
if line_number > self.cached_wrap_invalid_at {
|
if line_number > self.cached_wrap_invalid_at {
|
||||||
@@ -65,7 +68,6 @@ impl Decoration for LineNumberDecoration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Line changes decoration.
|
|
||||||
pub struct LineChangesDecoration {
|
pub struct LineChangesDecoration {
|
||||||
cached_none: DecorationText,
|
cached_none: DecorationText,
|
||||||
cached_added: DecorationText,
|
cached_added: DecorationText,
|
||||||
@@ -99,7 +101,7 @@ impl Decoration for LineChangesDecoration {
|
|||||||
&self,
|
&self,
|
||||||
line_number: usize,
|
line_number: usize,
|
||||||
continuation: bool,
|
continuation: bool,
|
||||||
printer: &Printer,
|
printer: &InteractivePrinter,
|
||||||
) -> DecorationText {
|
) -> DecorationText {
|
||||||
if !continuation {
|
if !continuation {
|
||||||
if let Some(ref changes) = printer.line_changes {
|
if let Some(ref changes) = printer.line_changes {
|
||||||
@@ -121,7 +123,6 @@ impl Decoration for LineChangesDecoration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Grid border decoration.
|
|
||||||
pub struct GridBorderDecoration {
|
pub struct GridBorderDecoration {
|
||||||
cached: DecorationText,
|
cached: DecorationText,
|
||||||
}
|
}
|
||||||
@@ -142,7 +143,7 @@ impl Decoration for GridBorderDecoration {
|
|||||||
&self,
|
&self,
|
||||||
_line_number: usize,
|
_line_number: usize,
|
||||||
_continuation: bool,
|
_continuation: bool,
|
||||||
_printer: &Printer,
|
_printer: &InteractivePrinter,
|
||||||
) -> DecorationText {
|
) -> DecorationText {
|
||||||
self.cached.clone()
|
self.cached.clone()
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-4
@@ -15,11 +15,14 @@ pub type LineChanges = HashMap<u32, LineChange>;
|
|||||||
|
|
||||||
pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
||||||
let repo = Repository::discover(&filename).ok()?;
|
let repo = Repository::discover(&filename).ok()?;
|
||||||
let path_absolute = fs::canonicalize(&filename).ok()?;
|
|
||||||
let path_relative_to_repo = path_absolute.strip_prefix(repo.workdir()?).ok()?;
|
let repo_path_absolute = fs::canonicalize(repo.workdir()?).ok()?;
|
||||||
|
|
||||||
|
let filepath_absolute = fs::canonicalize(&filename).ok()?;
|
||||||
|
let filepath_relative_to_repo = filepath_absolute.strip_prefix(&repo_path_absolute).ok()?;
|
||||||
|
|
||||||
let mut diff_options = DiffOptions::new();
|
let mut diff_options = DiffOptions::new();
|
||||||
let pathspec = path_relative_to_repo.into_c_string().ok()?;
|
let pathspec = filepath_relative_to_repo.into_c_string().ok()?;
|
||||||
diff_options.pathspec(pathspec);
|
diff_options.pathspec(pathspec);
|
||||||
diff_options.context_lines(0);
|
diff_options.context_lines(0);
|
||||||
|
|
||||||
@@ -42,7 +45,7 @@ pub fn get_git_diff(filename: &str) -> Option<LineChanges> {
|
|||||||
Some(&mut |delta, hunk| {
|
Some(&mut |delta, hunk| {
|
||||||
let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
|
let path = delta.new_file().path().unwrap_or_else(|| Path::new(""));
|
||||||
|
|
||||||
if path_relative_to_repo != path {
|
if filepath_relative_to_repo != path {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-112
@@ -1,112 +0,0 @@
|
|||||||
use ansi_term::Colour::Green;
|
|
||||||
use app::Config;
|
|
||||||
use assets::HighlightingAssets;
|
|
||||||
use diff::get_git_diff;
|
|
||||||
use errors::*;
|
|
||||||
use output::OutputType;
|
|
||||||
use printer::Printer;
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io::{self, BufRead, BufReader};
|
|
||||||
use syntect::easy::HighlightLines;
|
|
||||||
use syntect::highlighting::Theme;
|
|
||||||
use syntect::parsing::SyntaxDefinition;
|
|
||||||
|
|
||||||
pub fn list_languages(assets: &HighlightingAssets, term_width: usize) {
|
|
||||||
let mut languages = assets
|
|
||||||
.syntax_set
|
|
||||||
.syntaxes()
|
|
||||||
.iter()
|
|
||||||
.filter(|syntax| !syntax.hidden && !syntax.file_extensions.is_empty())
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
languages.sort_by_key(|lang| lang.name.to_uppercase());
|
|
||||||
|
|
||||||
let longest = languages
|
|
||||||
.iter()
|
|
||||||
.map(|syntax| syntax.name.len())
|
|
||||||
.max()
|
|
||||||
.unwrap_or(32); // Fallback width if they have no language definitions.
|
|
||||||
|
|
||||||
let comma_separator = ", ";
|
|
||||||
let separator = " ";
|
|
||||||
// Line-wrapping for the possible file extension overflow.
|
|
||||||
let desired_width = term_width - longest - separator.len();
|
|
||||||
|
|
||||||
for lang in languages {
|
|
||||||
print!("{:width$}{}", lang.name, separator, width = longest);
|
|
||||||
|
|
||||||
// Number of characters on this line so far, wrap before `desired_width`
|
|
||||||
let mut num_chars = 0;
|
|
||||||
|
|
||||||
let mut extension = lang.file_extensions.iter().peekable();
|
|
||||||
while let Some(word) = extension.next() {
|
|
||||||
// If we can't fit this word in, then create a line break and align it in.
|
|
||||||
let new_chars = word.len() + comma_separator.len();
|
|
||||||
if num_chars + new_chars >= desired_width {
|
|
||||||
num_chars = 0;
|
|
||||||
print!("\n{:width$}{}", "", separator, width = longest);
|
|
||||||
}
|
|
||||||
|
|
||||||
num_chars += new_chars;
|
|
||||||
print!("{}", Green.paint(&word[..]));
|
|
||||||
if extension.peek().is_some() {
|
|
||||||
print!("{}", comma_separator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
println!();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn print_files(assets: &HighlightingAssets, config: &Config) -> Result<bool> {
|
|
||||||
let theme = assets.get_theme(config.theme.unwrap_or("Default"))?;
|
|
||||||
let mut output_type = OutputType::from_mode(config.paging_mode);
|
|
||||||
let handle = output_type.handle()?;
|
|
||||||
let mut printer = Printer::new(handle, &config);
|
|
||||||
let mut no_errors: bool = true;
|
|
||||||
|
|
||||||
for file in &config.files {
|
|
||||||
printer.line_changes = file.and_then(|filename| get_git_diff(filename));
|
|
||||||
let syntax = assets.get_syntax(config.language, *file);
|
|
||||||
|
|
||||||
let result = print_file(theme, &syntax, &mut printer, *file);
|
|
||||||
|
|
||||||
if let Err(error) = result {
|
|
||||||
handle_error(&error);
|
|
||||||
no_errors = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(no_errors)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_file(
|
|
||||||
theme: &Theme,
|
|
||||||
syntax: &SyntaxDefinition,
|
|
||||||
printer: &mut Printer,
|
|
||||||
filename: Option<&str>,
|
|
||||||
) -> Result<()> {
|
|
||||||
let stdin = io::stdin(); // TODO: this is not always needed
|
|
||||||
|
|
||||||
let mut reader: Box<BufRead> = match filename {
|
|
||||||
None => Box::new(stdin.lock()),
|
|
||||||
Some(filename) => Box::new(BufReader::new(File::open(filename)?)),
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut highlighter = HighlightLines::new(syntax, theme);
|
|
||||||
|
|
||||||
printer.print_header(filename)?;
|
|
||||||
|
|
||||||
let mut buffer = Vec::new();
|
|
||||||
while reader.read_until(b'\n', &mut buffer)? > 0 {
|
|
||||||
{
|
|
||||||
let line = String::from_utf8_lossy(&buffer);
|
|
||||||
let regions = highlighter.highlight(line.as_ref());
|
|
||||||
|
|
||||||
printer.print_line(®ions)?;
|
|
||||||
}
|
|
||||||
buffer.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
printer.print_footer()?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
use errors::*;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct LineRange {
|
||||||
|
pub lower: usize,
|
||||||
|
pub upper: usize,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LineRange {
|
||||||
|
pub fn from(range_raw: &str) -> Result<LineRange> {
|
||||||
|
LineRange::parse_range(range_raw)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new() -> LineRange {
|
||||||
|
LineRange {
|
||||||
|
lower: usize::min_value(),
|
||||||
|
upper: usize::max_value(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_range(range_raw: &str) -> Result<LineRange> {
|
||||||
|
let mut new_range = LineRange::new();
|
||||||
|
|
||||||
|
if range_raw.bytes().nth(0).ok_or("Empty line range")? == b':' {
|
||||||
|
new_range.upper = range_raw[1..].parse()?;
|
||||||
|
return Ok(new_range);
|
||||||
|
} else if range_raw.bytes().last().ok_or("Empty line range")? == b':' {
|
||||||
|
new_range.lower = range_raw[..range_raw.len() - 1].parse()?;
|
||||||
|
return Ok(new_range);
|
||||||
|
}
|
||||||
|
|
||||||
|
let line_numbers: Vec<&str> = range_raw.split(':').collect();
|
||||||
|
if line_numbers.len() == 2 {
|
||||||
|
new_range.lower = line_numbers[0].parse()?;
|
||||||
|
new_range.upper = line_numbers[1].parse()?;
|
||||||
|
return Ok(new_range);
|
||||||
|
}
|
||||||
|
|
||||||
|
Err("expected single ':' character".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_full() {
|
||||||
|
let range = LineRange::from("40:50").expect("Shouldn't fail on test!");
|
||||||
|
assert_eq!(40, range.lower);
|
||||||
|
assert_eq!(50, range.upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_partial_min() {
|
||||||
|
let range = LineRange::from(":50").expect("Shouldn't fail on test!");
|
||||||
|
assert_eq!(usize::min_value(), range.lower);
|
||||||
|
assert_eq!(50, range.upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_partial_max() {
|
||||||
|
let range = LineRange::from("40:").expect("Shouldn't fail on test!");
|
||||||
|
assert_eq!(40, range.lower);
|
||||||
|
assert_eq!(usize::max_value(), range.upper);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_fail() {
|
||||||
|
let range = LineRange::from("40:50:80");
|
||||||
|
assert!(range.is_err());
|
||||||
|
let range = LineRange::from("40::80");
|
||||||
|
assert!(range.is_err());
|
||||||
|
let range = LineRange::from(":40:");
|
||||||
|
assert!(range.is_err());
|
||||||
|
let range = LineRange::from("40");
|
||||||
|
assert!(range.is_err());
|
||||||
|
}
|
||||||
+127
-27
@@ -19,21 +19,28 @@ extern crate syntect;
|
|||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
mod assets;
|
mod assets;
|
||||||
|
mod controller;
|
||||||
mod decorations;
|
mod decorations;
|
||||||
mod diff;
|
mod diff;
|
||||||
mod features;
|
mod line_range;
|
||||||
mod output;
|
mod output;
|
||||||
mod printer;
|
mod printer;
|
||||||
mod style;
|
mod style;
|
||||||
mod terminal;
|
mod terminal;
|
||||||
|
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::io;
|
use std::io;
|
||||||
|
use std::io::Write;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process;
|
use std::process;
|
||||||
|
|
||||||
use app::App;
|
use ansi_term::Colour::Green;
|
||||||
|
use ansi_term::Style;
|
||||||
|
|
||||||
|
use app::{App, Config, InputFile};
|
||||||
use assets::{clear_assets, config_dir, HighlightingAssets};
|
use assets::{clear_assets, config_dir, HighlightingAssets};
|
||||||
use features::{list_languages, print_files};
|
use controller::Controller;
|
||||||
|
use style::{OutputComponent, OutputComponents};
|
||||||
|
|
||||||
mod errors {
|
mod errors {
|
||||||
error_chain! {
|
error_chain! {
|
||||||
@@ -41,6 +48,7 @@ mod errors {
|
|||||||
Clap(::clap::Error);
|
Clap(::clap::Error);
|
||||||
Io(::std::io::Error);
|
Io(::std::io::Error);
|
||||||
SyntectError(::syntect::LoadingError);
|
SyntectError(::syntect::LoadingError);
|
||||||
|
ParseIntError(::std::num::ParseIntError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -61,6 +69,111 @@ mod errors {
|
|||||||
|
|
||||||
use errors::*;
|
use errors::*;
|
||||||
|
|
||||||
|
fn run_cache_subcommand(matches: &clap::ArgMatches) -> Result<()> {
|
||||||
|
if matches.is_present("init") {
|
||||||
|
let source_dir = matches.value_of("source").map(Path::new);
|
||||||
|
let target_dir = matches.value_of("target").map(Path::new);
|
||||||
|
|
||||||
|
let blank = matches.is_present("blank");
|
||||||
|
|
||||||
|
let assets = HighlightingAssets::from_files(source_dir, blank)?;
|
||||||
|
assets.save(target_dir)?;
|
||||||
|
} else if matches.is_present("clear") {
|
||||||
|
clear_assets();
|
||||||
|
} else if matches.is_present("config-dir") {
|
||||||
|
writeln!(io::stdout(), "{}", config_dir())?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_languages(assets: &HighlightingAssets, config: &Config) -> Result<()> {
|
||||||
|
let mut languages = assets
|
||||||
|
.syntax_set
|
||||||
|
.syntaxes()
|
||||||
|
.iter()
|
||||||
|
.filter(|syntax| !syntax.hidden && !syntax.file_extensions.is_empty())
|
||||||
|
.collect::<Vec<_>>();
|
||||||
|
languages.sort_by_key(|lang| lang.name.to_uppercase());
|
||||||
|
|
||||||
|
let longest = languages
|
||||||
|
.iter()
|
||||||
|
.map(|syntax| syntax.name.len())
|
||||||
|
.max()
|
||||||
|
.unwrap_or(32); // Fallback width if they have no language definitions.
|
||||||
|
|
||||||
|
let comma_separator = ", ";
|
||||||
|
let separator = " ";
|
||||||
|
// Line-wrapping for the possible file extension overflow.
|
||||||
|
let desired_width = config.term_width - longest - separator.len();
|
||||||
|
|
||||||
|
let stdout = io::stdout();
|
||||||
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
|
let style = if config.colored_output {
|
||||||
|
Green.normal()
|
||||||
|
} else {
|
||||||
|
Style::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
for lang in languages {
|
||||||
|
write!(stdout, "{:width$}{}", lang.name, separator, width = longest)?;
|
||||||
|
|
||||||
|
// Number of characters on this line so far, wrap before `desired_width`
|
||||||
|
let mut num_chars = 0;
|
||||||
|
|
||||||
|
let mut extension = lang.file_extensions.iter().peekable();
|
||||||
|
while let Some(word) = extension.next() {
|
||||||
|
// If we can't fit this word in, then create a line break and align it in.
|
||||||
|
let new_chars = word.len() + comma_separator.len();
|
||||||
|
if num_chars + new_chars >= desired_width {
|
||||||
|
num_chars = 0;
|
||||||
|
write!(stdout, "\n{:width$}{}", "", separator, width = longest)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
num_chars += new_chars;
|
||||||
|
write!(stdout, "{}", style.paint(&word[..]))?;
|
||||||
|
if extension.peek().is_some() {
|
||||||
|
write!(stdout, "{}", comma_separator)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeln!(stdout)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn list_themes(assets: &HighlightingAssets, cfg: &Config) -> Result<()> {
|
||||||
|
let themes = &assets.theme_set.themes;
|
||||||
|
let mut config = cfg.clone();
|
||||||
|
let mut style = HashSet::new();
|
||||||
|
style.insert(OutputComponent::Plain);
|
||||||
|
config.files = vec![InputFile::ThemePreviewFile];
|
||||||
|
config.output_components = OutputComponents(style);
|
||||||
|
|
||||||
|
let stdout = io::stdout();
|
||||||
|
let mut stdout = stdout.lock();
|
||||||
|
|
||||||
|
if config.colored_output {
|
||||||
|
for (theme, _) in themes.iter() {
|
||||||
|
writeln!(
|
||||||
|
stdout,
|
||||||
|
"Theme: {}\n",
|
||||||
|
Style::new().bold().paint(theme.to_string())
|
||||||
|
)?;
|
||||||
|
config.theme = theme.to_string();
|
||||||
|
let _controller = Controller::new(&config, &assets).run();
|
||||||
|
writeln!(stdout)?;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (theme, _) in themes.iter() {
|
||||||
|
writeln!(stdout, "{}", theme)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns `Err(..)` upon fatal errors. Otherwise, returns `Some(true)` on full success and
|
/// Returns `Err(..)` upon fatal errors. Otherwise, returns `Some(true)` on full success and
|
||||||
/// `Some(false)` if any intermediate errors occurred (were printed).
|
/// `Some(false)` if any intermediate errors occurred (were printed).
|
||||||
fn run() -> Result<bool> {
|
fn run() -> Result<bool> {
|
||||||
@@ -68,38 +181,25 @@ fn run() -> Result<bool> {
|
|||||||
|
|
||||||
match app.matches.subcommand() {
|
match app.matches.subcommand() {
|
||||||
("cache", Some(cache_matches)) => {
|
("cache", Some(cache_matches)) => {
|
||||||
if cache_matches.is_present("init") {
|
run_cache_subcommand(cache_matches)?;
|
||||||
let source_dir = cache_matches.value_of("source").map(Path::new);
|
Ok(true)
|
||||||
let target_dir = cache_matches.value_of("target").map(Path::new);
|
|
||||||
|
|
||||||
let assets = HighlightingAssets::from_files(source_dir)?;
|
|
||||||
assets.save(target_dir)?;
|
|
||||||
} else if cache_matches.is_present("clear") {
|
|
||||||
clear_assets();
|
|
||||||
} else if cache_matches.is_present("config-dir") {
|
|
||||||
println!("{}", config_dir());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(true);
|
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
let config = app.config()?;
|
let config = app.config()?;
|
||||||
let assets = HighlightingAssets::new();
|
let assets = HighlightingAssets::new();
|
||||||
|
|
||||||
if app.matches.is_present("list-languages") {
|
if app.matches.is_present("list-languages") {
|
||||||
list_languages(&assets, config.term_width);
|
list_languages(&assets, &config)?;
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if app.matches.is_present("list-themes") {
|
Ok(true)
|
||||||
let themes = &assets.theme_set.themes;
|
} else if app.matches.is_present("list-themes") {
|
||||||
for (theme, _) in themes.iter() {
|
list_themes(&assets, &config)?;
|
||||||
println!("{}", theme);
|
|
||||||
}
|
|
||||||
return Ok(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
print_files(&assets, &config)
|
Ok(true)
|
||||||
|
} else {
|
||||||
|
let controller = Controller::new(&config, &assets);
|
||||||
|
controller.run()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-9
@@ -1,8 +1,10 @@
|
|||||||
use app::PagingMode;
|
use std::env;
|
||||||
use errors::*;
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::{Child, Command, Stdio};
|
||||||
|
|
||||||
|
use app::PagingMode;
|
||||||
|
use errors::*;
|
||||||
|
|
||||||
pub enum OutputType {
|
pub enum OutputType {
|
||||||
Pager(Child),
|
Pager(Child),
|
||||||
Stdout(io::Stdout),
|
Stdout(io::Stdout),
|
||||||
@@ -20,13 +22,24 @@ impl OutputType {
|
|||||||
|
|
||||||
/// Try to launch the pager. Fall back to stdout in case of errors.
|
/// Try to launch the pager. Fall back to stdout in case of errors.
|
||||||
fn try_pager(quit_if_one_screen: bool) -> Self {
|
fn try_pager(quit_if_one_screen: bool) -> Self {
|
||||||
let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
|
let pager = env::var("BAT_PAGER")
|
||||||
if quit_if_one_screen {
|
.or_else(|_| env::var("PAGER"))
|
||||||
args.push("--quit-if-one-screen");
|
.unwrap_or(String::from("less"));
|
||||||
}
|
|
||||||
Command::new("less")
|
let mut process = if pager == "less" {
|
||||||
.args(&args)
|
let mut args = vec!["--RAW-CONTROL-CHARS", "--no-init"];
|
||||||
.env("LESSCHARSET", "UTF-8")
|
if quit_if_one_screen {
|
||||||
|
args.push("--quit-if-one-screen");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut p = Command::new("less");
|
||||||
|
p.args(&args).env("LESSCHARSET", "UTF-8");
|
||||||
|
p
|
||||||
|
} else {
|
||||||
|
Command::new(pager)
|
||||||
|
};
|
||||||
|
|
||||||
|
process
|
||||||
.stdin(Stdio::piped())
|
.stdin(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.map(OutputType::Pager)
|
.map(OutputType::Pager)
|
||||||
|
|||||||
+168
-74
@@ -1,31 +1,83 @@
|
|||||||
use ansi_term::Colour::{Fixed, Green, Red, White, Yellow};
|
|
||||||
use ansi_term::Style;
|
|
||||||
use app::Config;
|
|
||||||
use console::AnsiCodeIterator;
|
|
||||||
use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration};
|
|
||||||
use diff::LineChanges;
|
|
||||||
use errors::*;
|
|
||||||
use std::boxed::Box;
|
use std::boxed::Box;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::vec::Vec;
|
use std::vec::Vec;
|
||||||
use style::OutputWrap;
|
|
||||||
use syntect::highlighting;
|
|
||||||
use terminal::as_terminal_escaped;
|
|
||||||
|
|
||||||
pub struct Printer<'a> {
|
use ansi_term::Colour::{Fixed, Green, Red, Yellow};
|
||||||
handle: &'a mut Write,
|
use ansi_term::Style;
|
||||||
|
|
||||||
|
use console::AnsiCodeIterator;
|
||||||
|
|
||||||
|
use syntect::easy::HighlightLines;
|
||||||
|
use syntect::highlighting::Theme;
|
||||||
|
|
||||||
|
use app::{Config, InputFile};
|
||||||
|
use assets::HighlightingAssets;
|
||||||
|
use decorations::{Decoration, GridBorderDecoration, LineChangesDecoration, LineNumberDecoration};
|
||||||
|
use diff::get_git_diff;
|
||||||
|
use diff::LineChanges;
|
||||||
|
use errors::*;
|
||||||
|
use style::OutputWrap;
|
||||||
|
use terminal::{as_terminal_escaped, to_ansi_color};
|
||||||
|
|
||||||
|
pub trait Printer {
|
||||||
|
fn print_header(&mut self, handle: &mut Write, file: InputFile) -> Result<()>;
|
||||||
|
fn print_footer(&mut self, handle: &mut Write) -> Result<()>;
|
||||||
|
fn print_line(
|
||||||
|
&mut self,
|
||||||
|
out_of_range: bool,
|
||||||
|
handle: &mut Write,
|
||||||
|
line_number: usize,
|
||||||
|
line_buffer: &[u8],
|
||||||
|
) -> Result<()>;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct SimplePrinter;
|
||||||
|
|
||||||
|
impl SimplePrinter {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
SimplePrinter {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Printer for SimplePrinter {
|
||||||
|
fn print_header(&mut self, _handle: &mut Write, _file: InputFile) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_footer(&mut self, _handle: &mut Write) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn print_line(
|
||||||
|
&mut self,
|
||||||
|
out_of_range: bool,
|
||||||
|
handle: &mut Write,
|
||||||
|
_line_number: usize,
|
||||||
|
line_buffer: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
if !out_of_range {
|
||||||
|
handle.write(line_buffer)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct InteractivePrinter<'a> {
|
||||||
colors: Colors,
|
colors: Colors,
|
||||||
config: &'a Config<'a>,
|
config: &'a Config<'a>,
|
||||||
decorations: Vec<Box<Decoration>>,
|
decorations: Vec<Box<Decoration>>,
|
||||||
panel_width: usize,
|
panel_width: usize,
|
||||||
line_number: usize,
|
ansi_prefix_sgr: String,
|
||||||
pub line_changes: Option<LineChanges>,
|
pub line_changes: Option<LineChanges>,
|
||||||
|
highlighter: HighlightLines<'a>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Printer<'a> {
|
impl<'a> InteractivePrinter<'a> {
|
||||||
pub fn new(handle: &'a mut Write, config: &'a Config) -> Self {
|
pub fn new(config: &'a Config, assets: &'a HighlightingAssets, file: InputFile) -> Self {
|
||||||
|
let theme = assets.get_theme(&config.theme);
|
||||||
|
|
||||||
let colors = if config.colored_output {
|
let colors = if config.colored_output {
|
||||||
Colors::colored()
|
Colors::colored(theme, config.true_color)
|
||||||
} else {
|
} else {
|
||||||
Colors::plain()
|
Colors::plain()
|
||||||
};
|
};
|
||||||
@@ -60,30 +112,55 @@ impl<'a> Printer<'a> {
|
|||||||
panel_width = 0;
|
panel_width = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create printer.
|
// Get the Git modifications
|
||||||
Printer {
|
let line_changes = match file {
|
||||||
|
InputFile::Ordinary(filename) => get_git_diff(filename),
|
||||||
|
_ => None,
|
||||||
|
};
|
||||||
|
|
||||||
|
// Determine the type of syntax for highlighting
|
||||||
|
let syntax = assets.get_syntax(config.language, file);
|
||||||
|
let highlighter = HighlightLines::new(syntax, theme);
|
||||||
|
|
||||||
|
InteractivePrinter {
|
||||||
panel_width,
|
panel_width,
|
||||||
handle,
|
|
||||||
colors,
|
colors,
|
||||||
config,
|
config,
|
||||||
decorations,
|
decorations,
|
||||||
line_number: 0,
|
ansi_prefix_sgr: String::new(),
|
||||||
line_changes: None,
|
line_changes,
|
||||||
|
highlighter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_header(&mut self, filename: Option<&str>) -> Result<()> {
|
fn print_horizontal_line(&mut self, handle: &mut Write, grid_char: char) -> Result<()> {
|
||||||
self.line_number = 0;
|
if self.panel_width == 0 {
|
||||||
|
writeln!(
|
||||||
|
handle,
|
||||||
|
"{}",
|
||||||
|
self.colors.grid.paint("─".repeat(self.config.term_width))
|
||||||
|
)?;
|
||||||
|
} else {
|
||||||
|
let hline = "─".repeat(self.config.term_width - (self.panel_width + 1));
|
||||||
|
let hline = format!("{}{}{}", "─".repeat(self.panel_width), grid_char, hline);
|
||||||
|
writeln!(handle, "{}", self.colors.grid.paint(hline))?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> Printer for InteractivePrinter<'a> {
|
||||||
|
fn print_header(&mut self, handle: &mut Write, file: InputFile) -> Result<()> {
|
||||||
if !self.config.output_components.header() {
|
if !self.config.output_components.header() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.config.output_components.grid() {
|
if self.config.output_components.grid() {
|
||||||
self.print_horizontal_line('┬')?;
|
self.print_horizontal_line(handle, '┬')?;
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
self.handle,
|
handle,
|
||||||
"{}{}",
|
"{}{}",
|
||||||
" ".repeat(self.panel_width),
|
" ".repeat(self.panel_width),
|
||||||
self.colors
|
self.colors
|
||||||
@@ -91,33 +168,45 @@ impl<'a> Printer<'a> {
|
|||||||
.paint(if self.panel_width > 0 { "│ " } else { "" }),
|
.paint(if self.panel_width > 0 { "│ " } else { "" }),
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
write!(self.handle, "{}", " ".repeat(self.panel_width))?;
|
write!(handle, "{}", " ".repeat(self.panel_width))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
writeln!(
|
let (prefix, name) = match file {
|
||||||
self.handle,
|
InputFile::Ordinary(filename) => ("File: ", filename),
|
||||||
"{}{}",
|
_ => ("", "STDIN"),
|
||||||
filename.map_or("", |_| "File: "),
|
};
|
||||||
self.colors.filename.paint(filename.unwrap_or("STDIN"))
|
|
||||||
)?;
|
writeln!(handle, "{}{}", prefix, self.colors.filename.paint(name))?;
|
||||||
|
|
||||||
if self.config.output_components.grid() {
|
if self.config.output_components.grid() {
|
||||||
self.print_horizontal_line('┼')?;
|
self.print_horizontal_line(handle, '┼')?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_footer(&mut self) -> Result<()> {
|
fn print_footer(&mut self, handle: &mut Write) -> Result<()> {
|
||||||
if self.config.output_components.grid() {
|
if self.config.output_components.grid() {
|
||||||
self.print_horizontal_line('┴')
|
self.print_horizontal_line(handle, '┴')
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_line(&mut self, regions: &[(highlighting::Style, &str)]) -> Result<()> {
|
fn print_line(
|
||||||
self.line_number += 1;
|
&mut self,
|
||||||
|
out_of_range: bool,
|
||||||
|
handle: &mut Write,
|
||||||
|
line_number: usize,
|
||||||
|
line_buffer: &[u8],
|
||||||
|
) -> Result<()> {
|
||||||
|
let line = String::from_utf8_lossy(&line_buffer);
|
||||||
|
let regions = self.highlighter.highlight(line.as_ref());
|
||||||
|
|
||||||
|
if out_of_range {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let mut cursor: usize = 0;
|
let mut cursor: usize = 0;
|
||||||
let mut cursor_max: usize = self.config.term_width;
|
let mut cursor_max: usize = self.config.term_width;
|
||||||
let mut panel_wrap: Option<String> = None;
|
let mut panel_wrap: Option<String> = None;
|
||||||
@@ -127,11 +216,11 @@ impl<'a> Printer<'a> {
|
|||||||
let decorations = self
|
let decorations = self
|
||||||
.decorations
|
.decorations
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ref d| d.generate(self.line_number, false, self))
|
.map(|ref d| d.generate(line_number, false, self))
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
for deco in decorations {
|
for deco in decorations {
|
||||||
write!(self.handle, "{} ", deco.text)?;
|
write!(handle, "{} ", deco.text)?;
|
||||||
cursor_max -= deco.width + 1;
|
cursor_max -= deco.width + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +231,7 @@ impl<'a> Printer<'a> {
|
|||||||
let colored_output = self.config.colored_output;
|
let colored_output = self.config.colored_output;
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
self.handle,
|
handle,
|
||||||
"{}",
|
"{}",
|
||||||
regions
|
regions
|
||||||
.iter()
|
.iter()
|
||||||
@@ -151,19 +240,27 @@ impl<'a> Printer<'a> {
|
|||||||
text,
|
text,
|
||||||
true_color,
|
true_color,
|
||||||
colored_output,
|
colored_output,
|
||||||
))
|
)).collect::<Vec<_>>()
|
||||||
.collect::<Vec<_>>()
|
|
||||||
.join("")
|
.join("")
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
for &(style, region) in regions.iter() {
|
for &(style, region) in regions.iter() {
|
||||||
let mut ansi_iterator = AnsiCodeIterator::new(region);
|
let mut ansi_iterator = AnsiCodeIterator::new(region);
|
||||||
let mut ansi_prefix = "";
|
let mut ansi_prefix: String = String::new();
|
||||||
for chunk in ansi_iterator {
|
for chunk in ansi_iterator {
|
||||||
match chunk {
|
match chunk {
|
||||||
// ANSI escape passthrough.
|
// ANSI escape passthrough.
|
||||||
(text, true) => {
|
(text, true) => {
|
||||||
ansi_prefix = text;
|
if text.chars().last().map_or(false, |c| c == 'm') {
|
||||||
|
ansi_prefix.push_str(text);
|
||||||
|
if text == "\x1B[0m" {
|
||||||
|
self.ansi_prefix_sgr = "\x1B[0m".to_owned();
|
||||||
|
} else {
|
||||||
|
self.ansi_prefix_sgr.push_str(text);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ansi_prefix.push_str(text);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Regular text.
|
// Regular text.
|
||||||
@@ -181,11 +278,14 @@ impl<'a> Printer<'a> {
|
|||||||
cursor += remaining;
|
cursor += remaining;
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
self.handle,
|
handle,
|
||||||
"{}",
|
"{}",
|
||||||
as_terminal_escaped(
|
as_terminal_escaped(
|
||||||
style,
|
style,
|
||||||
&*format!("{}{}", ansi_prefix, text),
|
&*format!(
|
||||||
|
"{}{}{}",
|
||||||
|
self.ansi_prefix_sgr, ansi_prefix, text
|
||||||
|
),
|
||||||
self.config.true_color,
|
self.config.true_color,
|
||||||
self.config.colored_output,
|
self.config.colored_output,
|
||||||
)
|
)
|
||||||
@@ -201,9 +301,8 @@ impl<'a> Printer<'a> {
|
|||||||
self.decorations
|
self.decorations
|
||||||
.iter()
|
.iter()
|
||||||
.map(|ref d| d
|
.map(|ref d| d
|
||||||
.generate(self.line_number, true, self)
|
.generate(line_number, true, self)
|
||||||
.text)
|
.text).collect::<Vec<String>>()
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(" ")
|
.join(" ")
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
@@ -217,47 +316,36 @@ impl<'a> Printer<'a> {
|
|||||||
remaining -= available;
|
remaining -= available;
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
self.handle,
|
handle,
|
||||||
"{}\n{}",
|
"{}\n{}",
|
||||||
as_terminal_escaped(
|
as_terminal_escaped(
|
||||||
style,
|
style,
|
||||||
&*format!("{}{}", ansi_prefix, text),
|
&*format!(
|
||||||
|
"{}{}{}",
|
||||||
|
self.ansi_prefix_sgr, ansi_prefix, text
|
||||||
|
),
|
||||||
self.config.true_color,
|
self.config.true_color,
|
||||||
self.config.colored_output,
|
self.config.colored_output,
|
||||||
),
|
),
|
||||||
panel_wrap.clone().unwrap()
|
panel_wrap.clone().unwrap()
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clear the ANSI prefix buffer.
|
||||||
|
ansi_prefix.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
write!(self.handle, "\n")?;
|
write!(handle, "\n")?;
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn print_horizontal_line(&mut self, grid_char: char) -> Result<()> {
|
|
||||||
if self.panel_width == 0 {
|
|
||||||
writeln!(
|
|
||||||
self.handle,
|
|
||||||
"{}",
|
|
||||||
self.colors.grid.paint("─".repeat(self.config.term_width))
|
|
||||||
)?;
|
|
||||||
} else {
|
|
||||||
let hline = "─".repeat(self.config.term_width - (self.panel_width + 1));
|
|
||||||
let hline = format!("{}{}{}", "─".repeat(self.panel_width), grid_char, hline);
|
|
||||||
writeln!(self.handle, "{}", self.colors.grid.paint(hline))?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const GRID_COLOR: u8 = 238;
|
const DEFAULT_GUTTER_COLOR: u8 = 238;
|
||||||
const LINE_NUMBER_COLOR: u8 = 244;
|
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Colors {
|
pub struct Colors {
|
||||||
@@ -274,14 +362,20 @@ impl Colors {
|
|||||||
Colors::default()
|
Colors::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn colored() -> Self {
|
fn colored(theme: &Theme, true_color: bool) -> Self {
|
||||||
|
let gutter_color = theme
|
||||||
|
.settings
|
||||||
|
.gutter_foreground
|
||||||
|
.map(|c| to_ansi_color(c, true_color))
|
||||||
|
.unwrap_or(Fixed(DEFAULT_GUTTER_COLOR));
|
||||||
|
|
||||||
Colors {
|
Colors {
|
||||||
grid: Fixed(GRID_COLOR).normal(),
|
grid: gutter_color.normal(),
|
||||||
filename: White.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: Fixed(LINE_NUMBER_COLOR).normal(),
|
line_number: gutter_color.normal(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -1,7 +1,8 @@
|
|||||||
use errors::*;
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use errors::*;
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
||||||
pub enum OutputComponent {
|
pub enum OutputComponent {
|
||||||
Auto,
|
Auto,
|
||||||
@@ -58,6 +59,7 @@ impl FromStr for OutputComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct OutputComponents(pub HashSet<OutputComponent>);
|
pub struct OutputComponents(pub HashSet<OutputComponent>);
|
||||||
|
|
||||||
impl OutputComponents {
|
impl OutputComponents {
|
||||||
|
|||||||
+14
-13
@@ -1,5 +1,6 @@
|
|||||||
use ansi_term::Colour::{Fixed, RGB};
|
use ansi_term::Colour::{Fixed, RGB};
|
||||||
use ansi_term::Style;
|
use ansi_term::{self, Style};
|
||||||
|
|
||||||
use syntect::highlighting::{self, FontStyle};
|
use syntect::highlighting::{self, FontStyle};
|
||||||
|
|
||||||
/// Approximate a 24 bit color value by a 8 bit ANSI code
|
/// Approximate a 24 bit color value by a 8 bit ANSI code
|
||||||
@@ -13,14 +14,19 @@ fn rgb2ansi(r: u8, g: u8, b: u8) -> u8 {
|
|||||||
} else if r > 248 {
|
} else if r > 248 {
|
||||||
WHITE
|
WHITE
|
||||||
} else {
|
} else {
|
||||||
let fr = f32::from(r);
|
((r - 8) as u16 * 24 / 247) as u8 + 232
|
||||||
(((fr - 8.) / 247.) * 24.) as u8 + 232
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let fr = f32::from(r);
|
36 * (r / 51) + 6 * (g / 51) + (b / 51) + 16
|
||||||
let fg = f32::from(g);
|
}
|
||||||
let fb = f32::from(b);
|
}
|
||||||
16 + (36 * (fr / 255. * 5.) as u8) + (6 * (fg / 255. * 5.) as u8) + (fb / 255. * 5.) as u8
|
|
||||||
|
pub fn to_ansi_color(color: highlighting::Color, true_color: bool) -> ansi_term::Colour {
|
||||||
|
if true_color {
|
||||||
|
RGB(color.r, color.g, color.b)
|
||||||
|
} else {
|
||||||
|
let ansi_code = rgb2ansi(color.r, color.g, color.b);
|
||||||
|
Fixed(ansi_code)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,12 +39,7 @@ pub fn as_terminal_escaped(
|
|||||||
let style = if !colored {
|
let style = if !colored {
|
||||||
Style::default()
|
Style::default()
|
||||||
} else {
|
} else {
|
||||||
let color = if true_color {
|
let color = to_ansi_color(style.foreground, true_color);
|
||||||
RGB(style.foreground.r, style.foreground.g, style.foreground.b)
|
|
||||||
} else {
|
|
||||||
let ansi = rgb2ansi(style.foreground.r, style.foreground.g, style.foreground.b);
|
|
||||||
Fixed(ansi)
|
|
||||||
};
|
|
||||||
|
|
||||||
if style.font_style.contains(FontStyle::BOLD) {
|
if style.font_style.contains(FontStyle::BOLD) {
|
||||||
color.bold()
|
color.bold()
|
||||||
|
|||||||
+53
-27
@@ -1,17 +1,29 @@
|
|||||||
use std::env;
|
use std::env;
|
||||||
use std::fs::{self, File};
|
use std::fs::{self, File};
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
|
extern crate tempdir;
|
||||||
|
use self::tempdir::TempDir;
|
||||||
|
|
||||||
|
extern crate git2;
|
||||||
|
use self::git2::build::CheckoutBuilder;
|
||||||
|
use self::git2::Repository;
|
||||||
|
use self::git2::Signature;
|
||||||
|
|
||||||
pub struct BatTester {
|
pub struct BatTester {
|
||||||
|
/// Temporary working directory
|
||||||
|
temp_dir: TempDir,
|
||||||
|
|
||||||
|
/// Path to the *bat* executable
|
||||||
exe: PathBuf,
|
exe: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BatTester {
|
impl BatTester {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
modify_sample_file();
|
let temp_dir = create_sample_directory().expect("sample directory");
|
||||||
// Lifted from fd :)
|
|
||||||
let root = env::current_exe()
|
let root = env::current_exe()
|
||||||
.expect("tests executable")
|
.expect("tests executable")
|
||||||
.parent()
|
.parent()
|
||||||
@@ -21,17 +33,22 @@ impl BatTester {
|
|||||||
.to_path_buf();
|
.to_path_buf();
|
||||||
|
|
||||||
let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" };
|
let exe_name = if cfg!(windows) { "bat.exe" } else { "bat" };
|
||||||
|
let exe = root.join(exe_name);
|
||||||
|
|
||||||
BatTester {
|
BatTester { temp_dir, exe }
|
||||||
exe: root.join(exe_name),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn test_snapshot(&self, style: &str) {
|
pub fn test_snapshot(&self, style: &str) {
|
||||||
let output = Command::new(&self.exe)
|
let output = Command::new(&self.exe)
|
||||||
.args(&["tests/snapshots/sample.rs", &format!("--style={}", style)])
|
.current_dir(self.temp_dir.path())
|
||||||
.output()
|
.args(&[
|
||||||
|
"sample.rs",
|
||||||
|
"--decorations=always",
|
||||||
|
"--terminal-width=80",
|
||||||
|
&format!("--style={}", style),
|
||||||
|
]).output()
|
||||||
.expect("bat failed");
|
.expect("bat failed");
|
||||||
|
|
||||||
// have to do the replace because the filename in the header changes based on the current working directory
|
// have to do the replace because the filename in the header changes based on the current working directory
|
||||||
let actual = String::from_utf8_lossy(&output.stdout)
|
let actual = String::from_utf8_lossy(&output.stdout)
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@@ -47,26 +64,35 @@ impl BatTester {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for BatTester {
|
fn create_sample_directory() -> Result<TempDir, git2::Error> {
|
||||||
fn drop(&mut self) {
|
// Create temp directory and initialize repository
|
||||||
undo_sample_file_modification();
|
let temp_dir = TempDir::new("bat-tests").expect("Temp directory");
|
||||||
}
|
let repo = Repository::init(&temp_dir)?;
|
||||||
}
|
|
||||||
|
|
||||||
fn modify_sample_file() {
|
// Copy over `sample.rs`
|
||||||
fs::copy(
|
let sample_path = temp_dir.path().join("sample.rs");
|
||||||
"tests/snapshots/sample.modified.rs",
|
println!("{:?}", &sample_path);
|
||||||
"tests/snapshots/sample.rs",
|
fs::copy("tests/snapshots/sample.rs", &sample_path).expect("successful copy");
|
||||||
).expect("generating modified sample file failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn undo_sample_file_modification() {
|
// Commit
|
||||||
let output = Command::new("git")
|
let mut index = repo.index()?;
|
||||||
.args(&["checkout", "--", "tests/snapshots/sample.rs"])
|
index.add_path(Path::new("sample.rs"))?;
|
||||||
.output()
|
|
||||||
.expect("git checkout failed");
|
|
||||||
|
|
||||||
if !output.status.success() {
|
let oid = index.write_tree()?;
|
||||||
panic!("undoing modified sample changes failed")
|
let signature = Signature::now("bat test runner", "bat@test.runner")?;
|
||||||
}
|
let tree = repo.find_tree(oid)?;
|
||||||
|
let _ = repo.commit(
|
||||||
|
Some("HEAD"), // point HEAD to our new commit
|
||||||
|
&signature, // author
|
||||||
|
&signature, // committer
|
||||||
|
"initial commit",
|
||||||
|
&tree,
|
||||||
|
&[],
|
||||||
|
);
|
||||||
|
let mut opts = CheckoutBuilder::new();
|
||||||
|
repo.checkout_head(Some(opts.force()))?;
|
||||||
|
|
||||||
|
fs::copy("tests/snapshots/sample.modified.rs", &sample_path).expect("successful copy");
|
||||||
|
|
||||||
|
Ok(temp_dir)
|
||||||
}
|
}
|
||||||
|
|||||||
+30
-28
@@ -2,32 +2,34 @@ mod tester;
|
|||||||
|
|
||||||
use tester::BatTester;
|
use tester::BatTester;
|
||||||
|
|
||||||
static STYLES: &'static [&'static str] = &[
|
macro_rules! snapshot_tests {
|
||||||
"changes",
|
($($test_name: ident: $style: expr,)*) => {
|
||||||
"grid",
|
$(
|
||||||
"header",
|
#[test]
|
||||||
"numbers",
|
fn $test_name() {
|
||||||
"changes,grid",
|
let bat_tester = BatTester::new();
|
||||||
"changes,header",
|
bat_tester.test_snapshot($style);
|
||||||
"changes,numbers",
|
}
|
||||||
"grid,header",
|
)*
|
||||||
"grid,numbers",
|
};
|
||||||
"header,numbers",
|
}
|
||||||
"changes,grid,header",
|
|
||||||
"changes,grid,numbers",
|
snapshot_tests! {
|
||||||
"changes,header,numbers",
|
changes: "changes",
|
||||||
"grid,header,numbers",
|
grid: "grid",
|
||||||
"changes,grid,header,numbers",
|
header: "header",
|
||||||
"full",
|
numbers: "numbers",
|
||||||
"plain",
|
changes_grid: "changes,grid",
|
||||||
];
|
changes_header: "changes,header",
|
||||||
|
changes_numbers: "changes,numbers",
|
||||||
#[test]
|
grid_header: "grid,header",
|
||||||
fn test_snapshots() {
|
grid_numbers: "grid,numbers",
|
||||||
let bat_tester = BatTester::new();
|
header_numbers: "header,numbers",
|
||||||
|
changes_grid_header: "changes,grid,header",
|
||||||
for style in STYLES {
|
changes_grid_numbers: "changes,grid,numbers",
|
||||||
println!("testing {}", style);
|
changes_header_numbers: "changes,header,numbers",
|
||||||
bat_tester.test_snapshot(&*style);
|
grid_header_numbers: "grid,header,numbers",
|
||||||
}
|
changes_grid_header_numbers: "changes,grid,header,numbers",
|
||||||
|
full: "full",
|
||||||
|
plain: "plain",
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user