Wednesday, December 18, 2013

Midnight Commander color scheme

Midnight Commander (or "mc") can have transparent panels instead of the ugly, dull default blue. So can "mcedit", its text editor.

Here's how to do it. Edit the file ~/.mc/ini and add at the end the following:


[Colors]
base_color=normal=,default:selected=,:marked=,default:\
markselect=,:menu=,:menuhot=,:menusel=,:\
menuhotsel=,:dnormal=,:dfocus=,:dhotnormal=,:dhotfocus=,:\
input=,:reverse=,:executable=,default:directory=,default:\
link=,default:device=,default:special=,:core=,:helpnormal=,:\
helplink=,:helpslink=,:editnormal=,default:

Note #1: In the above 'code' block, there is only one line below [Colors]. I truncated the line with the backslash because of blogspot rendering issues. You just write all that on one single line, without the "\" (backslash-es).

Note #2: At the end of this line, the "editnormal,=default:" option means that mcedit will have transparent background in your console, as well.


To my great shame, I didn't pay too much attention to this blog or to the comments asking for further advice. I found Mateus' comment rather late (just now!) and decided to dig further, in order to find out how exactly to deal with more refined color changes, while still keeping the transparent background (in both in Midnight Commander and its editor).


So the first thing to know is which are the colors that Midnight Commander supports; the available colors are:

black
gray
lightgray
white
red
brightred
green
brightgreen
blue
brightblue
magenta
brightmagenta
cyan
brightcyan
brown
yellow
default

The "default" color is the one giving out the nice transparency.

Now, there are certain "components" in Midnight Commander's display that can have their colors altered. Here they are:

base_color, normal, selected, marked, markselect, errors, menu, reverse, dnormal, dfocus, dhotnormal, dhotfocus, viewunderline, menuhot, menusel, menuhotsel, helpnormal, helpitalic, helpbold, helplink, helpslink, gauge, input, directory, executable, link, stalelink, device, core, special, editnormal, editbold, editmarked, errdhotnormal, errdhotfocus

Each and every one of these "components" can have its own colors set accordingly to the user's wish. Each component is assigned a color pair and must be followed by a colon (':') in order to separate it from the color pair of the next component. Here's how this basic syntax must look like:

component=foreground_color,background_color:

When you start modifying the color scheme in your Midnight Commander configuration file (located at ~/.mc/ini), you just have to add a section called "[Colors]" and proceed with enumerating the color pairs. So you'd have something like this:

# the rest of your ~/.mc/ini file

[Colors]
component1=foreground_color1,background_color1:...:componentN= foreground_colorN,background_colorN

