Commit Graph

933 Commits

Author SHA1 Message Date
skoriop 0937d575fd fix: rewrite overflow test using `usize::MAX` 2023-10-05 09:20:09 +02:00
skoriop d89df18de2 test: add test for overflow in `LineRange::from` 2023-10-05 09:20:09 +02:00
skoriop 9fcc57e496 fix: integer overflow in `LineRange::parse_range` 2023-10-05 09:20:09 +02:00
Linda_pp 9f795dd947
Associate `*.sarif` files with `json` syntax (#2695)
* Associate `*.sarif` files with `json` syntax

* Update changelog for #2695
2023-10-04 09:34:40 +02:00
Nicolas AMBRY 5a240f36b9
Case insensitive `--map-syntax` (#2650)
Co-authored-by: Nicolas AMBRY <nicolas.ambry@atos.net>
2023-09-14 16:04:43 +02:00
J-Kappes e2bf85e749
Make -pp override --paging and vice versa when passed as a later argument. (#2660) 2023-09-14 05:45:46 +02:00
Anomalocaridid 433176ab54 require LESSOPEN to have exactly one %s 2023-09-08 06:25:20 +02:00
Anomalocaridid b56021ffa9 make LESSOPEN support opt-in 2023-09-08 06:25:20 +02:00
Anomalocaridid ac2953c070 pass --no-lessopen to less by default 2023-09-08 06:25:20 +02:00
Anomalocaridid e32ad0b048
Add `$LESSOPEN` and `$LESSCLOSE` support (#2444) 2023-09-02 08:48:26 +02:00
David Peter 3abc0c0fc4
Merge pull request #2548 from utkarshgupta137/master
Replace `dirs` crate with `etcetera` crate
2023-09-01 21:41:24 +02:00
David Peter b06f13f0c5
Merge pull request #2618 from Piturnah/feat/write-to-buffer
feat: Optionally write to a buffer instead of stdout
2023-09-01 21:18:04 +02:00
Utkarsh Gupta a721cc31f3 Replace `dirs` crate with `etcetera` crate 2023-09-01 21:13:21 +02:00
David Peter 1e52785d35
Merge pull request #2626 from rhysd/encoding_rs
Replace unmaintained `encoding` dependency with `encoding_rs`
2023-09-01 21:12:07 +02:00
Orion Yeung 9ba3b6ed13
No duplicate keys test, fixes #2643 (#2647)
* moved unit tests to conditional compile

made module `tests` and conditionally compiled

* added test to check for duplicate keys in builtin

checks all pairs in GlobMatcher::mappings via `GlobMatcher::glob`s `Eq`
panics at first match

```rs
SyntaxMapping {
  mappings: Vec<(
    GlobMatcher {
      glob: Glob, ...,
    }, ...,
  }, ...,
}
```

* output more info with test failure

* dont duplicatively add git config path

* use guard in match for adding builtin git config syntax mapping

---------

Co-authored-by: Orion Yeung <11580988+orionyeung001@users.noreply.github.com>
2023-09-01 21:11:41 +02:00
Peter Hebden 72e1a40bab Remove leftover unwrap 2023-09-01 20:52:55 +02:00
Peter Hebden b2c28cdddb Clippy lints 2023-09-01 20:52:55 +02:00
Peter Hebden 906e774372 Handle todos 2023-09-01 20:52:55 +02:00
Peter Hebden d929becefc Fix signatures 2023-09-01 20:52:55 +02:00
Peter Hebden 103a2f0d9b Add `OutputHandle` enum to use instead of `&mut dyn io::Write` 2023-09-01 20:52:55 +02:00
rhysd d33b2e158e Replace unmaintained `encoding` with `encoding_rs` 2023-09-01 20:41:55 +02:00
einfachIrgendwer0815 26111950b3 Add environment variable `BAT_PAGING` 2023-09-01 17:59:41 +02:00
Orion Yeung f21d3502e1 Add `*.ron` syntax mapping
Add a mapping to use `Rust` for rusty object notation, identified by `.ron` extension. See [#2427](https://github.com/sharkdp/bat/issues/2427).
2023-09-01 17:57:46 +02:00
WinterCore d580445aef fix: Add syntax mapping `jsonl` => `json` 2023-09-01 17:45:41 +02:00
mataha 82664e3c82 Bump MSRV to 1.70.0
The intention is to take advantage of `std::io::IsTerminal` that landed
in 1.70.0, both in `bat` and its dependencies (`clap`, `grep-cli`).

This will fix #2570 as well - `grep-cli` 0.1.9 has a patch for that.

Signed-off-by: mataha <mataha@users.noreply.github.com>
2023-09-01 05:42:45 +02:00
Ville Skyttä 1893405cbf Add .dpkg-new and .dpkg-tmp to ignored suffixes
Refs https://www.debian.org/doc/manuals/debian-handbook/sect.package-meta-information.en.html#sect.conffiles
2023-08-28 17:50:29 +02:00
John Higgins b1fbcc8a6e
fix for issue #2633 2023-08-02 00:04:55 -07:00
einfachIrgendwer0815 c46c53320b
Add `Containerfile` syntax mapping 2023-07-02 13:50:37 +02:00
cyqsimon f8c700027e
Add `os-release` syntax mapping 2023-06-01 13:17:22 +08:00
Nigecat 149dec6953 Fix paging not happening when stdout is interactive but stdin is not 2023-05-22 05:42:01 +02:00
Constantin Nickel 57cc0d8435 Use the `is-terminal` crate instead of `atty`
The crate is already used by `clap` and a similar trait is about to be
stabilized in `std`.
2023-04-05 19:26:52 +02:00
Collin Styles 7929179a74 Make `PrettyPrinter::header` an alias for `header_filename`
Fixes #2378
2023-03-24 22:33:43 +01:00
David Peter 1a142a82b4
Merge pull request #2513 from nickelc/deps/dirs
Replace `dirs-next` with the original `dirs` crate
2023-03-24 22:07:47 +01:00
Constantin Nickel 0e148e35dd Replace `dirs-next` with the original `dirs` crate
The `dirs` crate was forked as `dirs-next` after the original repos were archived.
The fork hasn't released a new version since October 2020, while the original
has been taken off the shelf and has seen updates since then.
2023-03-24 19:10:38 +01:00
Constantin Nickel da3aa4e2fd Use `nu-ansi-term` instead of `ansi_term`
The `nu-ansi-term` crate is a fork of `ansi_term` which is maintained by
the Nushell project.
2023-03-24 17:42:54 +01:00
David Peter 231ad86f04
Merge pull request #2502 from Enselic/clippy-1.68
Fix clippy warnings with Rust 1.68
2023-03-15 08:36:28 +01:00
einfachIrgendwer0815 8f99a78cf1
Print non-printable characters using caret notation (#2443)
When the new flag is set, non-printable characters are printed using caret notation.
2023-03-14 22:21:30 +01:00
Martin Nordholts 40a423905a Fix clippy warnings with Rust 1.68 2023-03-14 21:19:14 +01:00
Martin Nordholts ec6e9c29ac
Bump MSRV to 1.62 (#2496)
* Bump MSRV to 1.62

Mainly to be able to derive default enum variants.

* CHANGELOG.md: Update
2023-03-03 13:20:03 +01:00
BlackHoleFox 1004018941 Directly read preferences instead of using the defaults CLI 2023-02-05 16:53:28 +01:00
rhysd 4cc2a489d0 Remove unnecessary heap allocations in `PrettyPrinter::print` for style components 2023-01-15 21:16:36 +09:00
rhysd 5e3abcad07 Fix code fence in doc comment 2023-01-13 08:16:38 +01:00
Miles Liu e39178b101
Fix `bat cache --clear` not clearing the `--target` dir if specified 2022-11-19 18:00:37 +08:00
Aaron Kollasch e773b48135
Fix cache subcommand and add tests
Treat the cache subcommand differently from --no-config:
For --no-config, insert args from selected environment variables
For cache, don't insert args
2022-11-02 16:48:51 -04:00
Aaron Kollasch 4bcea01e9d
Deduplicate lines in matches function 2022-11-02 16:48:51 -04:00
Aaron Kollasch 76aad7c74f
Improve correctness and add more tests 2022-11-02 16:48:50 -04:00
Aaron Kollasch 36ccc6a31e
Allow env vars to override config but not args 2022-11-02 16:48:50 -04:00
David Peter a65b0828ee Merge remote-tracking branch 'origin/master' into HEAD 2022-10-30 20:43:06 +01:00
David Peter ccde13c9e8 Hide 'cache' subcommand, re-enable bold/underline styling, add note about cache subcommand 2022-10-30 20:26:06 +01:00
John Higgins ff71303349
Update src/bin/bat/clap_app.rs for PR 2309
Co-authored-by: Martin Nordholts <enselic@gmail.com>
2022-10-17 23:35:52 -07:00
John Higgins 236a2c5794
Fixed inverted logic on -S and --chop-long-lines 2022-10-13 23:52:15 -07:00
John Higgins 03216c9c18
Merge branch 'sharkdp:master' into master 2022-10-09 22:56:11 -07:00
John Higgins 375b392478
Fixed reversed logic error for --chop-long-lines 2022-10-09 22:41:27 -07:00
Gábor Lipták 1e0b0f7c5c Add github-actions to Dependabot
Signed-off-by: Gábor Lipták <gliptak@gmail.com>
2022-10-03 15:18:39 -05:00
Martin Nordholts 352309b056 Revert "Remove code that tries to handle ANSI escape inputs"
This reverts commit 8174e02279. Turns out
it is needed for a common use case, see
https://github.com/sharkdp/bat/issues/2307.

It is not a clean revert, because I adjust CHANGELOG.md and also add a
comment to the test. I also had to resolve a small `use` conflict.
2022-09-10 17:59:33 +02:00
John Higgins a272d3df16
Added -S flag for truncating long lines 2022-09-09 17:04:09 -07:00
dag-h 08386daa3a
Strip BOM from output in interactive mode (#1938)
* Strip BOM from output in interactive mode

* Strip BOM when not loop_through, add regression tests

* Update CHANGELOG.md

* Only strip BOM from beginning of first line

* Fix integration test on macOS that relied on color scheme

* Fix integration test on Windows that relied on detected terminal width

* Fix syntax test that was failing due to a previously wrong (now fixed) highlighting

Co-authored-by: David Peter <mail@david-peter.de>
Co-authored-by: Martin Nordholts <enselic@gmail.com>
2022-09-06 19:08:38 +02:00
rhysd 3d7817d662 Clear `highlighted_lines` when calling `PrettyPrinter::print` 2022-09-05 21:17:08 +09:00
rhysd abd69f2deb Add `bat::PrettyPrinter::clear_highlights` (fixes #1919) 2022-09-05 17:35:32 +09:00
Kid 839e62cff8 Map `fish_history` to YAML 2022-09-04 22:22:18 +02:00
Martin Nordholts 2dd2994b2f Merge remote-tracking branch 'origin/master' into feature/668/add-systemwide-config 2022-09-04 20:44:23 +02:00
David Peter 48541b8507 Fix clippy suggestions
Leads to a performance improvement for `bat -A`:

    | Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
    |:---|---:|---:|---:|---:|
    | `./bat-master --no-config -A ./bat-master` | 259.8 ± 1.1 | 258.4 | 261.7 | 1.15 ± 0.01 |
    | `./bat-2301 --no-config -A ./bat-master` | 225.6 ± 1.8 | 224.0 | 229.5 | 1.00 |
2022-09-04 14:28:44 +02:00
Ed Page 08c91a116c refactor: Parse, don't validate 2022-09-03 14:01:56 +02:00
Ed Page 3d398b35c3 refactor: Switch from is_present to actions
Because "diff" is conditionally present, we need to check for it to
avoid some of clap's stricter checks meant to prevent bugs.
2022-09-03 14:01:56 +02:00
Ed Page 6099f2c146 refactor: Move off of value_of 2022-09-03 14:01:56 +02:00
Ed Page 50bb924ee3 refactor: Replace multiple_occurrences 2022-09-03 14:01:56 +02:00
Ed Page e8e1c1d6c9 refactor: Replace allow_invalid_utf8 with PathBuf 2022-09-03 14:01:56 +02:00
Ed Page 542b3d2317 refactor: Resolve basic clap deprecations 2022-09-03 14:01:56 +02:00
Ed Page 2323804f7e refactor: Port to clap3
Ths does remove the specialization of version's description.  The way
this is done (internally through `mut_arg`) doesn't play well with
subcommands.  Clap tries to force this version of `version` into the
subcommand despite not being needed.  Clap v4 dramatically changes how
version customization works.

clap also does more error checks now to prevent programmer mistake, so
we can't have a conflict with an argument that is conditionally there,
so I swapped the condition.
2022-09-03 14:01:56 +02:00
Martin Nordholts 49875d6ce7
Make `bat::PrettyPrinter::syntaxes()` iterate over new `bat::Syntax` struct (#2222)
We can't keep `syntect::parsing::SyntaxReference` as part of the public
API, because that might prevent us from bumping to syntect 6.0.0 without
also bumping bat to v2.0.0, once we reach v1.0.0.

So introduce a new stripped down struct `Syntax` and return that
instead. Let it be fully owned to make the API simple. It is not going
to be in a hot code path anyway.

I have looked at all code of our 27 dependents but I can't find a single
instance of this method being used, so this change should be safe for
v1.0.0.
2022-09-03 12:33:38 +02:00
Martin Nordholts 899fdbb347
Remove code that tries to handle ANSI escape inputs (#2189)
Syntax highlighting is broken when input contains ANSI escape characters
anyway, so there is not much point in trying to handle ANSI escapes in
input.
2022-08-29 18:49:29 +02:00
Christopher Acosta 9a924b445b
Make --map-syntax and --ignored-suffix work together (#2260)
* Make --map-syntax and --ignored-suffix work together

* Minor refactor
2022-08-16 22:42:15 +02:00
Marie Katrine Ekeberg 9c7ca33929
Make `--no-paging`/`-P` override `--paging=...` if passed as a later arg (#2201)
* Make the no-paging option override earlier paging options

* Update CHANGELOG.md

Co-authored-by: Martin Nordholts <enselic@gmail.com>
2022-08-14 21:09:13 +02:00
John Higgins 7b2e0ece55
Prevent fork nightmare with PAGER=batcat (#2235)
* Added rsamuelklatchko's changes

* Added some comments and deleted redundant code

* Ran cargo fmt

* Update src/pager.rs

Co-authored-by: Martin Nordholts <enselic@gmail.com>

* Added bugfix to changelog

* src/pager.rs nitpick: arg0 -> s

I forgot to comment on this name so I figured I'd just push a commit to
take care of it.

Co-authored-by: Martin Nordholts <enselic@gmail.com>
2022-08-12 14:27:47 +02:00
Anders Kaseorg 4583826a5b Fix documentation typo: --pager=never → --paging=never
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2022-07-07 06:09:11 +02:00
Cre3per ed4997c77c
Add syntax mapping from NSE to Lua (#2214) 2022-06-04 14:12:42 +02:00
Martin Nordholts 3339eee2dc
Make the default macOS theme depend on Dark Mode (#2197)
* Make the default macOS theme depend on Dark Mode

We frequently get complaints from macOS users that bat does not work on
their default macOS terminal background, which is white.

Pay the price of slightly increased startup time to get a better default
on macOS. To avoid the slightly increased startup time, simply specify a
theme explicitly via `--theme`, `BAT_THEME`, or `~/.config/bat`.

Note that if there is an error when we check if Dark Mode is enabled, we
behave the same as on Windows and Linux; assume that the terminal
background is dark. This harmonizes behavior across platforms, and makes
bat behave the same as before, when Dark Mode was always assumed to be
enabled.

* src/assets.rs: Fix typo

* Update CHANGELOG.md
2022-05-24 19:29:03 +02:00
Martin Nordholts 7334ab4542
Bump to syntect 5.0.0 to e.g. start lazy-loading syntaxes (#2181)
* Bump to syntect 5.0.0 to e.g. start lazy-loading themes

Closes #915
Closes #951
Closes #1846
Closes #1854

* Typo fix formated -> formatted

* Update CHANGELOG.md
2022-05-07 13:43:11 +02:00
Martin Nordholts 0851bbbb28 printer.rs: De-duplicate code to highlight long lines
We do this to only have one invocation of `highlighter.highlight(...)`
so we don't need to change to `highlighter.highlight_line(...)` in two
places in #2181.
2022-05-05 17:21:49 +02:00
Isaac Horvath adea895026
Add a --style=default option (#2119)
* Add a --style=default option

* Added --style=default test and CHANGELOG entry

* Format CHANGELOG.md options with quotes

Co-authored-by: Martin Nordholts <enselic@gmail.com>

* Update help text for '--style'

* Make --style=default the default option

* Update style descriptions: "basic" -> "recommended"

* Add integration test for --style=default as default

* Update clap long help for --style
2022-05-04 21:31:32 +02:00
Keith Hall b5294f1cb2
Skip syntax highlighting for long lines (#2165)
* Skip highlighting for long lines

* Run cargo fmt, update changelog
2022-05-04 07:59:24 +02:00
Nathan Fisher 5114c0189d
Add support for BusyBox less as pager (#2162)
* Add support for BusyBox less as pager

* Run tests/syntax-tests/update.sh to update tests

* Address reviewer's concerns with pull request
* Revert all changes in `test` directory
* Minimize overall diff size
* Detect busybox from separate helper function
* Pass equivalent options to BusyBox from same code by changing from long to
  short options

* Remove redundant `if` statement from previous commit
Add test for invalid utf-8
Add `parse_less_version_busybox` to test for invalid program
Add commenting around short options
2022-05-04 07:56:38 +02:00
Martin Nordholts acb1231e40 Run `cargo clippy --fix --all-targets --all-features` with Rust 1.60
Clippy in the newly released Rust 1.60 found some new lints.
Conveniently, all of them were fixable with `--fix`.

By fixing these lints it becomes easier for us and others to see when
new lints are introduced.
2022-05-04 07:49:40 +02:00
cyqsimon 3ae05333b0
Add mapping for Unix mail spool (#2156) 2022-04-27 22:51:10 +02:00
Martin Nordholts 520081a92c Print info about custom assets in --diagnostics 2022-04-02 21:46:41 +02:00
acheronfail b1e67e215c Allow configuring show_nonprintable from PrettyPrinter 2022-04-02 21:05:37 +02:00
Patrick Pichler 5ed64444e3 Add systemwide config file support
There is now support for a systemwide config file. The location of the
system wide config file is `$(BAT_SYSTEM_CONFIG_PREFIX)/bat/config`.
`$(BAT_SYSTEM_CONFIG_PREFIX)` has to be provided at compile time as an
environment variable. If the environment variable is not set, a default
is used. This default is `C:\ProgramData` for windows and `/etc` for
every other os.
2022-03-10 20:55:11 +01:00
Martin Nordholts 9ab378b5dc Include contents of custom assets `metadata.yaml` in `--diagnostics` 2022-03-07 21:05:09 +01:00
Patrick Hilhorst e7df748b6d correctly handle multiple tabs in one line 2022-03-06 20:03:00 +01:00
Patrick Hilhorst da5921b4a9 Correctly render tab stops 2022-03-06 20:03:00 +01:00
TruncatedDinosour cde239e809
Syntax: add clang-format (#2076)
Highlight .clang-format files as YAML

Co-authored-by: Ari Archer <truncateddinosour@gmail.com>
Co-authored-by: David Peter <mail@david-peter.de>
2022-03-06 20:01:49 +01:00
cyqsimon 14ddda0a8b
Recognize files in `$XDG_CONFIG_HOME/git/` and `$HOME/.config/git/` better (#2067)
* git global config - lookup $XDG_CONFIG_HOME faithfully

* Use `bool::then`

* Cover both `$XDG_CONFIG_HOME` & `$HOME/.config`

* Remove unused import

* Global git config tests

* Added trailing newline

* Fix git config test

* Wrote to changelog

* Revert change of `Result::ok` to `Result::unwrap`

* Apply suggestions from code review

Co-authored-by: Martin Nordholts <enselic@gmail.com>

* Guard against empty `$HOME`

Co-authored-by: Martin Nordholts <enselic@gmail.com>
2022-02-26 17:01:00 +01:00
Mahdi Dibaiee d21f1e8f17
Underline highlighted lines in ANSI theme (#1985)
* Underline highlighted lines in ANSI theme

* add test for ansi highlight underline, fix underscore in plain
2022-02-14 19:02:14 +01:00
Dan Davison 4e36a56014
Expose syntect theme and syntax sets (#2030)
Fixes #2026
Ref https://github.com/dandavison/delta/issues/895
2022-02-08 08:00:12 +01:00
Mahdi Dibaiee 312c8ef01f
Add new `--style` called `header-filesize` and display it by default (#1988)
Also rename `header` to `header-filename`.

Related to #1701
2022-02-07 20:48:57 +01:00
Martin Nordholts 486510395b Allow the license used by GraphQL
This license is apparently common enough that GitHub recognizes it. See
https://github.com/dncrews/GraphQL-SublimeText3/blob/master/LICENSE.

This will fix the CI failure in #2000
2022-02-07 06:14:07 +01:00
Martin Nordholts 5b37438f08 `bat --help`: Put `--ignored-suffix` directly after `--map-syntax`
It feels out of place to have between `--acknowledgements` and `--help`.
2022-01-08 17:01:20 +01:00
Martin Nordholts 68528983d7 Mark `MappingTarget` as `#[non_exhaustive]` for increased semver flexibility
This will allow us to add new enum variants in the future without breaking
semver compatibility. See
https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute

Since we already added an enum variant since v0.18.3, now is a good time to mark
it as `#[non_exhaustive]`.
2022-01-04 08:19:51 +01:00
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
Kevin John Mulligan 156dec2737 Add context to .ino configuration
This allows a user to search the README or the entire repository for "Arduino" to find the necessary configuration.
2021-09-07 20:21:12 +02:00
Martin Nordholts 87978e7755
Make asset compression optional at compile time (#1825)
This will be needed to later support zero-copy deserialization of independent
syntax sets, but is interesting and useful on its own.

Instead of deferring serialization and deserialization to syntect, we implement it
ourselves in the same way, but make compression optional.
2021-09-07 17:21:48 +02:00