Repository: sharkdp/bat (language: rust)

Issue:
Bat displays escape codes when run with sudo and less -X or -F
<!-- Hey there, thank you for creating an issue! -->

**Describe the bug you encountered:**

```sh
❯ sudo bat .
[bat error]: '.' is a directory.
❯ sudo bat . --pager=less
[bat error]: '.' is a directory.
❯ sudo bat . --pager='less -F'
ESC[31m[bat error]ESC[0m: '.' is a directory.
❯ bat . --pager=less
[bat error]: '.' is a directory.
❯ bat . --pager='less -F'
[bat error]: '.' is a directory.
❯ bat .
[bat error]: '.' is a directory.
❯ sudo bat . --pager='less -X'
ESC[31m[bat error]ESC[0m: '.' is a directory.
```
![image](https://user-images.githubusercontent.com/13354331/138255530-e339544f-856e-47c3-ade9-420a95acaa78.png)


**What did you expect to happen instead?**

Adding options to the pager does not break coloring.

**How did you install `bat`?**

Arch

---

**bat version and environment**

#### Software version

bat 0.18.3 (b146958)

#### Operating system

Linux 5.14.9-arch2-1

#### Command-line

```bash
bat . '--pager=less -F' --diagnostic 
```

#### Environment variables

```bash
SHELL=/bin/zsh
PAGER=less
LESS=<not set>
BAT_PAGER=<not set>
BAT_CACHE_PATH=<not set>
BAT_CONFIG_PATH=<not set>
BAT_OPTS=<not set>
BAT_STYLE=<not set>
BAT_TABS=<not set>
BAT_THEME=<not set>
XDG_CONFIG_HOME=<not set>
XDG_CACHE_HOME=<not set>
COLORTERM=truecolor
NO_COLOR=<not set>
MANPAGER=<not set>
```

#### Config file

Could not read contents of '/root/.config/bat/config': No such file or directory (os error 2).

#### Compile time information

- Profile: release
- Target triple: x86_64-unknown-linux-gnu
- Family: unix
- OS: linux
- Architecture: x86_64
- Pointer width: 64
- Endian: little
- CPU features: fxsr,sse,sse2
- Host: x86_64-unknown-linux-gnu

#### Less version

```
> less --version 
less 590 (PCRE2 regular expressions)
Copyright (C) 1984-2021  Mark Nudelman

less comes with NO WARRANTY, to the extent permitted by law.
For information about the terms of redistribution,
see the file named README in the less distribution.
Home page: https://greenwoodsoftware.com/less
```


Discussion / hints:
Maybe bat goes with the default `-RF` when no parameter is given. Adding `-R` fixes it in either case.
Yes, we add `-R` when less is specified via PAGER. Not when using —pager with explicit args though, because in that case we trust users to know what they are doing. Code for that is here and below: https://github.com/sharkdp/bat/blob/ed3246c423932561435d45c50fd8cd9e06add7f5/src/output.rs#L77
Maybe that should be mentioned in the man-page
Oh and sudo makes a difference because I have `-R` in my `$LESS`

Fix patch:
diff --git a/assets/manual/bat.1.in b/assets/manual/bat.1.in
index b91f7dc8c8..aa521e3415 100644
--- a/assets/manual/bat.1.in
+++ b/assets/manual/bat.1.in
@@ -118,6 +118,8 @@ which pager is used, see the '\-\-pager' option. Possible values: *auto*, never,
 Determine which pager is used. This option will override the PAGER and BAT_PAGER
 environment variables. The default pager is 'less'. To control when the pager is used, see
 the '\-\-paging' option. Example: '\-\-pager "less \fB\-RF\fR"'.
+
+Note: By default, if the pager is set to 'less' (and no command-line options are specified), 'bat' will pass the following command line options to the pager: '-R'/'--RAW-CONTROL-CHARS', '-F'/'--quit-if-one-screen' and '-X'/'--no-init'. The last option ('-X') is only used for 'less' versions older than 530. The '-R' option is needed to interpret ANSI colors correctly. The second option ('-F') instructs less to exit immediately if the output size is smaller than the vertical size of the terminal. This is convenient for small files because you do not have to press 'q' to quit the pager. The third option ('-X') is needed to fix a bug with the '--quit-if-one-screen' feature in old versions of 'less'. Unfortunately, it also breaks mouse-wheel support in 'less'. If you want to enable mouse-wheel scrolling on older versions of 'less', you can pass just '-R' (as in the example above, this will disable the quit-if-one-screen feature). For less 530 or newer, it should work out of the box.
 .HP
 \fB\-m\fR, \fB\-\-map\-syntax\fR <glob-pattern:syntax-name>...
 .IP


Test patch: