* 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>
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>
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.
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.
* 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>
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.
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.
* 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>
* 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
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.
* 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
* 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
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.
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.
* 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>
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.
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.
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.
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()`.
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.