I am using GNU nano version 4.8 on Ubuntu 20.04 LTS.
I have X11 set up to use white as the background colour of the xterm window. I don't want to change this setting. It looks like nano inherits this, and use white as its global background colour.
The default syntax highlighting for PHP (and other languages) seems to assume that the background colour in the nano editor is some dark colour. For instance these line from php.nanorc
:
# Function names.
color white "\<[A-Za-z_][A-Za-z_0-9]*\("
makes function names white, which of course is unreadable on a white backround.
Changing it to this;
# Function names.
color white,black "\<[A-Za-z_][A-Za-z_0-9]*\("
improves things a bit. It now makes the function name, but only the function name, display with a white font on a black background. But it also looks ugly, as everything else has a white background.
Is there a way to change the background in the nano edit to not re-use the terminal default colour, but black instead?
Here is a solution I came up with while looking around. We can use escape sequences to change terminal colors dynamically.
To do that we can create a function named
nnano
for example and store it somewhere like~/.bashrc
so it get sourced automatically when we open a new instance of bash.Then to use it:
It first changes the background color of terminal to
black
then when we close thenano
it changes it to white.Here is the function which can be improved a lot more:
If you don't flip the foreground color:
Idea comes from here.
It's not what exactly you want (A dark/black background). I'm not even sure if that thing is possible to do. Because as you said it yourself
nano
inherits its colors fromxterm
. Although you might be able to runxterm
using different configuration when you are planing to runnano
.However I believe if you create a
.Xresources
file containing a complete set of colors, then you shouldn't have any problem.Here is mine. The first part is for
urxvt
to make it look a little bit better. You can just ignore these lines. Pay attention to the last part of the file which is specifying the colors.I just changed the background and foreground colors to create something visually similar to what you want.
keep in mind that my colors have been configured to use a dark background. You can change them to get a really better output. For example after changing yellow color to black:
Don't forget to run
xrdb -merge ~/.Xresources
after editing the '~/Xresources` file.Here is a shot from
xterm
: