Color listing in xterm terminal - linux

I installed a minimal debian and i'm trying to set everything by myself, so i'm trying to tune my default terminal Xterm by giving it some colors, after some research i found that this can be done either by editing the .Xresources file so i can give the first 16 colors in Hexa code (#numbers) or by editing the .bashrc file.
After some research seems like the second solution is more dynamic 'cause i can specify the colors of files by extensions, the problem is that all the articles on the net use a color code very weird :
.gz 01;31
.bz2 01;31
.deb 07;31
.rpm 01;31
.jar 01;31
I want to know if there's a way to use RGB code color or hexa color so i can have more flexibility with my directory and files listings.

AFAIK, there is no RGB support, terminal emulators are limited to display a limited set of colors (a palette with 64 combinations of foreground and background, if I'm not mistaken). If ease of use is what concerns you, you can always declare several variables for the predefined colors, something like:
readonly BLACK_FONT_BLACK_BACKGROUND='30;40'
readonly BLACK_FONT_RED_BACKGROUND='30;41'
readonly BLACK_FONT_GREEN_BACKGROUND='30;42'
readonly BLACK_FONT_YELLOW_BACKGROUND='30;43'
...
readonly WHITE_FONT_CYAN_BACKGROUND='37;46'
readonly WHITE_FONT_WHITE_BACKGROUND='37;47'
And use them later like:
.gz $BLACK_FONT_YELLOW_BACKGROUND
The following is a table with the color codes for foreground and background:
Color Foreground Background
-------------------------------
black 30 40
red 31 41
green 32 42
yellow 33 43
blue 34 44
magenta 35 45
cyan 36 46
white 37 47
-------------------------------
If generating all the color names variables manually is too tedious, you can use the following python script:
colors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];
index = 0
for x in ["{0}_FONT_{1}_BACKGROUND='{2};{3}'".format(colors[i].upper(), colors[j].upper(), i + 30, j + 40) for i in xrange(0, 8) for j in xrange(0, 8)]:
print x.ljust(38) + "#" + str(index)
index += 1

I'm sorry, but you can't use the RBG color code (or HSV, or HCL). You may find the documentation with:
$ man 5 dir_colors

As noted by #Leonardo Fontenelle, the place to start reading about GNU ls coloring is the dir_colors manual page. The numbers used, such as 01;31 are the constants associated with what the manual page refers to as "ISO 6429 (ANSI) color sequences". Actually the manual page is a little more obscure than it ought to be:
the constants are parameters used in the ISO 6429 SGR (set graphic rendition) control sequence. The actual standard is very detailed (see ECMA-48).
01 happens to be the standard code for bold (the manual refers to it using the Linux-centric "brighter colors*).
as noted by #higuaro, codes 30-37 and 40-47 form a color palette; all of the colors shown on the terminal at any moment come from the current palette.
there is more than one way to update the color palette used by xterm; none of those are directly related to the ls configuration because the numbers used for referring to the palette do not contain the color information by themselves.
you can display the colors and video attributes using the ncurses tput utility, e.g., tput setaf 7.
some (relatively) recent ls configurations use additional color codes outside the 30-37 / 40-47 palette, e.g., for the aixterm 16-color feature, or the xterm 88-colors or 256-colors. The dir_colors manual page does not mention this.

Related

Temporarily colour Linux Terminal foreground and background text

How can I temporarily set the colors of my Linux Terminal? I wish to add to a script, a color setting so that I remember to run the partner script a few minutes later. The color change would be set on in one script and removed in the other and would act as a visible reminder to me.
So the color change needs to be applied after the terminal is started up and needs to stay for all subsequent typing until it is removed by another equivalent command.
My terminal is GNOME Terminal 2.31.3
There's more than one way to change colors. VTE (the actual terminal within GNOME Terminal) implements these features (generally from xterm):
"ANSI color" escapes (which would be useless to you, since many programs reset those)
changing the text foreground and background using non-ANSI dynamic colors (resetters are rare)
changing the color palette (again, resetters are rare)
The latter two are documented in XTerm Control Sequences, in the section Operating System Commands:
OSC Ps ; Pt BEL
OSC Ps ; Pt ST
gives the form of the control sequence, e.g., escape]Ps;PtBEL
The dynamic colors are described here:
The 10 colors (below) which may be set or queried using 1 0
through 1 9 are denoted dynamic colors, since the correspond-
ing control sequences were the first means for setting xterm's
colors dynamically, i.e., after it was started. They are not
the same as the ANSI colors. These controls may be disabled
using the allowColorOps resource. At least one parameter is
expected for Pt. Each successive parameter changes the next
color in the list. The value of Ps tells the starting point
in the list. The colors are specified by name or RGB specifi-
cation as per XParseColor.
and other colors here:
Ps = 4 ; c; spec -> Change Color Number c to the color spec-
ified by spec. This can be a name or RGB specification as per
XParseColor. Any number of c/spec pairs may be given. The
color numbers correspond to the ANSI colors 0-7, their bright
versions 8-15, and if supported, the remainder of the 88-color
or 256-color table.

what's the meaning of color[0-15] in urxvt settings?

First, I've searched the topics on google.com, but not help a lot.
I've configured my urxvt using some color themes, but it's really hurt my eyes. So, I decided to create my own using some Vim color pallete. I really need to know what's the meaning of color0 - color15 in urxvt .Xdefaults or .Xresources setting. What's the purpose of those colors? Anyone knows?
The purpose of those colors is to be colors.
Terminal emulators usually let you define the 16 "ASCII" colors:
Normal Bright
-------- -------
0 Black 8 Black
1 Red 9 Red
2 Yellow 10 Yellow
3 Green 11 Green
4 Blue 12 Blue
5 Magenta 13 Magenta
6 Cyan 14 Cyan
7 White 15 White
Where the "Normal" colors are usually darker and the "Bright" ones lighter.
As noted, there is no such thing as "ASCII" colors, no matter how many. "ANSI" colors also is problematic, since ANSI (referring to the defunct x3.64 standard) never specified 16 colors.
urxvt's color0-color15 resource names are inherited from rxvt's simulation of X resource settings. (X resources are usually managed by X Toolkit, which neither uses). urxvt's manual page considers these too well known to mention any details. rxvt would search for resource settings using both "XTerm" and "Rxvt" classnames, and in so doing incorporated several resource names from xterm. urxvt (which started as a translation of rxvt into C++) dropped that (searching for "XTerm") feature in 2004, but kept most of the other rxvt resource names.
Those names were defined in xterm (see manual), for these two ranges:
color0-color7 -- These specify the colors for the ISO-6429 extension. The defaults are, respectively, black, red3, green3, yellow3, a customizable dark blue, magenta3, cyan3, and gray90. The default shades of color are chosen to allow the colors 8-15 to be used as brighter versions.
color8-color15 -- These specify the colors for the ISO-6429 extension if the bold attribute is also enabled. The default resource values are respectively, gray30, red, green, yellow, a customizable light blue, magenta, cyan, and white.
The second range is a different type of "extension": ISO-6429 does not define escape sequences which might correspond to those. Rather, xterm combines two features into one palette:
SGR 90-107 (aixterm's extended control sequences for 16-colors, incorporated in xterm in 1997).
"PC-colors" (an alternative to treat bold as bright colors to work around font problems -- also from 1997).

Is it possible to change xterm "color table" at runtime?

I have my xterm inherit RGB values for its "color table" from an X resource file. As far as I understand, xterm does not just support 256 colors - it supports 256 color references pointing each to a 24-bit RGB space color, correct?
I would like to be able to reset the colors themselves, for example change the color with index 10 to an RGB value #ff8000 or something.
I don't even know if I have got my concepts right here. If I have, is it possible to change entries in this "color table" at runtime - for the current terminal window? Or one can only do so with xrdb for next opened terminal instance?
I'm not sure if this actually works (my xterm here isn't compiled with 256 color support!) but the xterm control sequence reference:
http://invisible-island.net/xterm/ctlseqs/ctlseqs.html
Look under "Operating System Controls"
P s = 4 ; c ; spec → Change Color Number c to the color specified by spec. This can be a name or RGB specification as per XParseColor. Any number of c name pairs may be given. The color numbers correspond to the ANSI colors 0-7, their bright versions 8-15, and if supported, the remainder of the 88-color or 256-color table.
OSC is \033], so try this out:
echo -n -e '\033]4;7;red\007'
should change color #7 to red if it works.

Redhat Linux - change directory color

I am using Redhat Linux and the problem I am facing is that the "blue" colour of the directories is hardly visible on the black background. I found some posts on the web which asks to change some settings in the file /etc/profile.d/colorls.sh and /etc/profile.d/colorls.csh. However, this will change the colour settings for everyone who logs into the system. Could someone please let me know how I can change the colour settings that will affect only me?
To specify the colors of the output of ls, you need to set LS_COLORS. In your .zshrc, try adding:
LS_COLORS="$LS_COLORS:di=00;33"
34 is blue, 33 is ... yellowish. Change that number and find what you like.
Use dircolors to get a feel for what LS_COLORS should look like and add -p to see a color list.
Joachim's answer is good for fixing the specific issue of directories, but if any other utilities output using the "blue" color, you will find them just as unreadable.
Different terminal emulators have different settings for changing the colors; my terminal emulator of choice reads X resources to determine what colors to use:
URxvt.color0: #000000
URxvt.color1: #A80000
URxvt.color2: #00A800
URxvt.color3: #A8A800
URxvt.color4: #0000A8
URxvt.color5: #A800A8
URxvt.color6: #00A8A8
URxvt.color7: #A8A8A8
URxvt.color8: #000054
URxvt.color9: #FF0054
URxvt.color10: #00FF54
URxvt.color11: #FFFF54
URxvt.color12: #0000FF
URxvt.color13: #FF00FF
URxvt.color14: #00FFFF
URxvt.color15: #FFFFFF
color4 is the blue in question; I have mine set like this:
URxvt.background: #000000
URxvt.foreground: gray75
URxvt.color3: DarkGoldenrod
URxvt.color4: RoyalBlue
URxvt.color11: LightGoldenrod
URxvt.color12: LightSteelBlue
URxvt.color7: gray75
URxvt.colorBD: #ffffff
URxvt.colorUL: LightSlateGrey
URxvt.colorIT: SteelBlue
URxvt.cursorColor: grey90
URxvt.highlightColor: grey25
This gives a black background, not-too-bright foreground, and most other colors are reasonable enough. (I too found the default blue unreadable.) I put these into my ~/.Xresources file, and they take effect after log in or after merging this file with the X resources database: xrdb -merge ~/.Xresources.
Of course, different terminals are configured differently. Check your terminal's manpage for more details on changing the colors of the usual colors.
You can see what is done in the global file, and then add it to your private ~/.profile (or similar file.)
samolod solution is good.
In case of KDE konsole you go to
Settings -> Edit current profile -> Appearance -> Edit -> Color 5.
Then use graphical color chooser to make it brighter (I picked #5871FF).

Color hex calculation

I have a picture, i choose a color on the picture like:
#18212d
rgb: 24 33 45
when i colorize that picture by increased hue with 6 (202 => 208), saturation with 4 (25 => 29) (using photoshop), old color above was turned into new color:
#19232c
rgb: 25 35 44
Have any ways to calculate a new color of another old color after colorized? I need that to colorize all my css file.
You need to convert all your colors to HSV, manipulate it and convert it back to RGB. You need to understand how different color system works. This page is a good reference,
http://www.easyrgb.com/index.php?X=MATH
This page lists all the algorithms. You can also find open source code in just about any language you use. For Javascript, Dojo, YUI all have conversion functions built-in.

Resources