Commit Graph

937 Commits

Author SHA1 Message Date
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
Ville Skyttä
7c41bd72da assets: add Debian ucf backups to ignored suffixes
Refs https://manpages.debian.org/bullseye/ucf/ucf.1.en.html
2021-08-29 19:55:00 +02:00
Martin Nordholts
27fa55d274
src/build_assets.rs: Refactor into smaller functions (#1822)
To make the code easier to work with.
2021-08-27 09:56:20 +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
Bojan Durdevic
c86a179412 PR comments addressed for line range +delta syntax 2021-08-23 19:55:41 +02:00
Bojan Durdevic
0748783404 Support for line range plus syntax 2021-08-23 19:55:41 +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
f5c1cb2dff Run 'cargo fmt' 2021-08-19 07:18:05 +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
deddc81426 src/assets.rs: Use ThemeSet::new() instead of BTreeMap::new() 2021-08-17 10:58:21 +02:00
Bill Risher
bf78288e9e feat(config): added recognition of $BAT_CONFIG_DIR 2021-08-14 22:02:58 +02:00
Martin Nordholts
89217e0d58 Make --no-paging and --no-pager work again 2021-08-09 13:37:56 +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
5236ed135e Fix typo in unreachable!(..) message for --wrap 2021-08-08 06:40:18 +02:00
Martin Nordholts
47d955a2ab Add code for analyzing dependencies between syntaxes
And also to generate independent SyntaxSets. This will later be used
to improve bat startup time.
2021-08-07 22:38:39 +02:00
Martin Nordholts
8ecd23eab4 Make --style docs reflect that 'full' is default
Closes #1742
2021-08-07 09:51:36 +02:00
Martin Nordholts
0331d28ee4 cargo fmt 2021-08-05 20:21:18 +02:00
Martin Nordholts
28eca6a2be Use assert!(..) instead of assert_eq!(true, ..)
This fixes all of these lint warnings:
https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison

They only appear in recent versions of clippy. Not on our MSRV.
2021-08-02 22:35:50 +02:00
Keith Hall
3b020fd95a
Merge pull request #1771 from sharkdp/warn_when_missing_contexts
Warn when building assets from files if some referenced contexts are missing
2021-08-02 22:55:37 +03:00
Keith Hall
50e1c6074f Warn when building assets from files if some referenced contexts are missing 2021-08-02 21:22:01 +03:00
Martin Nordholts
a610987ef7 assets::tests: Add get_syntax_name() helper
And instead of taking a get_syntax_set() detour to return a
name that represents "no syntax", return such a string directly.
2021-08-02 19:23:14 +02:00
Martin Nordholts
ffdf349a96 HighlightingAssets: Encapsulate theme_set behind a getter
Mainly to prepare for potential lazy-loading in the future to
improve startup performance. Like we did for syntax_set.
2021-07-29 21:30:03 +02:00
Martin Nordholts
6acec2c074 Reduce startup time in loop-through mode with 80%-90%
Instead of 100 ms - 50 ms, startup takes 10 ms - 5 ms.

HighlightingAssets::get_syntax_set() is never called when e.g. piping the bat
output to a file (see Config::loop_through), so by loading the SyntaxSet only
when needed, we radically improve startup time when it is not needed.
2021-07-29 20:36:05 +02:00
Martin Nordholts
1bac3750df HighlightingAssets: Move out fn get_integrated_*set() to module scope
They are just a way to get access to data embedded in the binary, so they don't
conceptually belong inside HighlightingAssets.

This has the nice side effect of getting HighlightingAssets::from_cache() and
::from_binary(), that are highly related, next to each other.
2021-07-29 20:36:05 +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
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
sharkdp
26136be903 Add --diagnostics alias 2021-01-06 22:53:51 +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
46487b201f Merge remote-tracking branch 'origin/master' into fix-1063 2021-01-06 14:30:55 +01:00
Niklas Mohrin
21ae26cb17 Add cycle detection with clircle, now v0.2 2021-01-05 18:21:16 +01:00
Martin Nordholts
bfa5342331 Also replace 'more' from PAGER with 'less'
But first do some quite significant refactorings to keep the code clean
and easy to understand.
2020-12-30 17:59:30 +01:00
Martin Nordholts
22bdc7c20f When PAGER=most, don't print a warning to stderr, silently use less instead 2020-12-30 08:25:39 +01:00
Martin Nordholts
552545fe5f Merge remote-tracking branch 'origin/master' into fix-1063 2020-12-28 22:48:52 +01:00
Martin Nordholts
dcfe883f4b Simplify and polish pager.rs and related code 2020-12-28 22:39:34 +01:00
Martin Nordholts
05e9da390f bat cache --build: Print syntect error message for themes if any
This will fix #614 by making it clear what is wrong by showing the
following error message:

    Failed to load one or more themes from
    '/Users/me/.config/bat/themes' (reason: 'Invalid syntax theme
    settings')

We also need to add a check if theme_dir.exists(), otherwise an absent
dir will seem like an error:

    Failed to load one or more themes from
    '/Users/me/.config/bat/themes' (reason: 'IO error for
    operation on /Users/me/.config/bat/themes: No such file or
    directory (os error 2)')

(This is the same check we already have for syntax_dir.)
2020-12-28 22:32:56 +01:00
Martin Nordholts
cc0f8ca813 Merge remote-tracking branch 'origin/master' into fix-1063 2020-12-28 21:57:38 +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
Martin Nordholts
47bb4a9c0f Introduce bat_warning! helper macro
This macro is intended to be package-internal and is not to be
considered part of the public lib API.

Use it in three places to reduce code duplication. However, main reason
for this refactoring is to allow us to fix #1063 without duplicating the
code yet another time.

The macro can also be used for the "Binary content from {} will not be
printed to the terminal" message if that message starts to use eprintln!
instead (if ever).

To trigger/verify the changed code, the following commands can be used:

    cargo run -- --theme=ansi-light tests/examples/single-line.txt
    cargo run -- --theme=does-not-exist tests/examples/single-line.txt
    cargo run -- --style=grid,rule tests/examples/single-line.txt
2020-12-28 09:27:40 +01:00
Martin Nordholts
6d1c7d5f57 Fix clippy::if_same_then_else warning in --paging=auto logic 2020-12-28 09:21:27 +01:00
Mitchell Kember
3099f51ba7 Add ansi theme to replace ansi-light and ansi-dark
This combines ansi-light and ansi-dark into a single theme that works
with both light and dark backgrounds. Instead of specifying white/black,
the ansi theme uses the terminal's default foreground/background color
by setting alpha=01, i.e. #00000001. This is in addition to the alpha=00
encoding where red contains an ANSI color palette number.

Now, `--theme ansi-light` and `--theme ansi-dark` will print a
deprecation notice and use ansi instead (unless the user has a custom
theme named ansi-light or ansi-dark, which would take precedence).
2020-12-21 17:05:10 +01:00
Lovecraftian Horror
b349155f2f Remove repeated contains calls 2020-12-21 09:41:29 +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
David Peter
73c16574e6
Merge branch 'master' into fix-1438-newline-can-be-added-even-if-style-plain 2020-12-21 08:22:01 +01:00
Martin Nordholts
68d525cd8b Don't add artificial newline to last line if --style=plain
This fixes #1438.

Note however, that using a pager such as less will add a newline itself.
So to actually not print a newline for such files, you need to either
disable paging:

  bat --style=plain --paging=never no-newline-at-end-of-file.txt

or use a "pager" that does not add a newline:

  bat --style=plain --pager=cat no-newline-at-end-of-file.txt

Note that we also update syntax tests file since a bunch of them had
missing newlines on the last lines.
2020-12-19 10:32:50 +01:00
Martin Nordholts
c3fc1b88fe replace_nonprintable: Keep \n around
Since it has a functional role, we can not just replace it, we must keep
it around. This also allows us to simplify the code slightly.

We must fix this before we fix #1438 since otherwise the \n will be
missing with --style=plain, since we will stop adding it if it is
missing.
2020-12-19 10:27:06 +01:00
rsteube
84b0702399 only print themes hint in interactive mode 2020-12-17 10:41:07 +01:00
Martin Nordholts
986d0e9777 Ignore PAGER=most by default with a warning to stderr
closes #1063
2020-11-27 06:47:46 +01:00
Martin Nordholts
f4202361b4 Add Pager helper with info about where the value comes from
In preparation of fixing issue #1063.
This is a pure refactoring with no intended functional side effects.
2020-11-27 06:42:58 +01:00
sharkdp
a6810e3353 Revert "Add io cycle detection with clircle"
This reverts commit aa2ae19dfd.
2020-11-24 21:40:11 +01:00
sharkdp
1fbdef06aa Use unreachable!(…) 2020-11-23 14:25:01 +01:00
MarcoIeni
f5531cc7fa remove all matches 2020-11-23 14:25:01 +01:00
MarcoIeni
2ccff145ed remove unuseful matches expression 2020-11-23 14:25:01 +01:00
MarcoIeni
43b2ee5e71 fix some clippy warnings 2020-11-23 14:25:01 +01:00
Niklas Mohrin
31793cfa62 Add io cycle detection with clircle 2020-11-23 14:06:54 +01:00
Ethan P
61f947a580
Merge pull request #1276 from tommilligan/style-rule
style: add component 'rule' for horizontal file delimiter
2020-10-31 23:14:00 -07: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
Adrian Rivera
9837948c3a Throws an error when bat is being user as pager.
As mentioned on #1334 `bat` should not be used as a value for `pager`,
this change checks both the balue of `bat` provided as a parameter or
as an environment variable.
2020-10-29 19:33:58 +01:00
Tom Milligan
3015ebfba1
disable rule when grid enabled, and print warning 2020-10-12 09:04:57 +01:00
Tom Milligan
aa4000cb0d
style: add component 'rule' for horizontal file delimiter 2020-10-12 09:04:27 +01:00
sharkdp
b3903175c8 Auto-format Rust code 2020-10-11 21:57:12 +02:00
gahag
6615eceb18 Code review: replace if let with equals operator 2020-10-08 18:51:42 +02:00
gahag
53f5a37f01 Code review
- Replace bools with enums
- Replace short flag with long flag
2020-10-08 18:51:42 +02:00
gahag
bbef2f41ec Add -S flag to less when --wrap=never (closes #1255)
Prevent less from wrapping lines by setting the proper flag when `--wrap=never`.
If the user set a custom value for `--pager`, no additional flag is set.
2020-10-08 18:51:42 +02:00
henil
8ff890635f add an after help NOTE 2020-10-04 06:33:11 +02:00
sharkdp
30993a8bfc Simplify code 2020-10-01 21:06:37 +02:00
sharkdp
2258fb2713 Remove .unwrap() in insert call to prevent crashes 2020-10-01 21:06:37 +02:00
sharkdp
a46191b8bf Remove .unwrap() to prevent crashes 2020-10-01 21:06:37 +02:00
sharkdp
9c4c3e965b Remove non-working unit test 2020-10-01 21:06:37 +02:00
Ahmed El Gabri
31acbe20d3 Support XDG_CONFIG_HOME git config files 2020-10-01 21:06:37 +02:00
sharkdp
32d22f464d Improve --style help text, closes #1146 2020-09-20 21:00:04 +02:00
sharkdp
71b2089384 Code formatting 2020-09-20 20:47:21 +02:00
sharkdp
57aa88a13a Improve --file-name help text, closes #1109 2020-09-20 20:43:30 +02: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
sharkdp
5df449bcf3 Remove unnecessary parenthesis 2020-09-14 11:24:14 +02:00
Alexander Karlis
6017989c4c removed printlns, updated Changelog, updated man 2020-09-14 11:24:14 +02:00
Alexander Karlis
d349974089 updated PR based on comments 2020-09-14 11:24:14 +02:00
Alexander Karlis
ccdea6a429 remove println 2020-09-14 11:24:14 +02:00
Alexander Karlis
fdf11326ef added additional alias for color=always when always-decorations flag is triggered 2020-09-14 11:24:14 +02:00
Alexander Karlis
565a80305c Added new alias for 'decoration=always' 2020-09-14 11:24:14 +02:00
Niklas Mohrin
ad18f070ae Adds custom mapping for nginx and apache config files 2020-09-14 10:36:22 +02:00
Kienyew
cab5ddf6ae Fix Typo 2020-08-12 06:45:24 +02:00
Mitchell Kember
f9d5e81f0e Add new theme: base16-256
Bat already has a base16 theme. The new base16-256 theme is for users
of base16-shell, who configure their terminal with a 256-color variant
of a base16 theme. These variants put some of the base16 colors in
elsewhere in the 256-color table to avoid clobbering bright color slots
(ansi codes 8 to 15) with colors that don't respect the ordinary meaning
of that slot (e.g. bright green in ordinary base16 is not green).

For more details, see https://github.com/chriskempson/base16-shell
2020-08-03 11:39:49 +02:00
sharkdp
2b3457e8d6 Update --help text for --color 2020-07-25 22:32:34 +02:00
Dash Peters
99819087f1 Switch to "·" (U+00B7) Middle Dot from "•" (U+2022) Bullet 2020-07-09 08:15:04 +02:00
Attila Gonda
a0b89a68d9 Update generated config to reflect pager argument behaviour 2020-07-09 08:13:52 +02:00
Dash Peters
c264f74771 Hide alias in help, update man and completions
A long alias doesn't make sense, since `--paging=never` already exists
2020-07-02 00:07:37 -07:00
Dash Peters
f53ea60ed4 Merge remote-tracking branch 'sharkdp/master' 2020-07-02 00:04:55 -07:00
David Peter
3a62e3d188
Merge pull request #1066 from gsomix/feature/1061-show-all-redirected
Enable non-printable characters for redirected output
2020-07-02 08:21:50 +02:00
Evgeniy Andreev (gsomix)
3c5ce9f86c Enable non-printable chars for redirected output (#1061) 2020-07-02 09:36:58 +04:00
Dash Peters
5fdeeabb44 Change to name no-paging, add long flag and alias 2020-07-01 21:35:45 -07:00
Dash Peters
2575aae945 Add short flag for --paging=never 2020-06-30 12:19:22 -07:00
Caio Alonso
fc121f0c87 Defaults *.fs to F# 2020-06-26 21:42:05 -03:00
Guido Cella
44deddbbfe Highlight pacman hooks as ini 2020-06-21 10:58:32 +02:00
Guido Cella
aa8a2b1769 Highlight systemd files as ini 2020-06-21 10:58:32 +02:00
sharkdp
19aa878a08 Remove explicit type annotation 2020-06-03 19:44:41 +02:00
sharkdp
9f52012443 Prevent allocation of additional Strings 2020-06-03 19:44:41 +02:00
sharkdp
e57e9b6dbb Use 'or_insert_with' 2020-06-03 19:44:41 +02:00
sharkdp
74e8373e34 Return mappings as a slice 2020-06-03 19:44:41 +02:00
sharkdp
ec2722d465 Use 'if let' instead of 'match' 2020-06-03 19:44:41 +02:00
Alex Novak
9e2ea5fdd4 Incorporating feedback 2020-06-03 19:44:41 +02:00
Alex Novak
48b4a6a906 Adds a little logic to main to get other mappings from config 2020-06-03 19:44:41 +02:00
Roy Ivy III
99226b745f Revert 9ed8db22c ('windows' pager process execution fix) based on PR feedback/owner request 2020-06-03 09:13:47 +02:00
Roy Ivy III
a2c09b41bc Fix pager process execution under 'windows'
## [why]

For 'windows' platforms, directly spawning a process (eg, called PATHNAME) bypasses the
usual windows shell machinery for determining which process to execute. Specifically,
the extensions in PATHEXT will not be used to determine the final executable. So,
`PATHNAME.bat`, `PATHNAME.cmd`, ... will *not* be executed even if on they exist on the
PATH; and this is counter to the usual expectation of a Windows user. Additionally,
built-in commands, such as `echo` and `dir`, will never be accessible as they do not
have a PATH to execute and, so, will never be found.

To use the usual machinery, giving access to PATHNAME.bat and `echo`, execute the PATHNAME
using the windows shell, eg `cmd /d/c PATHNAME`. Note this may expose the constructed
command line to the windows shell quoting vagaries (sadly, that may be part of the price).

Following Windows standards, the ComSpec environment variable is used to determine which
shell to use, with a fallback to the "modern", built-in `cmd` shell.
2020-06-03 09:13:47 +02:00
Roy Ivy III
9cc8e52512 Fix compiler warning for 'windows' tests (dead_code) 2020-06-03 09:13:47 +02:00
Ethan P
342cae2dc6 Change use of 'BatInput' to 'input::Input' 2020-05-29 22:13:10 +02:00
Ethan P
d2b26a5f1f Remove unnecessary '-> ()'s 2020-05-29 22:13:10 +02:00
Ethan P
9d08c0102e Replace Input::stdin_as_file with bat-application functions 2020-05-29 22:13:10 +02:00
Ethan P
a3357547ea Remove unused with_name for theme preview file 2020-05-29 22:13:10 +02:00
Ethan P
7a9decad70 Remove Input.as_file and add Input::stdin_as_file 2020-05-29 22:13:10 +02:00
Ethan P
a8d7141c4c Improve documentation for Input API 2020-05-29 22:13:10 +02:00
Ethan P
0f06d3b90d Reexport bat::pretty_printer::Input as bat::Input 2020-05-29 22:13:10 +02:00
Ethan P
589c94aa93 Fix regression with --list-themes and --language 2020-05-29 22:13:10 +02:00
Ethan P
798b742617 Refactor InputDescription API into Input API 2020-05-29 22:13:10 +02:00
Ethan P
11a72ab765 Fix a typo 2020-05-29 22:13:10 +02:00
Ethan P
0319149b4d [breaking] Remove special handling for theme previews 2020-05-29 22:13:10 +02:00
Ethan P
2f823d59b0 Add PrettyPrinter::input function 2020-05-29 22:13:10 +02:00
Ethan P
981352992b Add InputDescription API 2020-05-29 22:13:10 +02:00
Ethan P
384ea38bd9 Add documentation to InputDescription 2020-05-29 22:13:10 +02:00
Ethan P
8b481dd41f Add support for NO_COLOR env var (#1021) 2020-05-28 21:49:10 +02:00
sharkdp
9cb43ef64d Update tests 2020-05-27 10:09:57 +02:00
sharkdp
bd17fd571f Switch from path-absolutize to path_abs
closes #1022
2020-05-26 08:11:26 +02:00
sharkdp
8f1babf346 Mark 'vcs_modification_markers' as deprecated 2020-05-25 11:51:10 +02:00
sharkdp
fa25695b74 Make 'vcs_modification_markers' change non-breaking 2020-05-25 11:51:10 +02:00
sharkdp
943b1f82b6 Fix syntax detection for symlinks
closes #1001
2020-05-24 17:32:43 +02:00
sharkdp
c4031ad65c Fix syntax detection for files called 'rails'
closes #1008
2020-05-24 11:27:42 +02:00
Ethan P
35b6067496 Print error message when invalid syntax is specified 2020-05-16 13:44:26 +02:00
Ethan P
5aa20c090b Refactor HighlightingAssets::get_syntax to return Result type 2020-05-16 13:44:26 +02:00
Ethan P
887e61a99d
Allow application to be built without git support
Caveats:
The help descriptions aren't changed with you remove the "git" feature.
2020-05-15 13:58:48 -07:00
Ethan P
0aca8cab0b
Remove vcs_modification_markers from PrettyPrinter 'git' feature disabled 2020-05-15 13:58:48 -07:00
Ethan P
b8687bc969
Merge branch 'master' of github.com:sharkdp/bat into string-input 2020-05-15 13:22:24 -07:00
Ethan P
cc52f79e42
Add helper fn for checking if opened input is theme preview file 2020-05-15 12:20:20 -07:00
Ethan P
59140b458c
Consolidate syntax detection behavior for all InputKind types 2020-05-13 02:53:30 -07:00
Ethan P
157b8dd848
Rename test for checking if inputkinds are consistent 2020-05-13 00:47:18 -07:00
Ethan P
1fb669ae1a
Test that OrdinaryFile consistent with CustomReader 2020-05-13 00:38:56 -07:00
Ethan P
7d07aa395a
Change assets.rs tests to use InputKind::CustomReader
This should avoid errors in filesystems that don't
support UTF-8 or invalid UTF-8.
2020-05-13 00:38:41 -07:00