Commit Graph

97 Commits

Author SHA1 Message Date
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
Miles Liu e39178b101
Fix `bat cache --clear` not clearing the `--target` dir if specified 2022-11-19 18:00:37 +08: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 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 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 520081a92c Print info about custom assets in --diagnostics 2022-04-02 21:46:41 +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
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
cbolgiano 7fe4fdf33d
Introduce MapExtensionToUnknown MappingTarget (#1889)
Co-authored-by: Martin Nordholts <enselic@gmail.com>
2021-10-25 17:59:12 +02:00
rhysd ed3246c423 Make grep-cli optional dependency 2021-10-17 21:22:57 +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 405a80f3ee HighlightingAssets: Turn get_syntax_for_path() into public API 2021-09-28 07:26:20 +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 19c3e82abf
Replace deprecated 'error-chain' with 'thiserror' (#1820)
We can't use #[from] on Error::Msg(String) because String does not implement Error.
(Which it shouldn't; see e.g. https://internals.rust-lang.org/t/impl-error-for-string/8881.)
So we implement From manually for Error::Msg, since our current code was written
in that way for error-chain.
2021-08-26 13:12:21 +02:00
Martin Nordholts f1c0fd7343
Don't take a HighlightingAssets detour to build assets (#1802)
Move code to build assets to its own file. That results in better modularity and flexibility.

It also allows us to simplify HighlightingAssets a lot, since it will now always
be initialized with a SerializedSyntaxSet.
2021-08-24 07:58:03 +02:00
Martin Nordholts ba8a694314 Add LANG and LC_ALL to --diagnostics output
To make it easier to debug problems like #1806 in the future.
2021-08-22 18:31:39 +02:00
Martin Nordholts ed09f90e5e Fix all lints that are new with Rust 1.54
They are all of the following type:
https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
2021-08-19 07:19:12 +02:00
Martin Nordholts 25fa577cd0 Make 'build-assets' an optional capability for application
Also structure features a bit more clever to avoid duplication of
feature dependency declarations.
2021-08-17 10:58:21 +02:00
Martin Nordholts 905902d811 bin: Allow to build without bugreport 2021-08-08 11:18:26 +02:00
Martin Nordholts d8b813c0bf
When returning a SyntaxReference, also return the SyntaxSet that contains it (#1776)
To improve startup performance, we will later load smaller `SyntaxSet`s instead
of one giant one. However, the current API assumes only one `SyntaxSet` is ever used,
and that that implicitly is the `SyntaxSet` from which returned `SyntaxReference`s
comes.

This change changes the API to reflect that `SyntaxSet` and `SyntaxReference`
are tightly coupled, and enables the use of several `SyntaxSet`.
2021-08-08 08:26:17 +02:00
Martin Nordholts b040efff79 Support a hidden arg --no-custom-assets that skips loading assets from the cache 2021-07-29 08:27:02 +02:00
Martin Nordholts a81009607a HighlightingAssets: Make .syntaxes() and syntax_for_file_name() failable
Or rather, introduce new versions of these methods and deprecate the old ones.

This is preparation to enable robust and user-friendly support for lazy-loading.
With lazy-loading, we don't know if the SyntaxSet is valid until after we try to
use it, so wherever we try to use it, we need to return a Result. See discussion
about panics in #1747.
2021-07-29 08:26:18 +02:00
David Peter 3fa09dbe2e Use resolved path for --diagnostic as well 2021-07-12 23:17:30 +02:00
Martin Nordholts e04fbd1992 Include LESS in --diagnostic
So issues like #1586 are easier to troubleshoot.
2021-03-17 21:10:16 +01:00
Aleksey Kladov 35347c2310 Improve readability
Using `Path`s for paths expresses intent more clearly.
2021-03-07 14:59:10 +01:00
David Peter 9ad401be87 Fix clippy suggestion 2021-02-16 09:13:22 +01:00
Ethan P f874c8e4db Use less binary specified in bat config for --diagnostic 2021-02-16 09:11:27 +01:00
sharkdp c5c28eb05b --diagnostic: add MANPAGER environment variable 2021-01-09 21:56:17 +01:00
Csaba Henk fed30b1b36 Fix theme dir hint in --list-themes output 2021-01-08 20:10:45 +01:00
sharkdp 6a52f69b58 Update to bugreport 0.3.0 2021-01-06 22:53:51 +01:00
sharkdp 60406c7c2d Exhaustive list of relevant environment variables 2021-01-06 22:53:51 +01:00
sharkdp dec94b4111 Add config file, compile time info and less version 2021-01-06 22:53:51 +01:00
sharkdp ebb97e94a9 Add --diagnostic option to bat 2021-01-06 22:53:51 +01:00
Martin Nordholts 9c16571347 bat --list-languages: remove unnecessary format!() call
To trigger/verify the changed code, run

    bat --list-languages   # or -L

This is the last clippy warning in the code that you get if you run

    cargo clippy --all-targets --all-features -- --allow clippy::style

so by fixing it it becomes easier to spot when a new warning is
introduced (that does not belong to the clippy category clippy::style).
And by making it easy to spot new warnings, we increase chance of such
regressions not ending up in the code base.
2020-12-28 20:28:24 +01:00
Stefan Kunkel bf96e6e642 make bat -L use plain style 2020-12-21 09:24:56 +01:00
Stefan Kunkel cffacad306 make bat -L use pager 2020-12-21 09:24:56 +01:00
rsteube 84b0702399 only print themes hint in interactive mode 2020-12-17 10:41:07 +01:00
Nicholas L 8e8131590c Use platform based path concatenation 2020-10-30 08:04:14 +01:00
Nicholas L 3acfe790b9 Add extra themes help to output 2020-10-30 08:04:14 +01:00
sharkdp f84aceec3d Fix unwrap error 2020-09-20 19:54:05 +02:00
Kienyew 83c7750656 Use unwrap 2020-09-20 12:14:21 +02:00
Kienyew c477e23fe9 Handle file extension conflicts in --list-languages 2020-09-20 12:14:21 +02:00
Kienyew 31fb7087f1 Revert to previous commit 2020-09-20 12:14:21 +02:00
Kienyew 52d6701f8f Fix undesired behavior 2020-09-20 12:14:21 +02:00
Kienyew f97634011e Handle file extension conflicts in --list-languages (#1076) 2020-09-20 12:14:21 +02:00