Commit Graph

137 Commits

Author SHA1 Message Date
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
Mohamed Abdelnour 304ee1489c Use `!theme.is_empty()` 2021-05-27 12:05:07 +02:00
Sean McLoughlin d89fa3ebc2 Add SystemVerilog support 2021-03-15 07:21:15 +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
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 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 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
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
Kienyew c477e23fe9 Handle file extension conflicts in --list-languages 2020-09-20 12:14:21 +02:00
Caio Alonso fc121f0c87 Defaults *.fs to F# 2020-06-26 21:42:05 -03:00
Roy Ivy III 9cc8e52512 Fix compiler warning for 'windows' tests (dead_code) 2020-06-03 09:13:47 +02:00
Ethan P 0319149b4d [breaking] Remove special handling for theme previews 2020-05-29 22:13: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 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 5aa20c090b Refactor HighlightingAssets::get_syntax to return Result type 2020-05-16 13:44:26 +02: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
Ethan P f39487fca9
Make syntax detection more consistent for Reader and File inputs 2020-05-11 19:44:09 -07:00
Lzu Tao e37e9c1214 Fix some clippy lints
Some might actually improve perf
2020-04-24 16:11:05 +02:00
sharkdp 261a7ea154 Add *_with_name methods 2020-04-22 23:55:28 +02:00
sharkdp 53a973e9dd Add syntaxes and themes method 2020-04-22 23:55:28 +02:00
sharkdp 702cb198da Rename error module 2020-04-22 23:55:28 +02:00
sharkdp 26c951fec4 Fix warnings, sort imports, input from string 2020-04-22 23:55:28 +02:00
sharkdp 590960f7f5 Completely refactor 'input' module 2020-04-22 23:55:28 +02:00
sharkdp f3b90ddb38 Add InputDescription 2020-04-22 23:55:28 +02:00
sharkdp f8d0956893 Rename InputFile => Input 2020-04-22 23:55:28 +02:00
sharkdp 1dc328ad49 Separate inputs from config 2020-04-22 23:55:28 +02:00
sharkdp 057e4eced1 Large refactoring towards a better builder structure 2020-04-22 23:55:28 +02:00
sharkdp 2e9cf63a5f Fix compilation of library 2020-04-21 18:14:31 +02:00
sharkdp 72618db179 Add metadata information to cached assets
When saving/reading user-provided syntaxes or themes, `bat` will now maintain a
`metadata.yaml` file which includes information about the `bat` version which was
used to create the cached files. When loading cached files, we now print an error
if they have been created with an incompatible version

closes #882
2020-04-21 18:14:31 +02:00
sharkdp 34619a2e89 Small refactoring, handle invalid UTF-8 filenames 2020-04-21 08:57:15 +02:00
Kyle Criddle 83d408bab3 Extract common syntax functionality to helper fns 2020-04-21 08:57:15 +02:00
sharkdp 1b8ce60054 Pass stdin as a generic BufRead, fix stdin tests 2020-04-21 08:57:15 +02:00
sharkdp 90e7d2fe33 Rename field name, new constructors 2020-04-21 08:57:15 +02:00
Kyle Criddle 04fa84aea7 Moved user_provided_filename to be contained within OrdinaryFile struct 2020-04-21 08:57:15 +02:00
Kyle Criddle a3f8140fbe Use --file-name to detect syntax highlighting
Closes #891
2020-04-21 08:57:15 +02:00
sharkdp eb2f3ddb7c Rename test methods 2020-03-22 11:02:51 +01:00
sharkdp dfd3ef022e Add more default mappings, reverse traversal 2020-03-22 11:02:51 +01:00
sharkdp 57aed07814 Use absolute path for lookup in database 2020-03-22 11:02:51 +01:00
sharkdp bd8a13dbc9 Initial implementation of glob-based syntax mapping 2020-03-22 11:02:51 +01:00
sharkdp 32346612b7 Move syntaxes, fixes #874 2020-03-21 23:53:53 +01:00
sharkdp dfe5eb3e98 Add an even simple example 2020-03-21 22:21:23 +01:00
sharkdp 8c500a7e40 Hide get_syntax, move tests to module 2020-03-21 22:21:23 +01:00
sharkdp acf51bd7b3 Rename methods and parameters 2020-03-21 22:21:23 +01:00
sharkdp 83dc13a86d Add fallback theme, remove BAT_THEME_DEFAULT 2020-03-21 22:21:23 +01:00
sharkdp 094c526a0e Hide some methods from HighlightingAssets 2020-03-21 22:21:23 +01:00
sharkdp 62f2d0c100 Do not export syntax_set and theme_set 2020-03-21 22:21:23 +01:00
sharkdp 7e0115641d Move error module to separate file 2020-03-21 22:21:23 +01:00
sharkdp 06b7be7ee9 Major restructuring of theme/syntax handling 2020-03-21 19:19:15 +01:00
Fahmi Akbar Wildana 2253d07341 Derive fmt::Debug whenever possible 2019-10-20 21:43:51 +02:00
Fernando Mendes c9d7e3652b Enforce the creation of the full cache dir path
Fixes #576
2019-05-30 22:28:52 +02:00
Daniele Esposti 82f14121bd Applied linter fixes 2019-03-09 07:43:41 +01:00
Daniele Esposti a21ae614e6 Migrated to Rust 2018 2019-03-09 07:43:41 +01:00
sharkdp 54143d1403 Add --cache-dir option 2019-02-07 22:19:32 +01:00
sharkdp 10965a6122 Implement syntax mapping
This adds a `-m`/`--map-syntax` option that allows users to (re)map
certain file extensions or file names to an existing syntax.

