Commit Graph

66 Commits

Author SHA1 Message Date
Anomalocaridid
ac2953c070 pass --no-lessopen to less by default 2023-09-08 06:25:20 +02:00
Nathan Fisher
5114c0189d
Add support for BusyBox less as pager (#2162)
* Add support for BusyBox less as pager

* Run tests/syntax-tests/update.sh to update tests

* Address reviewer's concerns with pull request
* Revert all changes in `test` directory
* Minimize overall diff size
* Detect busybox from separate helper function
* Pass equivalent options to BusyBox from same code by changing from long to
  short options

* Remove redundant `if` statement from previous commit
Add test for invalid utf-8
Add `parse_less_version_busybox` to test for invalid program
Add commenting around short options
2022-05-04 07:56:38 +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
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
Ethan P
025c5c061b Make less version check accept a path to the less binary 2021-02-16 09:11:27 +01:00
Martin Nordholts
dfe7a60140 PagerSource: [Bat]PagerEnvVar -> EnvVar[Bat]Pager 2021-01-10 13:16:09 +01:00
Martin Nordholts
02e6ff4183 Merge remote-tracking branch 'origin/master' into fix-1063 2021-01-10 11:56:03 +01:00
sharkdp
03a2710a08 Use new matches!(…) macro to simplify code 2021-01-09 19:43:39 +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
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
dcfe883f4b Simplify and polish pager.rs and related code 2020-12-28 22:39:34 +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
MarcoIeni
f5531cc7fa remove all matches 2020-11-23 14:25:01 +01:00
MarcoIeni
43b2ee5e71 fix some clippy warnings 2020-11-23 14:25:01 +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
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
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
sharkdp
48a7ce3bf2 Write error messages to pager, if attached
closes #946
2020-04-25 13:08:00 +02:00
sharkdp
8961f7aef8 Move PagingMode to separate module 2020-04-22 23:55:28 +02:00
sharkdp
702cb198da Rename error module 2020-04-22 23:55:28 +02:00
sharkdp
864656bd11 Pass --no-init on Windows if less version < 559
We used to call `less` with
``` bash
less --RAW-CONTROL-CHARS --quit-if-one-screen --no-init
```
We only passed `--no-init` because there was a bug with previous versions
of `less` which required the use of `--no-init` in combination with
`--quit-if-one-screen` to prevent this "no output" issue from happening.

Since bat 0.13, [we omit the `--no-init` option](0ecc94956b/src/output.rs (L85-L97))
if we can detect that the version of `less` is higher than or equal to 530. We
did that because `--no-init` breaks mouse support and because [less 530 fixed
the above-mentioned bug](http://www.greenwoodsoftware.com/less/news.530.html).
However, it seems that this bug was *not* fixed on Windows!

According to @gwsw, the issue should be fixed with less 559 on Windows.

closes #887
2020-04-21 18:18:03 +02:00
sharkdp
ce583eb9bf Revert "Pass '--mouse' to less versions >= 551"
This reverts commit cb21b74ecd.
2020-04-21 17:29:01 +02:00
sharkdp
3a195be14e Revert "Only enable --mouse when running from tmux, see #904"
This reverts commit 5f6e310152.
2020-04-21 17:28:37 +02:00
sharkdp
5f6e310152 Only enable --mouse when running from tmux, see #904 2020-04-21 16:15:02 +02:00
sharkdp
c386cb35fb Pass '--mouse' to less versions >= 551
When using `less` version 551 or newer, `bat` will now pass the `--mouse` argument, allowing
for (better) mouse scrolling support in some terminals.

closes #904
2020-04-21 10:00:32 +02:00
David Tolnay
42e3825daf Updates for review of PR 899 2020-03-31 09:27:56 +02:00
David Tolnay
014d754588 Move paging support behind a feature 2020-03-31 09:27:56 +02:00
David Tolnay
570805bc98 Strip dependencies of bat-as-a-library 2020-03-31 09:27:56 +02:00
sharkdp
a7338e2ea2 Run cargo fmt 2020-03-21 22:21:23 +01:00
sharkdp
9b8ddb24d1 move Config struct to separate file 2020-03-21 22:21:23 +01:00
sharkdp
e400ebd1bd Also pass '--no-init' if version could not be retrieved 2019-12-23 12:45:23 +01:00
sharkdp
67fe804256 Do not pass '--no-init' on newer less versions
With this change, we do not pass the `--no-init` option in newer
versions of less (530 or higher).

This fixes #749
2019-12-23 12:45:23 +01:00
Fahmi Akbar Wildana
2253d07341 Derive fmt::Debug whenever possible 2019-10-20 21:43:51 +02:00
Fahmi Akbar Wildana
0273848f54 Run cargo fmt 2019-10-20 21:43:51 +02:00
Fahmi Akbar Wildana
e542621125 Move back printer.rs and others into lib
others:
bin/bat/{controller,decorations,output,printer}.rs
2019-10-20 21:43:51 +02:00
Fahmi Akbar Wildana
cfd33168af Fix all compile errors in lib.rs 🚚
* Move {controller,output,printer,decorations}.rs into src/bin/

* Add `mod errors` from main.rs
2019-10-20 21:43:51 +02:00
Wild Kat
28266ee441 use explicit dyn with Write to appease compiler 2019-08-02 18:50:55 +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
f0771d6532 Do not replace arguments to pager when --pager is used, closes #509 2019-02-18 20:28:44 +01:00
sharkdp
6e8fca5bb2 Replace less command line arguments only for PAGER 2019-02-07 22:37:33 +01:00
Park Juhyung
63c77383ce Ignore flags from PAGER env var if the program is 'less' 2019-02-07 22:37:33 +01:00
sharkdp
7cac07d845 issue #383: Handle cases like PAGER=/usr/bin/bat 2018-11-06 19:53:32 +01:00
Rodrigo Orem
148caa1381 Fix code style 2018-11-06 19:35:41 +01:00