Commit Graph

656 Commits

Author SHA1 Message Date
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
Martin Nordholts c0e09662b4 HighlightingAssets::get_extension_syntax(): Split up into smaller methods
To make the code easier to understand and change.
2021-07-28 08:42:18 +02:00
Martin Nordholts ccf4563573 Make loading of cached assets closer in performance to integrated assets
Using BufReader makes sense for large files, but assets are never large enough
to require buffering. It is significantly faster to load the file contents in
one go, so let's do that instead.

Closes #1753
2021-07-27 14:53:59 +02:00
Martin Nordholts f6fc826dc6 HighlightingAssets: Introduce private fn new() helper
It already now reduces code duplication slightly, but will become even more
useful in the future when we add more complicated logic such as lazy-loading.
2021-07-20 06:34:32 +02:00
Martin Nordholts 375d55aa5d HighlightingAssets: Encapsulate syntax_set behind a getter
Since we only modify `pub(crate)` items, the stable bat-as-a-library API is not
affected.

This takes us one step closer to making SyntaxSet lazy-loaded, which in turn
takes us one step closer to solving #951.
2021-07-19 05:27:12 +02:00
Martin Nordholts 6ef2bb3283 De-duplicate some themes.bin and syntaxes.bin related code 2021-07-15 16:22:35 +02:00
David Peter 33c11d64f0 Run cargo fmt 2021-07-13 08:19:59 +02:00
David Peter 3fa09dbe2e Use resolved path for --diagnostic as well 2021-07-12 23:17:30 +02:00
David Peter bf2b2df9c9 Fix for Windows: do not run binaries from CWD
This fixes a bug on Windows where `Command::new` would also run
executables from the current working directory, possibly resulting in
accidental runs of programs called `less`.
2021-07-12 23:17:30 +02:00
David Peter 21338ed789 Abort ignored filename suffix stripping early on unworkable filenames 2021-07-09 06:34:11 +02:00
David Peter dc8ab0b5ce Simplify ignored filename suffix stripping 2021-07-09 06:34:11 +02:00
Ville Skyttä 355e62efe9 Find syntax ignoring known backup/template filename suffixes
For example, fall back to `foo.extension` for `foo.extension~`,
`foo.extension.orig`, `foo.extension.in.in` etc.
2021-07-09 06:34:11 +02:00
Martin Nordholts 073b9968c0 pretty_printer.rs: Don't use a URL as an example Input title
Otherwise Rust 1.53.0 gets confused during `cargo doc` because it thinks
we want an actual URL:

    warning: this URL is not a hyperlink
    --> src/pretty_printer.rs:331:40
        |
    331 |     /// The title for the input (e.g. "http://example.com/example.txt")
        |                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use an automatic link instead: `<http://example.com/example.txt>`
        |
        = note: `#[warn(rustdoc::bare_urls)]` on by default
        = note: bare URLs are not automatically turned into clickable links

It was perhaps also a bit confusing to give an URL as an example in the
first place, because according to our own API example
`examples/inputs.rs` it is meant to be more a free-text thing.
2021-06-28 07:10:30 +02:00
Ville Skyttä 90e48e9b61 Spelling fixes 2021-06-13 22:08:56 +02:00
Mohamed Abdelnour aa74d19940 Refactor "Use `matches` macro" 2021-05-27 12:05:07 +02:00
Mohamed Abdelnour 425a0f90e9 Use the functional update syntax 2021-05-27 12:05:07 +02:00
Mohamed Abdelnour a27814db8e Implement `From<..>` instead of `Into<..>` 2021-05-27 12:05:07 +02:00
Mohamed Abdelnour 9702f5256c Use the functional update syntax 2021-05-27 12:05:07 +02:00
Mohamed Abdelnour 23fd11e806 Use `matches` macro 2021-05-27 12:05:07 +02:00
Mohamed Abdelnour 304ee1489c Use `!theme.is_empty()` 2021-05-27 12:05:07 +02:00
Allen Wild 91a347bf6d Fix less version parsing for minor versions of less
Less 581.2 is here, and it has a ".2" in the version string, which can't
be parsed as a usize.

