You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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