Commit Graph

803 Commits

Author SHA1 Message Date
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