Compare commits

...

8 Commits

Author SHA1 Message Date
laalsaas 068314c03f
Merge 16bec17e5c into bb4d1cbd2e 2024-04-26 10:27:16 +08:00
Stéphane Blondon bb4d1cbd2e refactor: factorize constants by inverting loop and condition order 2024-04-19 11:44:47 +02:00
Stéphane Blondon 23ec433167 display which theme is the default one in basic output 2024-04-19 11:44:47 +02:00
Sharun 9eaed3e3f0
[JavaScript] Support bun in shebang for syntax highlighting (#2913)
* [JavaScript] Support bun in shebang for syntax highlighting

---------

Co-authored-by: Keith Hall <keith-hall@users.noreply.github.com>
2024-04-15 06:17:41 +00:00
sblondon d5bd4aa93f
display which theme is the default one in colored output (#2838) 2024-04-14 15:54:52 +02:00
laalsaas 16bec17e5c Mention SumblimeSuntaxConvertor in assets-doc 2024-03-04 15:21:22 +01:00
laalsaas edb2342c24 Add Prolog Syntax Highlighting 2024-03-04 15:20:57 +01:00
laalsaas e7a1d14c76 Acknowledgements: add support for MPL 2024-03-04 15:19:44 +01:00
11 changed files with 285 additions and 9 deletions

3
.gitmodules vendored
View File

@ -260,3 +260,6 @@
[submodule "assets/syntaxes/02_Extra/vscode-wgsl"]
path = assets/syntaxes/02_Extra/vscode-wgsl
url = https://github.com/PolyMeilex/vscode-wgsl.git
[submodule "assets/syntaxes/02_Extra/Prolog"]
path = assets/syntaxes/02_Extra/Prolog
url = https://github.com/alnkpa/sublimeprolog

View File

@ -6,6 +6,7 @@
- `bat --squeeze-blank`/`bat -s` will now squeeze consecutive empty lines, see #1441 (@eth-p) and #2665 (@einfachIrgendwer0815)
- `bat --squeeze-limit` to set the maximum number of empty consecutive when using `--squeeze-blank`, see #1441 (@eth-p) and #2665 (@einfachIrgendwer0815)
- `PrettyPrinter::squeeze_empty_lines` to support line squeezing for bat as a library, see #1441 (@eth-p) and #2665 (@einfachIrgendwer0815)
- Syntax highlighting for JavaScript files that start with `#!/usr/bin/env bun` #2913 (@sharunkumar)
## Bugfixes
@ -33,6 +34,8 @@
- Relax syntax mapping rule restrictions to allow brace expansion #2865 (@cyqsimon)
- Apply clippy fixes #2864 (@cyqsimon)
- Faster startup by offloading glob matcher building to a worker thread #2868 (@cyqsimon)
- Display which theme is the default one in basic output (no colors), see #2937 (@sblondon)
- Display which theme is the default one in colored output, see #2838 (@sblondon)
## Syntaxes
@ -44,6 +47,7 @@
- Added auto detect syntax for `.jsonc` #2795 (@mxaddict)
- Added auto detect syntax for `.aws/{config,credentials}` #2795 (@mxaddict)
- Add syntax mapping for Wireguard config #2874 (@cyqsimon)
- Add Prolog syntax, see #2848 (@laalsaas)
## Themes

View File

@ -0,0 +1,14 @@
Submodule assets/syntaxes/01_Packages contains modified content
diff --git syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax
index 05a4fed6..78a7bf55 100644
--- syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax
+++ syntaxes/01_Packages/JavaScript/JavaScript.sublime-syntax
@@ -5,7 +5,7 @@ name: JavaScript
file_extensions:
- js
- htc
-first_line_match: ^#!\s*/.*\b(node|js)\b
+first_line_match: ^#!\s*/.*\b(node|bun|js)\b
scope: source.js
variables:
bin_digit: '[01_]'

1
assets/syntaxes/02_Extra/Prolog vendored Submodule

@ -0,0 +1 @@
Subproject commit 9e8e142e55557465511338d5b26ca585cb729310

View File

@ -0,0 +1,137 @@
%YAML 1.2
---
# http://www.sublimetext.com/docs/3/syntax.html
name: SWI-Prolog
comment: This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
file_extensions:
- pro
- prolog
- swiplrc
scope: source.prolog
contexts:
main:
- include: comments
- match: (?<=:-)\s*
push:
- meta_scope: meta.clause.body.prolog
- match: (\.)
captures:
1: keyword.control.clause.bodyend.prolog
pop: true
- include: comments
- include: builtin
- include: controlandkeywords
- include: atom
- include: variable
- include: constants
- match: .
scope: meta.clause.body.prolog
- match: '^\s*([a-z][a-zA-Z0-9_]*)(\(?)(?=.*:-.*)'
captures:
1: entity.name.function.clause.prolog
2: punctuation.definition.parameters.begin
push:
- meta_scope: meta.clause.head.prolog
- match: ((\)?))\s*(:-)
captures:
1: punctuation.definition.parameters.end
3: keyword.control.clause.bodybegin.prolog
pop: true
- include: atom
- include: variable
- include: constants
- match: '^\s*([a-z][a-zA-Z0-9_]*)(\(?)(?=.*-->.*)'
captures:
1: entity.name.function.dcg.prolog
2: punctuation.definition.parameters.begin
push:
- meta_scope: meta.dcg.head.prolog
- match: ((\)?))\s*(-->)
captures:
1: punctuation.definition.parameters.end
3: keyword.control.dcg.bodybegin.prolog
pop: true
- include: atom
- include: variable
- include: constants
- match: (?<=-->)\s*
push:
- meta_scope: meta.dcg.body.prolog
- match: (\.)
captures:
1: keyword.control.dcg.bodyend.prolog
pop: true
- include: comments
- include: controlandkeywords
- include: atom
- include: variable
- include: constants
- match: .
scope: meta.dcg.body.prolog
- match: '^\s*([a-zA-Z][a-zA-Z0-9_]*)(\(?)(?!.*(:-|-->).*)'
captures:
1: entity.name.function.fact.prolog
2: punctuation.definition.parameters.begin
push:
- meta_scope: meta.fact.prolog
- match: ((\)?))\s*(\.)(?!\d+)
captures:
1: punctuation.definition.parameters.end
3: keyword.control.fact.end.prolog
pop: true
- include: atom
- include: variable
- include: constants
atom:
- match: '(?<![a-zA-Z0-9_])[a-z][a-zA-Z0-9_]*(?!\s*\(|[a-zA-Z0-9_])'
scope: constant.other.atom.simple.prolog
- match: "'.*?'"
scope: constant.other.atom.quoted.prolog
- match: '\[\]'
scope: constant.other.atom.emptylist.prolog
builtin:
- match: \b(op|findall|write|nl|writeln|fail|use_module|module)\b
scope: keyword.other
comments:
- match: "%.*"
scope: comment.line.percent-sign.prolog
- match: /\*
captures:
0: punctuation.definition.comment.prolog
push:
- meta_scope: comment.block.prolog
- match: \*/
captures:
0: punctuation.definition.comment.prolog
pop: true
constants:
- match: '(?<![a-zA-Z]|/)(\d+|(\d+\.\d+))'
scope: constant.numeric.integer.prolog
- match: '".*?"'
scope: string.quoted.double.prolog
controlandkeywords:
- match: (->)
captures:
1: keyword.control.if.prolog
push:
- meta_scope: meta.if.prolog
- match: (;)
captures:
1: keyword.control.else.prolog
pop: true
- include: main
- include: builtin
- include: comments
- include: atom
- include: variable
- match: .
scope: meta.if.body.prolog
- match: "!"
scope: keyword.control.cut.prolog
- match: (\s(is)\s)|=:=|=?\\?=|\\\+|@?>|@?=?<|\+|\*|\-
scope: keyword.operator.prolog
variable:
- match: "(?<![a-zA-Z0-9_])[_A-Z][a-zA-Z0-9_]*"
scope: variable.parameter.uppercase.prolog
- match: (?<!\w)_
scope: variable.language.anonymous.prolog

View File

@ -15,7 +15,9 @@ in the `.sublime-syntax` format.
2. If the Sublime Text syntax is only available as a `.tmLanguage` file, open the file in
Sublime Text and convert it to a `.sublime-syntax` file via *Tools* -> *Developer* ->
*New Syntax from XXX.tmLanguage...*. Save the new file in the `assets/syntaxes` folder.
*New Syntax from XXX.tmLanguage...*. Alternatively, you can use the
[Sublime Syntax Convertor](https://github.com/aziz/SublimeSyntaxConvertor).
Save the new file in the `assets/syntaxes` folder.
If only `.tmLanguage.json` or `.tmLanguage.yml` file is available, use
[PackageDev](https://packagecontrol.io/packages/PackageDev) to convert it to `.tmLanguage.plist`
format and then rename the converted file to `.tmLanguage` file.

View File

@ -95,6 +95,9 @@ fn include_license_in_acknowledgments(license_text: &str) -> bool {
// Apache 2.0
"Apache License Version 2.0, January 2004 http://www.apache.org/licenses/",
"Licensed under the Apache License, Version 2.0 (the \"License\");",
// MPL
"Mozilla Public License, version 2.0",
];
license_contains_marker(license_text, &markers)

View File

@ -30,6 +30,7 @@ use directories::PROJECT_DIRS;
use globset::GlobMatcher;
use bat::{
assets::HighlightingAssets,
config::Config,
controller::Controller,
error::*,
@ -199,19 +200,31 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
let stdout = io::stdout();
let mut stdout = stdout.lock();
if config.colored_output {
for theme in assets.themes() {
let default_theme = HighlightingAssets::default_theme();
for theme in assets.themes() {
let default_theme_info = if default_theme == theme {
" (default)"
} else {
""
};
if config.colored_output {
writeln!(
stdout,
"Theme: {}\n",
Style::new().bold().paint(theme.to_string())
"Theme: {}{}\n",
Style::new().bold().paint(theme.to_string()),
default_theme_info
)?;
config.theme = theme.to_string();
Controller::new(&config, &assets)
.run(vec![theme_preview_file()], None)
.ok();
writeln!(stdout)?;
} else {
writeln!(stdout, "{theme}{default_theme_info}")?;
}
}
if config.colored_output {
writeln!(
stdout,
"Further themes can be installed to '{}', \
@ -220,10 +233,6 @@ pub fn list_themes(cfg: &Config, config_dir: &Path, cache_dir: &Path) -> Result<
https://github.com/sharkdp/bat#adding-new-themes",
config_dir.join("themes").to_string_lossy()
)?;
} else {
for theme in assets.themes() {
writeln!(stdout, "{theme}")?;
}
}
Ok(())

View File

@ -272,6 +272,41 @@ fn squeeze_limit_line_numbers() {
.stdout(" 1 line 1\n 2 \n 3 \n 4 \n 5 line 5\n 6 \n 7 \n 8 \n 9 \n 10 \n 20 line 20\n 21 line 21\n 22 \n 23 \n 24 line 24\n 25 \n 26 line 26\n 27 \n 28 \n 29 \n 30 line 30\n");
}
#[test]
fn list_themes_with_colors() {
#[cfg(target_os = "macos")]
let default_theme_chunk = "Monokai Extended Light\x1B[0m (default)";
#[cfg(not(target_os = "macos"))]
let default_theme_chunk = "Monokai Extended\x1B[0m (default)";
bat()
.arg("--color=always")
.arg("--list-themes")
.assert()
.success()
.stdout(predicate::str::contains("DarkNeon").normalize())
.stdout(predicate::str::contains(default_theme_chunk).normalize())
.stdout(predicate::str::contains("Output the square of a number.").normalize());
}
#[test]
fn list_themes_without_colors() {
#[cfg(target_os = "macos")]
let default_theme_chunk = "Monokai Extended Light (default)";
#[cfg(not(target_os = "macos"))]
let default_theme_chunk = "Monokai Extended (default)";
bat()
.arg("--color=never")
.arg("--list-themes")
.assert()
.success()
.stdout(predicate::str::contains("DarkNeon").normalize())
.stdout(predicate::str::contains(default_theme_chunk).normalize());
}
#[test]
#[cfg_attr(any(not(feature = "git"), target_os = "windows"), ignore)]
fn short_help() {

View File

@ -0,0 +1,34 @@
% A formulation of Einstein's Riddle (aka Zebra Puzzle) in Prolog (specifically, SWI-Prolog - see http://www.swi-prolog.org/) as appeared on Life International magazine 17/12/1962
% Source: https://en.wikipedia.org/wiki/Zebra_Puzzle
% Modelling the problem:
% - Each house is represented by the predicate house/5
% - The five houses are modelled as a(n) (ordered) list of house(Color, Nationality, Pet, Beverage, Cigaret) in the variable Houses
% - The predicate solve/2 for solving the riddle is of the form solve(WaterDrinker, ZebraOwner) where WaterDrinker is the nationality of the person who drinks water and ZebraOwner the nationality of the person owning a zebra as a pet
% Expected solution: if the problem is modelled correctly by this program then the only solution set should be:
% WaterDrinker = norwegian, ZebraOwner = japanese.
% adjacent/3 - A helper function for expressing the "directly next to" relation in a list
% adjacent(A, B, List) means that either A is directly left of B in List or A is directly right of B in List
adjacent(A, B, List) :- nextto(A, B, List); nextto(B, A, List).
% solve/2 - The main predicate for solving the puzzle
solve(WaterDrinker, ZebraOwner) :-
  length(Houses, 5),                                                          % 1. There are five houses.
  member(house(red, english, _, _, _), Houses),                               % 2. The Englishman lives in the red house.
  member(house(_, spanish, dog, _, _), Houses),                               % 3. The Spaniard owns the dog.
  member(house(green, _, _, coffee, _), Houses),                              % 4. Coffee is drunk in the green house.
  member(house(_, ukrainian, _, tea, _), Houses),                             % 5. The Ukrainian drinks tea.
  nextto(house(ivory, _, _, _, _), house(green, _, _, _, _), Houses),         % 6. The green house is immediately to the right of the ivory house.
  member(house(_, _, snail, _, old_gold), Houses),                            % 7. The Old Gold smoker owns snails.
  member(house(yellow, _, _, _, kools), Houses),                              % 8. Kools are smoked in the yellow house.
  nth1(3, Houses, house(_, _, _, milk, _)),                                   % 9. Milk is drunk in the middle house.
  nth1(1, Houses, house(_, norwegian, _, _, _)),                              % 10. The Norwegian lives in the first house.
  adjacent(house(_, _, _, _, chesterfields), house(_, _, fox, _, _), Houses), % 11. The man who smokes Chesterfields lives in the house next to the man with the fox.
  adjacent(house(_, _, _, _, kools), house(_, _, horse, _, _), Houses),       % 12. Kools are smoked in the house next to the house where the horse is kept.
  member(house(_, _, _, orange_juice, lucky_strike), Houses),                 % 13. The Lucky Strike smoker drinks orange juice.
  member(house(_, japanese, _, _, parliaments), Houses),                      % 14. The Japanese smokes Parliaments.
  adjacent(house(_, norwegian, _, _, _), house(blue, _, _, _, _), Houses),    % 15. The Norwegian lives next to the blue house
  member(house(_, WaterDrinker, _, water, _), Houses),                        % Who (WaterDrinker) drinks water?
  member(house(_, ZebraOwner, zebra, _, _), Houses). % Who (ZebraOwner) owns the zebra?

View File

@ -0,0 +1,34 @@
% A formulation of Einstein's Riddle (aka Zebra Puzzle) in Prolog (specifically, SWI-Prolog - see http://www.swi-prolog.org/) as appeared on Life International magazine 17/12/1962
% Source: https://en.wikipedia.org/wiki/Zebra_Puzzle
% Modelling the problem:
% - Each house is represented by the predicate house/5
% - The five houses are modelled as a(n) (ordered) list of house(Color, Nationality, Pet, Beverage, Cigaret) in the variable Houses
% - The predicate solve/2 for solving the riddle is of the form solve(WaterDrinker, ZebraOwner) where WaterDrinker is the nationality of the person who drinks water and ZebraOwner the nationality of the person owning a zebra as a pet
% Expected solution: if the problem is modelled correctly by this program then the only solution set should be:
% WaterDrinker = norwegian, ZebraOwner = japanese.
% adjacent/3 - A helper function for expressing the "directly next to" relation in a list
% adjacent(A, B, List) means that either A is directly left of B in List or A is directly right of B in List
adjacent(A, B, List) :- nextto(A, B, List); nextto(B, A, List).
% solve/2 - The main predicate for solving the puzzle
solve(WaterDrinker, ZebraOwner) :-
length(Houses, 5), % 1. There are five houses.
member(house(red, english, _, _, _), Houses), % 2. The Englishman lives in the red house.
member(house(_, spanish, dog, _, _), Houses), % 3. The Spaniard owns the dog.
member(house(green, _, _, coffee, _), Houses), % 4. Coffee is drunk in the green house.
member(house(_, ukrainian, _, tea, _), Houses), % 5. The Ukrainian drinks tea.
nextto(house(ivory, _, _, _, _), house(green, _, _, _, _), Houses), % 6. The green house is immediately to the right of the ivory house.
member(house(_, _, snail, _, old_gold), Houses), % 7. The Old Gold smoker owns snails.
member(house(yellow, _, _, _, kools), Houses), % 8. Kools are smoked in the yellow house.
nth1(3, Houses, house(_, _, _, milk, _)), % 9. Milk is drunk in the middle house.
nth1(1, Houses, house(_, norwegian, _, _, _)), % 10. The Norwegian lives in the first house.
adjacent(house(_, _, _, _, chesterfields), house(_, _, fox, _, _), Houses), % 11. The man who smokes Chesterfields lives in the house next to the man with the fox.
adjacent(house(_, _, _, _, kools), house(_, _, horse, _, _), Houses), % 12. Kools are smoked in the house next to the house where the horse is kept.
member(house(_, _, _, orange_juice, lucky_strike), Houses), % 13. The Lucky Strike smoker drinks orange juice.
member(house(_, japanese, _, _, parliaments), Houses), % 14. The Japanese smokes Parliaments.
adjacent(house(_, norwegian, _, _, _), house(blue, _, _, _, _), Houses), % 15. The Norwegian lives next to the blue house
member(house(_, WaterDrinker, _, water, _), Houses), % Who (WaterDrinker) drinks water?
member(house(_, ZebraOwner, zebra, _, _), Houses). % Who (ZebraOwner) owns the zebra?