[223] | 1 | $Id: NOTES 820 2006-04-19 11:50:24Z sam $ |
---|
| 2 | |
---|
| 3 | o Colour does not work with all backends and all terminals. I tested |
---|
| 4 | many terminal emulators and tried to summarise which combinations |
---|
| 5 | worked properly and which ones did not. |
---|
| 6 | |
---|
[226] | 7 | From termcap(5): |
---|
| 8 | |
---|
| 9 | set_a_background setab AB Set background |
---|
| 10 | color to #1, using |
---|
| 11 | ANSI escape |
---|
| 12 | set_a_foreground setaf AF Set foreground |
---|
| 13 | color to #1, using |
---|
| 14 | ANSI escape |
---|
| 15 | From the xterm terminfo: |
---|
| 16 | |
---|
| 17 | setab=\E[4%p1%dm, setaf=\E[3%p1%dm |
---|
| 18 | |
---|
| 19 | From the xterm-16color terminfo: |
---|
[230] | 20 | (http://www.sct.gu.edu.au/~anthony/info/X/Xterm_xf86.terminfo) |
---|
[226] | 21 | |
---|
| 22 | setab=\E[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm, |
---|
| 23 | setaf=\E[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm, |
---|
| 24 | |
---|
[230] | 25 | These values can be simply retrieved with a tigetstr() call. |
---|
[226] | 26 | |
---|
[225] | 27 | o I tested the following terminals: |
---|
[223] | 28 | |
---|
[225] | 29 | name $TERM $COLORTERM |
---|
| 30 | ------------------------------------------ |
---|
| 31 | Linux console linux |
---|
| 32 | pterm xterm |
---|
| 33 | aterm xterm rxvt-xpm |
---|
| 34 | wterm xterm wterm-xpm |
---|
| 35 | Eterm xterm Eterm |
---|
| 36 | xterm xterm |
---|
| 37 | gnome-terminal xterm |
---|
| 38 | konsole xterm |
---|
| 39 | mlterm mlterm |
---|
| 40 | uxterm xterm |
---|
| 41 | |
---|
| 42 | o In most terminals, \e[3xm and \[4xm respectively set the foreground |
---|
[226] | 43 | and background colours. x is a colour between 0 and 7 or the value |
---|
| 44 | 9 for default colour (may be transparent). |
---|
[225] | 45 | |
---|
| 46 | \e[0m sets everything to normal, \e[1m sets bold, \e[5m sets blink |
---|
| 47 | and \e[7m sets inverse video. |
---|
| 48 | |
---|
| 49 | In ncurses, only 64 colour pairs are created, and A_BOLD (\e[1m) and |
---|
| 50 | A_BLINK (\e[5m) are used for foreground/background colour highlighting, |
---|
| 51 | hence creating 256 possible colour pairs. |
---|
| 52 | |
---|
| 53 | Different tests of blue on yellow: |
---|
| 54 | |
---|
| 55 | for invert in '' '\e[7m'; do |
---|
| 56 | for blink in '' '\e[5m'; do |
---|
| 57 | for bold in '' '\e[1m'; do |
---|
[226] | 58 | echo -ne "$bold$blink$invert"'\e[33m\e[44m'hop'\e[0m ' |
---|
[225] | 59 | echo "($bold$blink$invert)" |
---|
| 60 | done |
---|
| 61 | done |
---|
| 62 | done |
---|
| 63 | |
---|
| 64 | Successfully works on: |
---|
| 65 | + Linux console |
---|
| 66 | + pterm |
---|
| 67 | + Eterm |
---|
| 68 | + aterm, wterm, rxvt |
---|
| 69 | |
---|
| 70 | Almost works on: |
---|
[226] | 71 | + xterm (bright bg only works when fg is bright and then inverted, |
---|
| 72 | but then fg is not bright) |
---|
[225] | 73 | |
---|
| 74 | Fails on: |
---|
| 75 | + mlterm (no bright colours, neither fg nor bg) |
---|
| 76 | + gnome-terminal (no bright bg) |
---|
| 77 | + konsole (no bright bg, $blink really blinks) |
---|
| 78 | |
---|
[230] | 79 | o In an XTerm-compatible terminal, \e[9xm sets bright foreground |
---|
| 80 | and \e[10xm bright background colours. Documentation on this can be |
---|
| 81 | found at http://ftp.xfree86.org/pub/XFree86/4.2.1/doc/ctlseqs.TXT . |
---|
| 82 | Unfortunately all terminals don't support these escape sequences. Here |
---|
| 83 | is a testcase: |
---|
[225] | 84 | |
---|
| 85 | for fgpre in 3 9; do for fg in 0 4 2 6 1 5 3 7; do |
---|
[223] | 86 | for bgpre in 4 10; do |
---|
[225] | 87 | echo -ne '\e['$fgpre$fg'm' |
---|
[223] | 88 | for bg in 0 4 2 6 1 5 3 7; do echo -ne '\e['$bgpre$bg'm# '; done |
---|
[225] | 89 | echo -ne '\e[0m ' |
---|
[223] | 90 | done |
---|
| 91 | echo '' |
---|
| 92 | done; echo ''; done |
---|
| 93 | |
---|
[225] | 94 | Successfully tested on: |
---|
| 95 | + gnome-terminal |
---|
| 96 | + konsole |
---|
| 97 | + xterm |
---|
| 98 | + pterm |
---|
[223] | 99 | |
---|
[226] | 100 | Failed (\e[9x and \e[10x don't do anything) on: |
---|
[225] | 101 | + Eterm |
---|
| 102 | + aterm, wterm, rxvt |
---|
| 103 | + mlterm |
---|
[226] | 104 | + Linux console |
---|
[223] | 105 | |
---|
[226] | 106 | o How to draw bright colours on any terminal? |
---|
| 107 | |
---|
| 108 | '\e[93;104m' -> bright yellow on bright blue |
---|
| 109 | doesn't work on mlterm, gnome-terminal, konsole |
---|
| 110 | |
---|
| 111 | '\e[5;1;33;44m' -> bright yellow on bright blue |
---|
| 112 | doesn't work on mlterm, aterm/wterm/rxvt, Eterm, console |
---|
| 113 | |
---|
| 114 | '\e[5;1;33;44;93;104m' -> bright yellow on bright blue |
---|
| 115 | works on gnome-terminal, xterm, pterm, aterm/wterm/rxvt, console |
---|
| 116 | doesn't work on konsole |
---|
| 117 | |
---|
[223] | 118 | o MS-DOS: all bright colours, bright backgrounds, and bright combinations |
---|
[225] | 119 | work using <conio.h>. No need to kludge anything. |
---|
[223] | 120 | |
---|
[336] | 121 | o Win32: we use GetConsoleScreenBufferInfo etc. There is an interesting |
---|
| 122 | tutorial here: http://www.adrianxw.dk/SoftwareSite/index.html |
---|
[331] | 123 | |
---|
[343] | 124 | o Set terminal window title: |
---|
| 125 | http://mail.gnome.org/archives/mc-devel/2003-January/msg00101.html |
---|
| 126 | |
---|