Update the check to find a non-digit character rather than a space. This
ignores the minor version, but parses the major version correctly.
2021-05-12 11:47:16 +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
Sean McLoughlin d89fa3ebc2 Add SystemVerilog support 2021-03-15 07:21:15 +01:00
David Peter 2e7f2b6c07 'mut self' => 'self', remove pub 2021-03-07 14:59:10 +01:00
Aleksey Kladov 35347c2310 Improve readability
Using `Path`s for paths expresses intent more clearly.
2021-03-07 14:59:10 +01:00
Niklas Mohrin 694b31909a Change circle detection to use new more conservative method and run in main loop instead of before the loop 2021-02-28 23:04:49 +01:00
David Peter ca60937c2e Do not ignore non-existent BAT_CONFIG_PATH
Do not ignore `BAT_CONFIG_PATH` if it doesn't exist. Both when
generating a new config file with `--generate-config-file` and
when attempting to read the config.

Also, provide a better error message in case the file can not
be created.

closes #1550
2021-02-28 10:08:24 +01:00
David Peter 94496df3b0 Fix broken resolv.conf highlighting
closes #1510

The change in `create_highlighted_versions.py` fixes a "unknown theme
"'1337'" warning. The single quotes were wrong. `bat` was always falling
back to the default theme, so let's use that for now.
2021-02-16 22:15:31 +01:00
David Peter 7eabb5e05a Highlight *.pac files as JavaScript
closes #1515
2021-02-16 21:52:52 +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
Ethan P 025c5c061b Make less version check accept a path to the less binary 2021-02-16 09:11:27 +01:00
Caden Haustein 573f34d757
Update dependencies; replace unmaintained (#1522)
* Update dependencies; replace unmaintained

* Fix errors

* Revert dependency changes

* Revert git2 to 0.13.15

Co-authored-by: David Peter <mail@david-peter.de>
2021-02-16 08:50:41 +01:00
Martin Nordholts dc1620d1f0 get_pager(): Simplify use_less_instead expression 2021-01-11 21:56:10 +01:00
Martin Nordholts dd0d44bbb3 Fix #1413 Can't use `bat` at all! (Error: Use of bat as a pager is disallowed...)
Fixed by implementing the proposal by sharkdp:

* Allow PAGER=bat, but ignore the setting in bat and simply default to
  less. Unless of course, BAT_PAGER or --pager is used to overwrite the
  value of PAGER.

* Disallow the usage of bat within BAT_PAGER and --pager.
2021-01-11 21:56:10 +01:00
sharkdp 060b9981b5 Remove deprecated PrettyPrinter methods 2021-01-11 21:36:08 +01:00
sharkdp 1ae16fca90 Improve --map-syntax documentation, see #1386 2021-01-10 22:24:32 +01:00
Martin Nordholts 7809008016 PagerKind::from(): Simplify 2021-01-10 13:40:07 +01:00
Martin Nordholts dd6f57e107 pager.rs: Some comment fixups 2021-01-10 13:25:18 +01:00
Martin Nordholts dfe7a60140 PagerSource: [Bat]PagerEnvVar -> EnvVar[Bat]Pager 2021-01-10 13:16:09 +01:00
Martin Nordholts fc30277cfa pager.rs: Limit visibilities to pub(crate) 2021-01-10 13:07:37 +01:00
Martin Nordholts 02e6ff4183 Merge remote-tracking branch 'origin/master' into fix-1063 2021-01-10 11:56:03 +01:00
sharkdp c5c28eb05b --diagnostic: add MANPAGER environment variable 2021-01-09 21:56:17 +01:00
sharkdp cd7be018fe Fix clippy suggestion: .or_else(|| Some(…)) => .or(Some(…)) 2021-01-09 19:43:39 +01:00
sharkdp 03a2710a08 Use new matches!(…) macro to simplify code 2021-01-09 19:43:39 +01:00
sharkdp 09fbabb0b8 Add a Default implementation for PrettyPrinter 2021-01-09 19:43:39 +01:00
mark chaitin de6cb75f4b Addressed PR feedback. Upped min version and used matches! macro 2021-01-09 15:21:26 +01:00
mark chaitin 83c9cb7907 fix bug where long lines were truncated in plain mode without wrap=never not being set 2021-01-09 15:21:26 +01:00
Csaba Henk fed30b1b36 Fix theme dir hint in --list-themes output 2021-01-08 20:10:45 +01:00
Martin Nordholts da10166625 Merge remote-tracking branch 'origin/master' into fix-1063 2021-01-07 12:58:26 +01:00