Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I change man page colors? #170

Open
BarbzYHOOL opened this issue Dec 11, 2023 · 32 comments
Open

How can I change man page colors? #170

BarbzYHOOL opened this issue Dec 11, 2023 · 32 comments

Comments

@BarbzYHOOL
Copy link

Hello,
I set moar as the default pager
I had the same colors using LESS in the man pages

It's very dark and the worst is using the search tool and the result is highlighted but I see nothing, it's grey on grey

What can I do?

@walles
Copy link
Owner

walles commented Dec 12, 2023

Hello!

Please run the following commands and add their output to this issue:

  • env | grep '^LESS' | sort
  • echo $MOAR
  • moar --version

Also, please post a screenshot of what moar looks like for you.

@BarbzYHOOL
Copy link
Author

LESS=-FXMigR
-wrap -colors 16M
v1.18.4

image
image
In the last screenshot I looked for "palette"

@walles
Copy link
Owner

walles commented Dec 13, 2023

To verify that you actually did run env | grep '^LESS' | sort, could you post both the command line (env | grep '^LESS' | sort), its output and the prompt following it?

It looks like you have some LESS_xxx coloring variables set, and I want to verify that's the cause.

For example, here's what I get:

~/d/g/s/g/b/moar (master|✔) $ env | grep '^LESS' | sort
~/d/g/s/g/b/moar (master|✔) $

@BarbzYHOOL
Copy link
Author

BarbzYHOOL commented Dec 13, 2023

env | grep '^LESS' | sort                                                                                                                 00:18:32
LESS=-FXMigR

I'm not sure how LESS is related to MOAR tho

@walles
Copy link
Owner

walles commented Dec 14, 2023

For compatibility reasons, moar uses the formats declared in these environment variables if present:

But you do not have any of these set?

@BarbzYHOOL
Copy link
Author

no, i checked with "echo $LESS_TERMCAP_md" etc

@walles
Copy link
Owner

walles commented Dec 15, 2023

If you run this, do you still get the same problem?

man moar | LESS_TERMCAP_md= LESS_TERMCAP_us= LESS_TERMCAP_so= moar

If this doesn't help I think the next step would be to improve moar --help output to explain where moar is getting its colors from.

@BarbzYHOOL
Copy link
Author

Yes, it changes the result by highlighting the search result (the rest is not good looking)
So hmmm to have good looking man pages, what do I do?

image

@walles
Copy link
Owner

walles commented Dec 16, 2023

I'd suggest you play around with LESS_TERMCAP_md, LESS_TERMCAP_us and LESS_TERMCAP_so and set colors that you like.

Also try the --style parameter, unsure how that affects man pages but you should try!

See #14 and #114 for what the LESS_TERMCAP_xx variables affect, and https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters for inspiration.

Try https://chat.openai.com/ and see if it can guide you for how to set this up nicely for your shell!

@walles
Copy link
Owner

walles commented Dec 17, 2023

I thought about this some more and I think two things should be improved in moar.

  • Man page styling should default to being based on the --style option
  • moar --help output should include any LESS_TERMCAP_xxx settings affecting moar's output

walles added a commit that referenced this issue Dec 17, 2023
If present. Would have been useful for troubleshooting in #170.
@walles walles closed this as completed in 52516b2 Dec 17, 2023
@BarbzYHOOL
Copy link
Author

I don't understand the "--style" thing, without it asks for argument, and then I dunno what argument to type, I tried "style" or "api" nothing works

@BarbzYHOOL
Copy link
Author

BarbzYHOOL commented Dec 26, 2023

And to be fair, it doesn't work

 echo $LESS_TERMCAP_so                                                                                                                