For increased readability, I will "truncate" that long line, adding a backslash ('\') to indicate that in fact what follows on the next line should be adjacent to the text on the previous line. This being said, the [Colors] section could look like this:

# the rest of your ~/.mc/ini file

[Colors]
component1=foreground_color1,background_color1:\
component2=foreground_color2,background_color2:\
...
componentN=foreground_colorN,background_colorN

Now that you've gotten the hang of this, let's see how the [Colors] section looks like in the default Midnight Commander color scheme (you know, the "ugly" one, with blue and dull cyan):

IMPORTANT NOTE: For visual impact's sake and due to Blogspot breaking long lines, I wrote each color pair on a single row, followed by a backslash ('\'). Please note that this does NOT work in the ~/.mc/ini file, so the final [Colors] section in your Midnight Commander configuration file MUST be a SINGLE line with no spaces and with each color pair separated from the next one by a colon (':').

# the rest of your ~/.mc/ini file

[Colors]
base_color=lightgray,blue:\
normal=lightgray,blue:\
selected=black,cyan:\
marked=yellow,blue:\
markselect=yellow,cyan:\
errors=white,red:\
menu=white,cyan:\
reverse=black,lightgray:\
dnormal=black,lightgray:\
dfocus=black,cyan:\
dhotnormal=blue,lightgray:\
dhotfocus=blue,cyan:\
viewunderline=brightred,blue:\
menuhot=yellow,cyan:\
menusel=white,black:\
menuhotsel=yellow,black:\
helpnormal=black,lightgray:\
helpitalic=red,lightgray:\
helpbold=blue,lightgray:\
helplink=black,cyan:\
helpslink=yellow,blue:\
gauge=white,black:\
input=black,cyan:\
directory=white,blue:\
executable=brightgreen,blue:\
link=lightgray,blue:\
stalelink=brightred,blue:\
device=brightmagenta,blue:\
core=red,blue:\
special=black,blue:\
editnormal=lightgray,blue:\
editbold=yellow,blue:\
editmarked=black,cyan:\
errdhotnormal=yellow,red:\
errdhotfocus=yellow,lightgray

Now let's see. What you want to change first of all is most of the background of these "components", such that the display will be one with a neat looking transparent background. So first of all you might want to make a few changes to these color pairs by replacing the background color "blue" with "default". After doing these changes, your [Colors] section will look a bit like this:

# the rest of your ~/.mc/ini file

[Colors]
base_color=lightgray,default:\
normal=lightgray,default:\
selected=black,cyan:\
marked=yellow,default:\
markselect=yellow,cyan:\
errors=white,red:\
menu=white,cyan:\
reverse=black,lightgray:\
dnormal=black,lightgray:\
dfocus=black,cyan:\
dhotnormal=blue,lightgray:\
dhotfocus=blue,cyan:\
viewunderline=brightred,default:\
menuhot=yellow,cyan:\
menusel=white,black:\
menuhotsel=yellow,black:\
helpnormal=black,lightgray:\
helpitalic=red,lightgray:\
helpbold=blue,lightgray:\
helplink=black,cyan:\
helpslink=yellow,default:\
gauge=white,black:\
input=black,cyan:\
directory=white,default:\
executable=brightgreen,default:\
link=lightgray,default:\
stalelink=brightred,default:\
device=brightmagenta,default:\
core=red,default:\
special=black,default:\
editnormal=lightgray,default:\
editbold=yellow,default:\
editmarked=black,cyan:\
errdhotnormal=yellow,red:\
errdhotfocus=yellow,lightgray

Now you've got the basic "Midnight Commander transparent scheme" that was the result of this post.

Proceeding to Mateus' question, regarding how to change the rest of the colors now, it's about the same as before. What he didn't like there (and as a matter of fact I don't quite like it, either) is the dull cyan that's still seen in the following places:

  1. the bottom line (the one displaying the F1...F10 function keys);
  2. the line that signifies the current selection, the "prompt" which shows you on which file/directory you're "on" at a given moment;
  3. the uppermost line (the "menu" line);
  4. the menus themselves, once you open them.
To "fix" issues 1, 2, and 3 it is sufficient to alter the value of the "selected" parameter. Notice how it is initially

selected=black,cyan:\

My personal choice is to replace the background cyan, which I don't really like, with green. To do this, I'll change this color pair to

selected=black,green:\

You can, of course, change the foreground color as well. For me, it's alright to keep the foreground (the text) "black". You can change it to whatever suits your taste.

To "fix" issue number 4 in the list above, you need to change the "menu" parameter. To get it transparent, just change the "cyan" background to "default". Make other adjustments as you see fit. In other words, change

menu=white,cyan:\

into, for instance,

menu=ligthgray,default:\

However, there are a few "leftovers" from the default color scheme.

One of them is the parameter regarding the hotkeys in the menus (the "underlined" character on most of the menu options, showing you what key you can press in order to access that option faster than by moving to it with the arrow keys). This color pair is called "menuhot". I changed it from

menuhot=yellow,cyan:\

into

menuhot=yellow,default:\

