summaryrefslogtreecommitdiffstats
path: root/src/printer.rs
AgeCommit message (Collapse)Author
2024-03-11style: simplify equality checkHamir Mahal
2024-03-10refactor: remove reference that is unnecessaryHamir Mahal
2024-02-25Inline `format!` args wherever possibleLena
2024-02-24Add squeeze functionality to `SimplePrinter`einfachIrgendwer0815
2024-02-24Add --squeeze-limit to specify max number of consecutive empty linesEthan P
Co-authored-by: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com>
2024-02-24Add --squeeze/-s optionEthan P
Co-authored-by: einfachIrgendwer0815 <85333734+einfachIrgendwer0815@users.noreply.github.com>
2024-02-11Skip syntax parsing when color output disabledEthan P.
2024-02-11Split syntax highlighting from print_line into fnEthan P.
This simplifies the `print_line` function a little bit while also providing a way for syntax highlighting to be skipped when it's not being used (i.e. `--color=never`).
2024-02-09Remove hyperlink when wrapping linesEthan P
2024-02-09Replace AnsiCodeIterator in printer.rsEthan P
This uses the new EscapeSequenceIterator, saving us a preprocessing step for each line.
2024-02-09Strip OSC sequences before printingEthan P
This commit strips OSC (Operating System Command) sequences before printing lines. Eventually when time permits, I want to add back support for printing OSC sequences (and improve it to treat hyperlinks like an attribute). Until then, this should help prevent garbled output :)
2024-01-21Attempt to fix integration testFilip Razek
2024-01-21Run cargo fmtFilip Razek
2024-01-21fix: Wrap file name in headerFilip Razek
2023-10-05Replace our own macros to write buffers with standard macrosrhysd
2023-09-01Merge pull request #2618 from Piturnah/feat/write-to-bufferDavid Peter
feat: Optionally write to a buffer instead of stdout
2023-09-01Clippy lintsPeter Hebden
2023-09-01Handle todosPeter Hebden
2023-09-01Fix signaturesPeter Hebden
2023-09-01Add `OutputHandle` enum to use instead of `&mut dyn io::Write`Peter Hebden
2023-09-01Replace unmaintained `encoding` with `encoding_rs`rhysd
2023-03-24Use `nu-ansi-term` instead of `ansi_term`Constantin Nickel
The `nu-ansi-term` crate is a fork of `ansi_term` which is maintained by the Nushell project.
2023-03-15Merge pull request #2502 from Enselic/clippy-1.68David Peter
Fix clippy warnings with Rust 1.68
2023-03-14Print non-printable characters using caret notation (#2443)einfachIrgendwer0815
When the new flag is set, non-printable characters are printed using caret notation.
2023-03-14Fix clippy warnings with Rust 1.68Martin Nordholts
2022-09-10Revert "Remove code that tries to handle ANSI escape inputs"Martin Nordholts
This reverts commit 8174e022797924aec735ff440806920767f80496. 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-06Strip BOM from output in interactive mode (#1938)dag-h
* 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-08-29Remove code that tries to handle ANSI escape inputs (#2189)Martin Nordholts
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-05-07Bump to syntect 5.0.0 to e.g. start lazy-loading syntaxes (#2181)Martin Nordholts
* 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-05printer.rs: De-duplicate code to highlight long linesMartin Nordholts
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-04Skip syntax highlighting for long lines (#2165)Keith Hall
* Skip highlighting for long lines * Run cargo fmt, update changelog
2022-02-14Underline highlighted lines in ANSI theme (#1985)Mahdi Dibaiee
* Underline highlighted lines in ANSI theme * add test for ansi highlight underline, fix underscore in plain
2022-02-07Add new `--style` called `header-filesize` and display it by default (#1988)Mahdi Dibaiee
Also rename `header` to `header-filename`. Related to #1701
2021-12-08Improved ANSI passthrough (#1596)Ethan P
Improve handling of ANSI passthrough. Fix ANSI passthrough for --wrap=never. Add test for ANSI passthrough.
2021-09-29src/printer.rs: Simplify Plain Text fallback codeMartin Nordholts
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-22src/printer.rs: Add HighlighterFromSet helperMartin Nordholts
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-12Use deref coercion to simplify some argument passingMarcin Puc
2021-09-12Improve iterator usageMarcin Puc
2021-09-12Reduce nesting in if blocks by short circuitingMarcin Puc
2021-08-26Replace deprecated 'error-chain' with 'thiserror' (#1820)Martin Nordholts
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-19Fix all lints that are new with Rust 1.54Martin Nordholts
They are all of the following type: https://rust-lang.github.io/rust-clippy/master/index.html#needless_borrow
2021-08-08When returning a SyntaxReference, also return the SyntaxSet that contains it ↵Martin Nordholts
(#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-07-29HighlightingAssets: Make .syntaxes() and syntax_for_file_name() failableMartin Nordholts
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-19HighlightingAssets: Encapsulate syntax_set behind a getterMartin Nordholts
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-05-27Use the functional update syntaxMohamed Abdelnour
2021-01-09Addressed PR feedback. Upped min version and used matches! macromark chaitin
2021-01-09fix bug where long lines were truncated in plain mode without wrap=never not ↵mark chaitin
being set
2020-12-21Add ansi theme to replace ansi-light and ansi-darkMitchell Kember
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-19Don't add artificial newline to last line if --style=plainMartin Nordholts
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-19replace_nonprintable: Keep \n aroundMartin Nordholts
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.