\E[38;5;204m

I set it using fish shell with "set" but it does not change anything in the man page.

Also using "moar /etc/aliases" I can see the white highlight on search........ i don't get it

I even used these

set LESS_TERMCAP_mb '\E[01;31m'
set LESS_TERMCAP_md '\E[01;31m'
set LESS_TERMCAP_me '\E[0m'
set LESS_TERMCAP_se '\E[0m'
set LESS_TERMCAP_so '\E[01;44;37m'
set LESS_TERMCAP_ue '\E[0m'
set LESS_TERMCAP_us '\E[01;33m'

nothing changes anywhere

walles added a commit that referenced this issue Jan 10, 2024
Use GenericHeading style for man page headings.

Related to #170.
@walles
Copy link
Owner

walles commented Jan 10, 2024

From moar --help:

  -style value
    	Highlighting style from https://xyproto.github.io/splash/docs/longer/all.html

Does this help? You should pass moar a style listed on that page.

walles added a commit that referenced this issue Jan 10, 2024
Hopefully this change could have made this situation more obvious:
#170 (comment)
@postsolar
Copy link
Contributor

I set it using fish shell with "set" but it does not change anything in the man page.

Fish variables are not exported by default. For moar and other programs to know about these, you'd need to use set -x to make them exported. If you don't want to type it each time you can add it to your ~/.config/fish/config.fish, or use set -Ux. If you type help set in your fish shell you'll have the docs for this command open up.

@walles

This comment was marked as duplicate.

@walles
Copy link
Owner

walles commented Jan 11, 2024

On a related note, the latest release...

https://github.com/walles/moar/releases/tag/v1.22.2

... will syntax highlight man page headings as GenericHeading, making man pages look a bit nicer even without any configuration.

Here's what man moar looks like for me without any LESS... variables set and no --style option. This is with moar v1.22.2.

Skärmavbild 2024-01-11 kl  12 05 07

@BarbzYHOOL
Copy link
Author

BarbzYHOOL commented Jan 14, 2024

how is that good looking? it's just white, i see no difference except it's white lol

I told you I tried the "--style x" and it did nothing, I retried "--style witchhazel" and it did nothing

set -x changes nothing at all, I knew it but i tried just in case, cannot say I haven't tried everything here...

set -e LESS_TERMCAP_mb
set -e LESS_TERMCAP_md
set -e LESS_TERMCAP_me
set -e LESS_TERMCAP_se
set -e LESS_TERMCAP_so
set -e LESS_TERMCAP_ue
set -e LESS_TERMCAP_us

set -x LESS_TERMCAP_mb '\E[01;31m'
set -x LESS_TERMCAP_md '\E[01;31m'
set -x LESS_TERMCAP_me '\E[0m'
set -x LESS_TERMCAP_se '\E[0m'
set -x LESS_TERMCAP_so '\E[01;44;37m'
set -x LESS_TERMCAP_ue '\E[0m'
set -x LESS_TERMCAP_us '\E[01;33m'

image

image

tell me if i'm wrong

walles added a commit that referenced this issue Jan 14, 2024
@walles
Copy link
Owner

walles commented Jan 14, 2024

You must change the environment in the same terminal tab where you're running moar.

If you are changing the variables in one tab and running moar in the another that would explain a lot of the problems you're seeing here.

Also, '\E[01;31m' won't fly, if you're on fish you have to do \x1b'[01;31m'.

@BarbzYHOOL
Copy link
Author

BarbzYHOOL commented Jan 15, 2024

I never ran it in another tab lol, I set env variables for 10 years without issues

\x1b'[01;31m' no idea what all that stuff is, I've tried tons of different color codes from different pages, spent 1 hour testing all of them

I replaced by that thing and it still does nothing at all

set -x LESS_TERMCAP_mb \x1b'[01;31m'
set -x LESS_TERMCAP_md \x1b'[01;31m'

@postsolar
Copy link
Contributor

postsolar commented Jan 15, 2024

set -x MANROFFOPT '-c' should do the trick. But LESS_TERMCAP_so should work for the statusline even without it.

@walles I think $MANROFFOPT could be included in debug output the same way as $LESS_TERMCAP_* variables? From what I understand it's an obscure setting with very few mentions on the internet, and not all distros put it in /etc/profile or not all man implementations set -c as default, e.g. on Nix it seems it's not the case. But at the same time it influences behavior of moar the same way as $LESS_TERMCAP_*. It could be quite confusing. To quote man man on it:

  MANROFFOPT
         Every time man invokes the formatter (nroff, troff, or groff), it adds the contents of $MANROFFOPT to the formatter's command line.

To be extra clear, this would be an issue with less too. On my system, if I unset this variable neither moar nor less will display colors of the man pages (i.e. none but the status bar), even if less variables are correctly set.

walles added a commit that referenced this issue Jan 19, 2024
It was broken. Regression test added.

Related to #170.
@walles
Copy link
Owner

walles commented Jan 20, 2024

v1.23.1 fixes one problem in moar related to LESS_TERMCAP_xx handling.

Reopening this ticket since the discussion is still ongoing.

@walles walles reopened this Jan 20, 2024
@BarbzYHOOL
Copy link
Author

set -x MANROFFOPT '-c' changes nothing again

I updated moar and now the color changed a little as you pointed in your screenshot @walles it is now whiter than greyer ^^but that's all

@walles
Copy link
Owner

walles commented Jan 21, 2024

Try this (assuming you're using fish as your shell):

LESS_TERMCAP_md=\x1b'[01;31m' man moar
  1. If this has no effect, then this is a problem with moar
  2. If this makes certain text red, then this is a problem with your environment

Here's what this looks like to me:
red-man-page

@BarbzYHOOL
Copy link
Author

image
image

Same thing again

Or gimme the commands for bash and i'll try in bash.

Just in case, i TRIED THe same command in bash and here is the result, it's different and there is a background color (probably default) when searching...

image

@walles
Copy link
Owner

walles commented Jan 22, 2024

Try this: LESS_TERMCAP_md=\x1b'[01;31m' moar --help.

In the most recent versions of moar this should tell you what moar thinks of the LESS_TERMCAP_xx environment variables. Please send me the complete output of that command.

@BarbzYHOOL
Copy link
Author

Usage
  moar [options] <file>
  ... | moar
  moar < file

Shows file contents. Compressed files will be transparently decompressed.
Input is expected to be (possibly compressed) UTF-8 encoded text. Invalid /
non-printable characters are by default rendered as '?'.

More information + source code:
  <https://github.com/walles/moar#readme>

Environment
  Additional options are read from the MOAR environment variable.
  Current setting: MOAR="-wrap -colors 16M"
  LESS_TERMCAP_md (man page bold style): ESC[01;31m

Making moar Your Default Pager
  Put the following line in your ~/.bashrc, ~/.bash_profile or ~/.zshrc
  and moar will be used as the default pager in all new terminal windows:

     export PAGER=moar

Options
  -colors value
    	Highlighting palette size: 8, 16, 256, 16M, auto
  -debug
    	Print debug logs after exiting
  -follow
    	Follow piped input just like "tail -f"
  -lang value
    	File contents, used for highlighting. Mime type or file extension ("html"). Default is to guess by filename.
  -mousemode mode
    	Mouse mode: auto, select or scroll: https://github.com/walles/moar/blob/master/MOUSE.md
  -no-clear-on-exit
    	Retain screen contents when exiting moar
  -no-linenumbers
    	Hide line numbers on startup, press left arrow key to show
  -no-statusbar
    	Hide the status bar, toggle with '='
  -quit-if-one-screen
    	Don't page if contents fits on one screen
  -render-unprintable value
    	How unprintable characters are rendered: highlight or whitespace
  -scroll-left-hint value
    	Shown when view can scroll left. One character with optional ANSI highlighting.
  -scroll-right-hint value
    	Shown when view can scroll right. One character with optional ANSI highlighting.
  -shift amount
    	Horizontal scroll amount >=1, defaults to 16
  -statusbar style
    	Status bar style: inverse, plain or bold
  -style style
    	Highlighting style from https://xyproto.github.io/splash/docs/longer/all.html
  -trace
    	Print trace logs after exiting
  -version
    	Prints the moar version number
  -wrap
    	Wrap long lines
  +1234
    	Immediately scroll to line 1234

@walles
Copy link
Owner

walles commented Jan 23, 2024

Does this give you the color you ask for (still fish)?

PAGER=moar LESS_TERMCAP_md=\x1b'[01;31m' man moar

The help text indicates moar is not your current pager, or at least this version of moar isn't. Otherwise it wouldn't show the "Making moar Your Default Pager" section.

You might be using some other installation of moar as your PAGER.

Also, please do moar --version so I know where we are.

@postsolar
Copy link
Contributor

At least on some systems MANPAGER has precedence over PAGER, so MANPAGER=less PAGER=moar man moar will open less. I'd recommend running man moar | moar instead. Or like this for more assurance (assuming fish):

> set -e MANROFFOPT MANPAGER PAGER LESS_TERMCAP_mb LESS_TERMCAP_md LESS_TERMCAP_me LESS_TERMCAP_se LESS_TERMCAP_so LESS_TERMCAP_ue LESS_TERMCAP_us LESS LESSKEYIN_SYSTEM LESS LESSOPEN MOAR
> MANROFFOPT='-c' man moar | LESS_TERMCAP_md=\e'[01;31m' moar
> MANROFFOPT='-c' man moar | LESS_TERMCAP_md=\e'[01;31m' less

@BarbzYHOOL
Copy link
Author

Does this give you the color you ask for (still fish)?

PAGER=moar LESS_TERMCAP_md=\x1b'[01;31m' man moar

The help text indicates moar is not your current pager, or at least this version of moar isn't. Otherwise it wouldn't show the "Making moar Your Default Pager" section.

You might be using some other installation of moar as your PAGER.

Also, please do moar --version so I know where we are.

On fish you cannot put the export command like that, obviously it's the default pager since it opens moar when I type "man". Most likely your code tries to verify if it is set only on bash shells.
Hmm, in fact, I did something a bit special, lol. I set $PAGER to pager and set it as moar with update-alternatives command. I don't remember why but there was a purpose and maybe that's why it doesn't detect

My moar version is v1.23.3

@postsolar all the commands I press here open Moar, I can see the difference and you too from my screenshots

Ok so I pasted the last block of commands without trying to understand what it does. First of all, can you tell me why some people share commands with a > before (or another character)?
Secondly, here is the result, the top part of the screenshot is using these commands, the bottom one is normal moar

image

So the top terminalfinally has some background on search (but i lost the blue color on bold words)

@postsolar
Copy link
Contributor

On fish you cannot put the export command like that

You can since version 3.1.0

First of all, can you tell me why some people share commands with a > before (or another character)?

Don't know about others, or if it's an explicit convention, but I use it to indicate what is the command and what is the output, for example:

> echo 123
123

You'll also see $ used. There's also a convention that # prefix indicates running a command as root.

Ok so I pasted the last block of commands without trying to understand what it does

Well set -e ... you already know, the other two run moar and less with the right variables to see if it helps.

But what about less, does it look the same? Also, what distro are you on and which terminal do you use? And could you share your terminal's colorscheme (perhaps use fastfetch or neofetch to generate it)?

@walles
Copy link
Owner

walles commented Jan 25, 2024

@BarbzYHOOL maybe we should do a Google Meet call about this?

E-mail me (or send a calendar invite to) johan.walles@gmail.com. As for times let's try starting between 08:30CET and 20:00CET.

Seeing your screen live and talking to you directly would make this a lot easier to figure out I think.

@BarbzYHOOL
Copy link
Author

@postsolar here is what LESS looks with your command, a bit a different than MOAR
image

I'm on POPOS 22.04 using Tilix, maybe it's a bug with the terminal??

Here is my color scheme (custom)
image

@walles i cannot be there at these hours and I don't have this thing google meet (nor microphone)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants