Sunday, September 6, 2009

Editing Midnight Commander's color scheme

In a previous post I was sort of laying out a "formula" on how to transform your Midnight Commander default color scheme into a trasnparent skin, without talking too much about how you can change the other colors.

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:

26 comments:

  1. Hello Jared! Nice to see you around. As for social networking sites, I'm not into them at all.

    ReplyDelete
  2. neither am I- I use it to keep track of bands, but I couldn't put my name without a website... you'll see that I have no "human" friends :P

    ReplyDelete
  3. So, why'd you quit? I'm not asking you to come back or anything, but it IS a lot loess lively now. ;)

    ReplyDelete
  4. Damn, sorry to spam, but I have to. less*

    ReplyDelete
  5. Nice pic ;)

    Jared, you can e-mail/IM me. I'm sure I left some contact details when I left.

    Well, I left because I realized that my other interests were taking too much of my time and would not allow me to play FRP anymore, taking care of the administrating/social issues as well.

    Now I'm just working, learning and reading mainly.

    ReplyDelete
  6. I was going to email you originally, but I noticed the email address was @futurerp.

    The few times I've been on IM, you haven't. :P

    ReplyDelete
  7. still can't get the bar at the bottom to change... no matter what options i change, the numbers are still white/black and the text is always black/cyan :(

    ReplyDelete
  8. Damn. You're right. Something changed in the meantime. I'm sure it did, otherwise the above screenshot would make no sense. Up until this something-got-broken-in-mc unfortunate event, the "status bar" (the menu with the F1...F10 options) was afected by the "selected=foreground/background" keyword.

    ReplyDelete
  9. How to fix the problem decribed above?

    ReplyDelete
  10. i have the same problem with F's menu color =(

    ReplyDelete
  11. this fixes some colors back to transparent for mc 4.7.5

    statusbar=light,default
    menunormal=lightgreen,default

    ReplyDelete
  12. do you have a fix for this? id like to have the same colors as the screen shot but so far its not working

    ReplyDelete
  13. this is a Response to the last post
    as it was me and I found the answer

    If you go into your terminal profile and change the cyan color in the colors section to green or whatever you want it will change on Midnight Commander.

    hope this was helpful!

    ReplyDelete
  14. Hello this work for me, but when I "sudo mc" nothing change the default color BLUE background is appeared back.
    Is this a bug that MC having. I can't seem to get transparency while I'm in sudo. Is it something thing do with the owner ship. I would say it's only work for user
    not globally. Any suggestion is greatly appreiciated.

    thanks

    ReplyDelete
  15. This, and all others have one issue: if you write some code and place some tab characters then you will be disturbed by cyan background of this characters

    ReplyDelete
  16. For the life of me I can't seem to find where the Midnight Commander config files are stored, because ".mc" is not under /home/username anymore!!

    DAMN I wish Linux devs would stop shuffling things around....

    FC

    ReplyDelete
  17. Damn. I will answer myself. With the help from the Fedora mailing list... the config files are now in

    ~/.config/mc/
    plus
    ~/.local/share/mc/
    for other files.

    FC

    ReplyDelete
  18. Reading is about pattern recognition, so what's the point of the background pattern?

    ReplyDelete
  19. The background of the site is very annoying

    ReplyDelete
  20. Great job for publishing such a beneficial web site. Your web log isn’t only useful but it is additionally really creative too. cheap printing services

    ReplyDelete
  21. I understand this column. I realize You put a many of struggle to found this story. I admire your process. Disposable Setting Tool

    ReplyDelete
  22. Great and that i have a keen supply: Whole House Renovation Cost Calculator Canada home additions near me

    ReplyDelete