For example:
```
bat --map-syntax .config:json
```

The option can be use multiple times. Note that you can easily make
these mappings permanent by using `bat`s new configuration file.

closes #169
2018-10-17 23:08:19 +02:00
sharkdp 1ae02c65fb Fix include 2018-10-16 22:09:15 +02:00
sharkdp 8275b0436d Add simple configuration file
This allows users to create simple configuration file
(`~/.config/bat/config` on Linux) that has the following format:

    ```bash
    --flag1
    --flag2
    --option1=value1
    # lines beginning with '#' are ignored
    --option2=value2
    # empty lines and trailing whitespace are also ignored

    --option3=value3
    ```
2018-10-16 22:09:15 +02:00
sharkdp 5842d58c01 Updates for syntect 3.0 2018-10-09 22:04:51 +02:00
sharkdp e97095b724 Use first-line detection for STDIN 2018-10-07 15:34:37 +02:00
sharkdp f98fc5f06a Simplify access to first line 2018-10-07 15:34:37 +02:00
sharkdp 0502a3bd4a Add first-line detection for all input types
closes #205
2018-10-07 15:34:37 +02:00
sharkdp 860f3e9006 Move InputFile to separate module 2018-10-07 15:34:37 +02:00
sharkdp 8cacd9b432 Include theme_preview file in binary 2018-08-28 20:24:13 +02:00
sharkdp 9316f2a758 Major refactoring and cleanup 2018-08-22 22:29:12 +02:00
sharkdp 052425b12f Load customized themes in addition to defaults
- New themes in `$BAT_CONFIG_DIR/themes` are now loaded *in addition* to
  the default themes (they may also override).
- The `Default.tmTheme` symlink is not necessary anymore.

This relates to #172
2018-08-20 21:39:21 +02:00
sharkdp 2df3305b94 Add new '--blank' option for 'bat cache --init'
closes #206
2018-08-20 21:34:08 +02:00
sharkdp 1dddce3aa1 Separate syntax set and theme set
This commit separates the handling of syntax sets and theme sets. It
also changes the way how new syntax definitions are loaded from `bat`'s
configuration folder. New syntax definitions are now loaded *in
addition* to the ones that are stored in the `bat` binary by default.

This fixes #172
2018-08-19 11:08:23 +02:00
sharkdp 5b421b455d Update dependencies 2018-08-18 20:44:25 +02:00
sharkdp 28397b8f78 Always show a warning when theme is unknown 2018-07-23 21:51:49 +02:00
Armando Perez c68aa0f424 Allow specifying the theme via the `BAT_THEME` environment variable
The `--theme` command line option stills takes precedence and this
change preserves how errors are handled when it's used: If a theme name
that doesn't exist is specified using the argument, this error is fatal.
However, if a theme that doesn't exist is specified using the environment
variable, the error is logged to `stderr` and the "Default" theme is
loaded as a fallback.
2018-07-23 21:51:49 +02:00
sharkdp a348a9f68e Handle syntax-set loading errors 2018-05-25 22:42:06 +02:00
Gert Hulselmans 65bb4c7ee6 Print themes directory in error message if no themes could be loaded from it.
Before this patch:
    $ bat cache --init
    [bat error]: Could not load themes from '{}'

After:
    $ bat cache --init
    [bat error]: Could not load themes from '/home/user/.config/bat/themes'
2018-05-24 09:09:23 +02:00
Ezinwa Okpoechi 2712d63a4b Move asset clearing to assets module 2018-05-21 23:20:45 +02:00
sharkdp 2a9f5a24ed Permissive error handling, closes #17 2018-05-19 12:50:41 +02:00
Ezinwa Okpoechi 247dfbee83 Extract syntax finding to assets module 2018-05-18 16:45:59 +02:00
sharkdp c826c2a438 Better error handling 2018-05-16 22:55:37 +02:00
sharkdp 145b99f01c Include syntaxes and themes in repository
This changes a few things:

- All syntaxes and themes are now stored (as submodules) under
  assets/syntaxes and assets/themes

- The default directories for syntaxes and themes are "syntaxes"
  and "themes" (used to be "syntax" and "themes")

- The "bat cache" command can now take a `--source <dir>` and
  `--target <dir>` option.

- The cached files have been renamed to "themes.bin" and "syntaxes.bin"
2018-05-16 22:04:12 +02:00
Ryan Leung 22c8978fca add theme option (#95)
closes #89
2018-05-11 13:53:17 +02:00
sharkdp e2ac6de783 Fix clippy warnings 2018-05-10 13:15:59 +02:00
Ezinwa Okpoechi 25cee002f9 Split modules (#86)
* Split diffing to separate module
* Split assets to separate module
2018-05-10 12:36:09 +02:00