Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp authored Oct 30, 2020
2 parents 9daea73 + 8e81315 commit 3a612f0
Show file tree
Hide file tree
Showing 51 changed files with 2,085 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ jobs:
with:
command: test
args: --release
- name: Run ignored-by-default unit tests with new syntaxes and themes
uses: actions-rs/cargo@v1
with:
command: test
args: --release -- --ignored
- name: Syntax highlighting regression test
run: tests/syntax-tests/regression_test.sh
- name: List of languages
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -200,3 +200,9 @@
[submodule "assets/syntaxes/02_Extra/Ninja"]
path = assets/syntaxes/02_Extra/Ninja
url = https://github.com/pope/SublimeNinja.git
[submodule "assets/syntaxes/02_Extra/Svelte"]
path = assets/syntaxes/02_Extra/Svelte
url = https://github.com/corneliusio/svelte-sublime
[submodule "assets/themes/Coldark"]
path = assets/themes/Coldark
url = https://github.com/ArmandPhilippot/coldark-bat.git
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# unreleased

- Add Note to refer to see detailed help with --help (and vice versa with -h). see #1215 (@henil)

## Features

- Adjust pager configuration to comply with `--wrap=never`, see #1255 (@gahag)

## Bugfixes

- Throws an error when `bat` is being used as `pager`, see #1343 (@adrian-rivera)

## Other

- Add note to refer to see detailed help with `--help` (and vice versa with `-h`), see #1215 (@henil)
- Add a `Contributors` section to `README`, see #1348 (@adrian-rivera)

## Syntaxes

- Manpage syntax highlighting has been improved, see #1315 (@keith-hall)
- Add Svelte file syntax, see #1285 (@kjmph)

## New themes

- Coldark, see #1329 (@armandphilippot)

## `bat` as a library

## Packaging
Expand Down
48 changes: 48 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Contributing

Thank you for considering to contribute to `bat`!



## Add an entry to the changelog

If your contribution changes the behavior of `bat` (as opposed to a typo-fix
in the documentation), please update the [`CHANGELOG.md`](CHANGELOG.md) file
and describe your changes. This makes the release proess much easier and
therefore helps to get your changes into a new `bat` release faster.

The top of the `CHANGELOG` contains a *"unreleased"* section with a few
subsections (Features, Bugfixes, …). Please add your entry to the subsection
that best describes your change

Entries follow this format:
```
- Short description of what has been changed, see #123 (@user)
```
Here, `#123` is the number of the original issue and/or your pull request.
Please replace `@user` by your GitHub username.


## Development

