Open LangLangBart opened 1 day ago
Perhaps I'm not fully understanding, but if you're not using less for paging but only for adding coloring, I'm not sure that it's the right tool for the job. It seems like you could do what you want with a simple sed script or something like that.
Perhaps I'm not fully understanding
The request is to introduce an optional flag that retains the colors when the output is not a tty device.
For similar use cases, git
offers the --color=always
flag. However, less
currently lacks such a feature.
I'm not sure that it's the right tool for the job.
That is the question: do you think less
should be able to do this or not?
Whatever you decide will be accepted.
It seems like you could do what you want with a simple sed script or something like that
For the use case outlined in the description of the issue, one can also use
bat --color=always -pl man
, but it would look better with less
.
Problem
When a user defines
LESS_TERMCAP_xx
, these colors are not applied when the output of less is going to a non-interactive terminal.Consider this Docker command as an example:
In an interactive terminal,
FOO
is displayed in bold blue. However, if you run the same Docker command without the--tty
flag,FOO
is not colored or bold.<img src="https://github.com/user-attachments/assets/4a959740-1e61-45b8-a9e8-868e259d162d" width="600">
Feature Request
Would it be possible to add a new option that forces
LESS_TERMCAP_xx
colors to be retained when the output ofless
goes to a non-interactive terminal?More context
My use case involves
fzf
and its--preview
window, which executes the command in non-interactive mode[^1].The command downloads a html file using
curl
, and thehtml2text
transforms intotext
but retains backspaces. Finally,less
would make the output more readable by adding the user-definedLESS_TERMCAP_xx
colors.Currently, the result looks like this:
<img src="https://github.com/user-attachments/assets/971f5dbb-d34f-4b46-ba4d-59d48b732633" width="400">
But I would like it to look like this inside
fzf's
preview window:<img src="https://github.com/user-attachments/assets/30136f69-ad5b-464f-a8c0-2eac6832e7be" width="400">
[^1]:
less
functionality is reduced in preview window · Issue #1118 · junegunn/fzf