Commit Graph

735 Commits

Author SHA1 Message Date
Martin Nordholts a3ea798246
Credit syntax definition and theme authors with new `--acknowledgements` option (#1971)
The text that is printed is generated when building assets, by analyzing LICENSE
and NOTICE files that comes with syntaxes and themes.

We take this opportunity to also add a NOTICE file as defined by Apache License 2.0.
2021-12-11 14:00:45 +01:00
Ethan P 63ad53817d
Improved ANSI passthrough (#1596)
Improve handling of ANSI passthrough. Fix ANSI passthrough for --wrap=never. Add test for ANSI passthrough.
2021-12-08 16:06:42 +01:00
Martin Nordholts e250da8aaa Run `cargo clippy --fix --all-targets --all-features` with Rust 1.57
Clippy in the newly released Rust 1.57 found some new lints. Conveniently, all
of them were fixable with `--fix`.
2021-12-08 08:45:04 +01:00
Martin Nordholts 7fceb4878f
Load themes lazily for improved startup time (#1969)
This is for #951. Syntax lazy-loading will come later and have a much bigger
impact, but lazy-loading of themes does not have negligible impact.
2021-12-06 09:14:15 +01:00
Bojan Durdevic b8e79a2160 Line range edge cases test 2021-11-24 07:27:36 +01:00
Bojan Durdevic 715b0d8bf5 Line range minus overflow prevention 2021-11-24 07:27:36 +01:00
Bojan Durdevic 0eb4aaac1e Line range minus syntax clippy suggestions addressed 2021-11-24 07:27:36 +01:00
Bojan Durdevic bc86c29185 Support for line range minus syntax 2021-11-24 07:27:36 +01:00
Martin Nordholts 5519f9c716 Use once_cell instead of lazy_static
once_cell can do what lazy_static does and more, so replace lazy_static with
once_cell.

See https://docs.rs/once_cell/1.8.0/once_cell/#general-purpose-lazy-evaluation
2021-11-22 22:03:03 +01:00
Martin Nordholts dd0925a946 Replace lazycell with once_cell
We started to use lazycell because syntect already used it. But syntect has
changed to use once_cell. So we should also do that to prepare for using the
upcoming version of syntect.
2021-11-22 22:03:03 +01:00
Martin Nordholts d7671fa8e3 Remove the code related to minimal_syntaxes.bin
To get fast startup, syntect will instead start to lazy-load syntaxes. See
https://github.com/trishume/syntect/pull/393 and discussions in linked PRs.
2021-11-22 20:42:01 +01:00
Martin Nordholts e79b07bf5e HighlightingAssets::get_syntax_set(): Make private
Was forgotten in aefc8fd824.
2021-11-22 20:42:01 +01:00
Bojan Đurđević d6ed5e6746
Support for ignored-suffix CLI arguments (#1892) 2021-11-19 17:05:23 +01:00
rhysd d5f737f402 show skip message when asset cache is not found 2021-10-26 21:34:10 +02:00
cbolgiano 7fe4fdf33d
Introduce MapExtensionToUnknown MappingTarget (#1889)
Co-authored-by: Martin Nordholts <enselic@gmail.com>
2021-10-25 17:59:12 +02:00
Martin Nordholts 4081ace4b9 Include git hash in `bat -V` and `bat --version` output if present
I had to use a `lazy_static` due to that the clap API that only accepts a
reference to a version string. And, in our code, only a 'static reference to a
version string.

Code could probably be refactored to accept a "normal" reference, but that would
be a major undertaking.
2021-10-24 11:36:55 +02:00
rhysd f28d9db3d0 use io::Empty instead of crafted dummy stdin struct 2021-10-23 13:04:24 +02:00
rhysd deb80af449 remove unused lifetime parameter 2021-10-23 13:04:24 +02:00
rhysd dc0acbbb90 inline a closure which is called only once 2021-10-23 13:04:24 +02:00
rhysd 92ba42a602 do not take stdin lock when stdin is not used 2021-10-23 13:04:24 +02:00
rhysd ed3246c423 Make grep-cli optional dependency 2021-10-17 21:22:57 +02:00
Diva M ce4ddc0911 use saturating substraction to calculate Line ranges 2021-10-17 21:21:23 +02:00
Martin Nordholts 554374667e Deny unsafe code in lib and bin
The deny also applies recursively to submodules.
2021-10-04 08:08:33 +02:00
Martin Nordholts aefc8fd824 src/printer.rs: Simplify Plain Text fallback code
By forwarding the task to find the `Plain Text` syntax to `assets`. Not only does
the code become simpler; we also get rid of a call to `self.get_syntax_set()`
which is beneficial to the long term goal of replacing `syntaxes.bin` with
`minimal_syntaxes.bin`.

Note that the use of `.expect()` is not a regression in error handling. It was
previously hidden in `.find_syntax_plain_text()`.
2021-09-29 17:54:45 +02:00
Martin Nordholts 405a80f3ee HighlightingAssets: Turn get_syntax_for_path() into public API 2021-09-28 07:26:20 +02:00
Martin Nordholts ad98d35a48 HighlightingAssets: Implement get_syntax_for_file_name() with get_syntax_for_path()
We can do this since the file_name() of a file_name is file_name.
2021-09-28 07:26:20 +02:00
Martin Nordholts b69ab219d7 HighlightingAssets: Extract get_syntax_for_path() method
To make the code easier to refactor further.
2021-09-28 07:26:20 +02:00
Martin Nordholts dc8225f682 src/assets.rs: Extract helper method OpenedInput::path() 2021-09-27 08:00:58 +02:00
Martin Nordholts 9d9b266f54 build_assets.rs: Enable dump of syntax dependencies to Graphviz dot file 2021-09-24 20:07:55 +02:00
Martin Nordholts b9d01c1a61 build_assets.rs: Ignore explicit contexts when tracking dependencies 2021-09-24 20:07:55 +02:00
Martin Nordholts 122cae7902 build_assets.rs: Sort first to make dependencies.dedup() actually useful 2021-09-24 20:07:55 +02:00
Martin Nordholts 5143f3ad43 build_assets.rs: Add code to track dependents of each syntax
This information is useful when you want to build several SyntaxSets, but
without having to duplicate SyntaxDefinitions. For example:

"Rust" has no dependencies. But "Markdown" depends on "Rust". With the data
structures this code adds, we know that "Rust" is a dependent syntax for
"Markdown", and can construct a SyntaxSet that takes that into account.

Note that code has a temporary environment flag to ignore any information about
dependents when constructing SyntaxSets. Code that makes use of the new data
structure will be added later.
2021-09-22 09:14:19 +02:00
Martin Nordholts a6dc25a216 build_assets.rs: Make OtherSyntaxLookup come before SyntaxToDependencies
It makes more sense structurally when we later introduce SyntaxToDependents.
2021-09-22 09:14:19 +02:00
Martin Nordholts f04d2a9d6a build_assets.rs: Rename 'Dependency' to 'OtherSyntax'
So that we later can use it for not only information about dependencies, but
also for information about dependents.
2021-09-22 09:14:19 +02:00
Martin Nordholts eb3b3b9f8d src/printer.rs: Add HighlighterFromSet helper
The main benefit is that we get rid of a call to `assets.get_syntax_set()`,
which in turn makes it easier to later get rid of `syntaxes.bin`.
2021-09-22 06:11:32 +02:00
Martin Nordholts 0994f3783f HighlightingAssets: Move common get_extension_syntax() code into find_syntax_by_extension() 2021-09-22 06:03:24 +02:00
Martin Nordholts 974dec38e3 HighlightingAssets: Inline find_syntax_by_file_name() and find_syntax_by_file_name_extension()
There is no benefit to keeping separate functions.
2021-09-22 06:03:24 +02:00
Martin Nordholts a0c363647f src/assets.rs: Use /// not // for COMPRESS_* consts 2021-09-18 07:05:04 +02:00
Martin Nordholts d989224a8a HighlightingAssets: Inline absolute_path
Its name is confusing, because it does not always hold an absolute path. Get rid
of this problem by inlining it.
2021-09-18 06:19:52 +02:00
Martin Nordholts 82f439e715 HighlightingAssets: Simplify absolute_path with .map_or_else() 2021-09-18 06:19:52 +02:00
Martin Nordholts b034879eae HighlightingAssets: No need for both path and path_str 2021-09-18 06:19:52 +02:00
Martin Nordholts 9ed9a6fc3d
Simplify HighlightingAssets::get_syntax() first_line logic (#1852)
And make self.get_first_line_syntax() be called lazily.
2021-09-16 17:01:12 +02:00
Martin Nordholts e84b702309
Extract some private submodules from 'bat::assets' (#1850) 2021-09-15 07:59:33 +02:00
Martin Nordholts 6226eba52a HighlightingAssets: Add find_syntax_by_extension() helper 2021-09-14 07:38:36 +02:00
Martin Nordholts 9e0ea06435 HighlightingAssets: Add find_syntax_by_name() helper 2021-09-14 07:38:36 +02:00
Marcin Puc 863d9cacd0 Add various other code refactorings 2021-09-12 15:50:10 +02:00
Marcin Puc 4baa346aae Use deref coercion to simplify some argument passing 2021-09-12 15:50:10 +02:00
Marcin Puc 7956485e37 Improve iterator usage 2021-09-12 15:50:10 +02:00
Marcin Puc 372e42f350 Reduce nesting in if blocks by short circuiting 2021-09-12 15:50:10 +02:00
Martin Nordholts 9124271eaf
Load independent and minimal syntax sets when using --language (#1787)
This significantly speeds up the startup time of bat, since only a single
linked SyntaxDefinition is loaded for each file. The size increase of the
binary is just ~400 kB.

In order for startup time to be improved, the --language arg must be used, and
it must match one of the following names:

"Plain Text", "ActionScript", "AppleScript", "Batch File", "NAnt Build File",
"C#", "C", "CSS", "D", "Diff", "Erlang", "Go", "Haskell", "JSON", "Java
Properties", "BibTeX", "LaTeX Log", "TeX", "Lisp", "Lua", "MATLAB", "Pascal",
"R", "Regular Expression", "Rust", "SQL", "Scala", "Tcl", "XML", "YAML", "Apache
Conf", "ARM Assembly", "Assembly (x86_64)", "CMakeCache", "Comma Separated
Values", "Cabal", "CoffeeScript", "CpuInfo", "Dart Analysis Output", "Dart",
"Dockerfile", "DotENV", "F#", "Friendly Interactive Shell (fish)", "Fortran
(Fixed Form)", "Fortran (Modern)", "Fortran Namelist", "fstab", "GLSL",
"GraphQL", "Groff/troff", "group", "hosts", "INI", "Jinja2", "jsonnet",
"Kotlin", "Less", "LLVM", "Lean", "MemInfo", "Nim", "Ninja", "Nix", "passwd",
"PowerShell", "Protocol Buffer (TEXT)", "Puppet", "Rego", "resolv", "Robot
Framework", "SML", "Strace", "Stylus", "Solidity", "Vyper", "Swift",
"SystemVerilog", "TOML", "Terraform", "TypeScript", "TypeScriptReact",
"Verilog", "VimL", "Zig", "gnuplot", "log", "requirements.txt", "Highlight
non-printables", "Private Key", "varlink"

Later commits will improve startup time for more code paths.

* fix some typos and misspellings

* CHANGELOG.md: Add Performance section (preliminary)

* Add a CHANGELOG.md entry for this PR
2021-09-09 20:52:33 +02:00