Please check out the [Development](https://github.com/sharkdp/bat#development)
section in the README.


## Adding a new feature

Please consider opening a
[feature request ticket](https://github.com/sharkdp/bat/issues/new?assignees=&labels=feature-request&template=feature_request.md)
first in order to give us a chance to discuss the feature first.


## Adding new syntaxes/languages or themes

Before you make a pull request that adds a new syntax or theme, please read
the [Customization](https://github.com/sharkdp/bat#customization) section
in the README first.

If you really think that a particular syntax or theme should be added for all
users, please read the corresponding
[documentation](https://github.com/sharkdp/bat/blob/master/doc/assets.md)
first.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,18 @@ highlighting:
git show v0.6.0:src/main.rs | bat -l rs
```

Note that syntax highlighting within diffs is currently not supported. If you are looking for this, check out [`delta`](https://github.com/dandavison/delta).
#### `git diff`

You can combine `bat` with `git diff` to view lines around code changes with proper syntax
highlighting:
```bash
batdiff() {
git diff --name-only --diff-filter=d | xargs bat --diff
}
```
If you prefer to use this as a separate tool, check out `batdiff` in [`bat-extras`](https://github.com/eth-p/bat-extras).

If you are looking for more support for git and diff operations, check out [`delta`](https://github.com/dandavison/delta).

#### `xclip`

Expand Down Expand Up @@ -665,6 +676,10 @@ bash assets/create.sh
cargo install --path . --locked --force
```

## Contributing

Take a look at the [`CONTRIBUTING.md`](CONTRIBUTING.md) guide.

## Maintainers

- [sharkdp](https://github.com/sharkdp)
Expand Down
22 changes: 16 additions & 6 deletions assets/syntaxes/02_Extra/Manpage.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ contexts:
scope: markup.heading.title.man
- match: \s\s
pop: true
- match: '(?=\S)'
- match: '(?=\S|$)'
pop: true

- match: '$'
push: body
set: body

body:
# English, ..., ..., ..., Russian, ...
Expand All @@ -48,14 +48,16 @@ contexts:
embed: synopsis
escape: '(?={{section_heading}})'

- match: '^(?:USAGE)'
scope: markup.heading.synopsis.man
embed: synopsis
escape: '(?={{section_heading}})'

- match: '{{section_heading}}'
scope: markup.heading.other.man
embed: options # some man pages put command line options under the description heading
escape: '(?={{section_heading}})'

- include: function-call

function-call:
- match: '\b([A-Za-z0-9_\-]+)(\()([^)]*)(\))'
captures:
Expand Down Expand Up @@ -83,6 +85,7 @@ contexts:
- match: ''
pop: true
- include: function-call
- include: c-code

expect-command-line-option:
- match: '[A-Za-z0-9-]+'
Expand Down Expand Up @@ -127,9 +130,15 @@ contexts:
- match: '$|(?=[],]|{{command_line_option}})'
pop: true

c-code:
- match: '^(?=\s+(?:#include\b|#define\b|/\*|struct\s+(\w+\s*)?\{))'
embed: scope:source.c
#embed_scope: source.c.embedded.man
#escape: ^(?!#|\1|\s*(?:$|/\*|#include\b|#define\b))
escape: ^(?=\s*(?:\(.*\.\)\s*$|[A-Z](?![A-Z])))

synopsis:
- match: '^(?=\s+(?:#include|/\*))'
push: scope:source.c
- include: c-code
- match: \[
scope: punctuation.section.brackets.begin.man
push: command-line-option-or-pipe
Expand All @@ -140,6 +149,7 @@ contexts:
captures:
1: keyword.operator.logical.man
#- match: (?={{command_line_option}})
- match: \w+-\w+
- match: (?=-)
push:
- match: (?=\s*\|)
Expand Down
1 change: 1 addition & 0 deletions assets/syntaxes/02_Extra/Svelte
Submodule Svelte added at bf92f5
32 changes: 29 additions & 3 deletions assets/syntaxes/02_Extra/syntax_test_man.man
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SOMETHING(8) System Manager's Manual SOMETHING(8)
# ^^^^^^^ meta.preprocessor

NAME
#^^^ markup.heading.title
#^^^ markup.heading.other
example - do something useful

SYNOPSIS
Expand Down Expand Up @@ -45,9 +45,16 @@ SYNOPSIS
[--quiet] [--debug] [--help|-h] [--version] [--conf FILE]

/* According to POSIX.1-2001, POSIX.1-2008 */
# ^^ source comment.block punctuation.definition.comment
# ^^ source.c comment.block punctuation.definition.comment
#include <sys/select.h>
# ^^^^^^^^ source meta.preprocessor.include keyword.control.import.include
# ^^^^^^^^ source.c meta.preprocessor.include keyword.control.import.include
struct timeval {
# ^^^^^^ source.c storage.type

time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};



DESCRIPTION
Expand Down Expand Up @@ -123,3 +130,22 @@ OPTIONS
# ^^^ variable.parameter
# ^^ - variable
output NUM (default 3) lines of copied context

EXAMPLE
#include <stdio.h>
# ^^^^^^^^ source.c meta.preprocessor.include keyword.control.import.include

(This is not C code.)
# ^^^^^^^^^^^^^^^^^^^^^^ - source.c

struct timeval {
time_t tv_sec; /* seconds */
suseconds_t tv_usec; /* microseconds */
};
# ^ source.c punctuation.terminator

The corresponding argument for pselect() has the following type:
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - source.c
#define POLLIN_SET (EPOLLRDNORM | EPOLLRDBAND | EPOLLIN |
EPOLLHUP | EPOLLERR)
# ^ source.c meta.preprocessor.macro meta.group punctuation.section.group.end
Binary file modified assets/themes.bin
Binary file not shown.
1 change: 1 addition & 0 deletions assets/themes/Coldark
Submodule Coldark added at b4a1c7
8 changes: 8 additions & 0 deletions src/bin/bat/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ pub fn list_themes(cfg: &Config) -> Result<()> {
writeln!(stdout, "{}", theme)?;
}
}
writeln!(
stdout,
"Further themes can be installed to '{}', \
and are added to the cache with `bat cache --build`. \
For more information, see:\n\n \
https://github.com/sharkdp/bat#adding-new-themes",
config_file().join("themes").to_string_lossy()
)?;

Ok(())
}
Expand Down
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ error_chain! {
description("unknown syntax"),
display("unknown syntax: '{}'", name)
}
InvalidPagerValueBat {
description("invalid value `bat` for pager property"),
display("Use of bat as a pager is disallowed in order to avoid infinite recursion problems")
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ impl OutputType {

match pagerflags.split_first() {
Some((pager_name, args)) => {
let mut pager_path = PathBuf::from(pager_name);
let pager_path = PathBuf::from(pager_name);

if pager_path.file_stem() == Some(&OsString::from("bat")) {
pager_path = PathBuf::from("less");
return Err(ErrorKind::InvalidPagerValueBat.into());
}

let is_less = pager_path.file_stem() == Some(&OsString::from("less"));
Expand Down
4 changes: 4 additions & 0 deletions tests/assets.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use bat::assets::HighlightingAssets;

/// This test ensures that we are not accidentally removing themes due to submodule updates.
/// It is 'ignore'd by default because it requires themes.bin to be up-to-date.
#[test]
#[ignore]
fn all_themes_are_present() {
let assets = HighlightingAssets::from_binary();

Expand All @@ -12,6 +14,8 @@ fn all_themes_are_present() {
themes,
vec![
"1337",
"Coldark-Cold",
"Coldark-Dark",
"DarkNeon",
"Dracula",
"GitHub",
Expand Down
10 changes: 10 additions & 0 deletions tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ fn pager_disable() {
.stdout(predicate::eq("hello world\n").normalize());
}

#[test]
fn pager_value_bat() {
bat()
.arg("--pager=bat")
.arg("--paging=always")
.arg("test.txt")
.assert()
.failure();
}

#[test]
fn alias_pager_disable() {
bat()
Expand Down
44 changes: 44 additions & 0 deletions tests/syntax-tests/highlighted/D/test.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// selective import
import std.stdio : writeln, writefln;
// non-selective import
import std.algorithm;

/* a multiline comment
*
* this function is safe because it doesn't use pointer arithmetic
*/
int the_ultimate_answer() @safe {
 // assert1on
 assert(1 != 2);
 // now we can safely return our answer 
 return 42;
}

void main()
{
 // function call with string literal
 writeln("Hello World!");

 // an int array declaration
 int[] arr1 = [1, 2, 3];
 // an immutable double
 immutable double pi = 3.14;
 // a mutable double
 double d1 = pi;
 // a pointer
 double* dp1 = &d1;
 // another pointer to the same thingy
 auto a1 = &d1;
 // a constant bool
 const bool b1 = true;
 if (b1) {
 // another function call 
 writefln("%s\n%s\n%s\n", arr1, d1, the_ultimate_answer());
 }
 else if (!b1) {
 writeln("this seems wrong");
 }
 else {
 writeln("I'm giving up, this is too crazy for me");
 }
}
Loading

0 comments on commit 3a612f0

Please sign in to comment.