Another thing which might bother you is the color of the line in the panel you're in when you've "selected all" files (when you've pressed the "*" key). This parameter is called "markselect". I changed it from

markselect=yellow,cyan:\

into

markselect=white,green:\

The color pair of the selected buttons in dialogs is called "dfocus". I changed mine from

dfocus=black,cyan:\

into

dfocus=black,green:\

In the "focused" buttons or options, the underlined character is called "dhotfocus". I changed mine from

dhotfocus=blue,cyan:\

into

dhotfocus=brightgreen,green:\

since the background color was already green, after I modified the "dfocus" color pair.

The other buttons or options in the dialogs which have hotkeys assigned to them, but which are not "focused" (the buttons/options that you're not located on at a given moment) are still displayed in blue on a light gray background. This color pair is referred to as "dhotnormal". Since the blue looks a bit odd there, I changed

dhotnormal=blue,lightgray:\

into

dhotnormal=brightgreen,default:\

Well, this is nice, in window titles and on normal (unfocused) hotkeys I get the transparent background. The problem now is that the rest of the dialog window is still light gray. To change this (to make the window transparent as well), you only need to alter the "dnormal" color pair, such as changing it from

dnormal=black,lightgray:\

into

dnormal=white,default:\

You may notice that the input fields stay cyan, as well; you find these fields in quite a lot of dialog boxes. To alter this, I changed

input=black,cyan:\

into

input=black,green:\

One thing which I consider useful is to have symbolic links displayed in bright cyan (as in the colored listings in the terminal). So I just changed

link=lightgray,default:\

into

link=brightcyan,default:\

Now, regarding the rest of the color pairs, I don't really know what they do. However, if at some point after using Midnight Commander more with this new, neat, transparent/green color scheme you'll notice unwanted leftovers, you can try out other changes in the color pairs values, one at a time, until you determine the troublesome one.

After operating the changes above, my [Colors] section in ~/.mc/ini now looks like this:

[Colors]
base_color=lightgray,default:\
normal=lightgray,default:\
selected=black,green:\
marked=yellow,default:\
markselect=white,green:\
errors=white,red:\
menu=lightgray,default:\
reverse=black,lightgray:\
dnormal=white,default:\
dfocus=black,green:\
dhotnormal=brightgreen,default:\
dhotfocus=brightgreen,green:\
viewunderline=brightred,default:\
menuhot=yellow,default:\
menusel=white,black:\
menuhotsel=yellow,black:\
helpnormal=black,lightgray:\
helpitalic=red,lightgray:\
helpbold=blue,lightgray:\
helplink=black,cyan:\
helpslink=yellow,default:\
gauge=white,black:\
input=black,green:\
directory=white,default:\
executable=brightgreen,default:\
link=brightcyan,default:\
stalelink=brightred,default:\
device=brightmagenta,default:\
core=red,default:\
special=black,default:\
editnormal=lightgray,default:\
editbold=yellow,default:\
editmarked=black,cyan:\
errdhotnormal=yellow,red:\
errdhotfocus=yellow,lightgray

I need to direct you to the "IMPORTANT NOTE" above. The final [Colors] section above is written like this - one pair on each row, followed by a backslash - for clarity's sake. The actual final [Colors] section in your ~/.mc/ini file will have to be a one-liner, with no blanks and no backslashes. So it will probably look similar to this:

base_color=lightgray,default:normal=lightgray,default:selected=black,green:marked=yellow,default:markselect=white,green:errors=white,red:menu=lightgray,default:reverse=black,lightgray:dnormal=white,default:dfocus=black,green:dhotnormal=brightgreen,default:dhotfocus=brightgreen,green:viewunderline=brightred,default:menuhot=yellow,default:menusel=white,black:menuhotsel=yellow,black:helpnormal=black,lightgray:helpitalic=red,lightgray:helpbold=blue,lightgray:helplink=black,cyan:helpslink=yellow,default:gauge=white,black:input=black,green:directory=white,default:executable=brightgreen,default:link=brightcyan,default:stalelink=brightred,default:device=brightmagenta,default:core=red,default:special=black,default:editnormal=lightgray,default:editbold=yellow,default:editmarked=black,cyan:errdhotnormal=yellow,red:errdhotfocus=yellow,lightgray

Now, the next time you start mc, the new color scheme will take effect.

As a bonus, here's a picture of how my Midnight Commander looks like, with this new "skin" on: