TITLE: IBM 3164 Colors <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -O- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PROBLEM DISCUSSION: Color handling on a 3164 is not obvious. The terminals with which most AIX users are most familiar, such as the HFT and aixterm, permit independent selection of foreground and background colors (i.e. a single command can be sent to the terminal which will have no side effects). An example of color selection will illustrate the steps required, but first an understanding of the 'tput' command is necessary. AIX includes definitions for a number of terminals in the /usr/lib/terminfo directory in files whose name ends with '.ti'. The definitions for IBM terminals are given in the 'ibm.ti' file. An examination of that file will reveal that, for each terminal type defined in the file, there are a series of labels followed by strings of characters. An example from the 'hft' definition is 'smso=\E[7m'. In this case, the label is 'smso' (a mnemonic for Set Mode Stand Out) and the command string is '\E[7m' (\E is interpreted as the escape character, hex 1b). The 'tput' command requires an argument. That argument is the label of a command string. The result of a 'tput smso' command would be the writing of '\E[7m' to 'standard out', which will usually be your terminal, and will put the terminal in 'stand out' mode. The problem at hand is that you want to select foreground and background colors. To select foreground color number 1 (whatever the ibm.ti file says that is), you would issue the 'tput colf1' command. In the case of an hft, '\E[31m' would be written to the screen. This would affect only the foreground color. Background color 3 would be chosen with the 'tput colb3' command. On the 3164, things get complicated. The hardware only supports one command for changing the colors, and it changes both the foreground and background colors. The form of the command is '\E4xyz' where y and z are indirect references to the color to be chosen. In the definition for the ibm3164 terminal given in the ibm.ti file, the command string following the label for the foreground color specification assumes a background of black, while a background color specification command string assumes a foreground color of green. ibm.ti file foreground background --------------- ----------- ------------ colf0=\E4!'@ white black colf1=\E4 $@ red black colf2=\E4 "@ green black colf3=\E4 &@ yellow black colf4=\E4 !@ blue black colf5=\E4 %@ magenta black colf6=\E4 #@ turquoise black colf7=\E4 '@ white black colb0=\E4\s\s@ green black colb1=\E4\s\sD green red colb2=\E4\s\sB green green << not good colb3=\E4\s\sF green yellow colb4=\E4\s\sA green blue colb5=\E4\s\sE green magenta colb6=\E4\s\sC green turquoise colb7=\E4\s\sG green white In short, there is no way, using the 'tput' command, to select both the forground and background colors simultaneously. PROBLEM RESOLUTION: A properly developed curses application can set colors as needed. At the command line, a more complex approach is required. Please find below a script which will do the job. CUT HERE ------------------------------------------------------------------------------- #!/bin/ksh # No warranty expressed or implied etc., etc., etc. black=0 blue=1 green=2 turquoise=3 red=4 magenta=5 yellow=6 white=7 FORE=${green} BACK=${black} function usage { cat << _E_O_F_ usage: 3164_col -f -b where the desired color is specified as: black or 0 <- default background blue or 1 green or 2 <- default foreground turquoise or 3 red or 4 magenta or 5 yellow or 6 white or 7 e.g. 3164_col -f 5 -b bLU selects magenta/blue (Note: It's only necessary to provide a unique color selection and that the options is non-case sensitive. _E_O_F_ exit } function check_color { CHOICE=$1 SUCCESS=1 case ${CHOICE} in 0|[bB][lL][aA]*) CHOICE=${black}; SUCCESS=0; break ;; 1|[bB][lL][uU]*) CHOICE=${blue}; SUCCESS=0; break ;; 2|[gG]*) CHOICE=${green}; SUCCESS=0; break ;; 3|[tT]*) CHOICE=${turquoise}; SUCCESS=0; break ;; 4|[rR]*) CHOICE=${red}; SUCCESS=0; break ;; 5|[mM]*) CHOICE=${magenta}; SUCCESS=0; break ;; 6|[yY]*) CHOICE=${yellow}; SUCCESS=0; break ;; 7|[wW]*) CHOICE=${white}; SUCCESS=0; break ;; esac return ${SUCCESS} } if [ -z "`echo ${TERM} | fgrep 3164`" ]; then echo "TERM should be 'ibm3164', but is '$TERM'" usage fi while getopts :f:b: OPT; do case $OPT in f) if check_color $OPTARG; then FORE=${CHOICE} else usage fi ;; b) if check_color $OPTARG; then BACK=${CHOICE} else usage fi ;; *) usage ;; esac done if [ ${FORE} = ${BACK} ]; then echo "Can't use the same foreground and background colors" exit fi echo -n "`tput smcup`\00334 \004${FORE}\010${BACK}" echo -n "\004${FORE}" | read F_letter echo -n "\010${BACK}" | read B_letter echo "For future reference, '\E4 ${F_letter}${B_letter}'" echo "the string that was sent out was: // |" echo " escape space" ------------------------------------------------------------------------------- CUT HERE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -O- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PROBLEM DISCUSSION: There is another problem with colors. It has to do with whether the 3164 is running in its default mode or not. When the 3164 is powered up, it is in default color mode. That means it is green on black AND CANNOT BE CHANGED. There is a command in the ibm.ti file that changes the terminal to 'program color mode', but simply sending that command ('tput smcup') isn't the final answer. The problem is best illustrated by using the vi editor. Type the following series of commands: tput smcup tput colf1 < colors change to red on black > vi (any_file) < colors remain red on black > immediately quit the editing session < colors revert to green on black > PROBLEM RESOLUTION: The problem, as illustrated above, is that as vi closes, it reaches down into the ibm.ti file and extracts the command string associated with the 'rmcup' label then sends it out. That undoes the 'smcup' command you sent at the beginning of the example. If you don't mind 'tput'ing smcup all the time, OK, but if that is unacceptable, the ibm.ti file will have to be changed. Use the following steps to change the file. Note: While you're at it, we'll make some changes that affect things that are not at issue here. The relevant item is that we're making the smcup and rmcup commands the same. cd /usr/lib/terminfo Change directories vi ibm.ti Edit the file /3164 Find the entry for the 3164 /smcup Find the smcup entry You should see a line similar to the following: smcup=\E!9/N, rmcup=\E!9(N, msgr, The line should be changed to: smcup=\E!9\054B, rmcup=\E!9\054B, msgr, :wq Write and quit tic ibm.ti Re-compile the revised ibm.ti file Now, if you perform the test above, the colors won't revert as they did. One final note: If you try to set the background color to something other than black, you will be very dissatisfied with the result. All the characters printed will have the desired background color, but the part of the line after the last printable character will be black. At this writing, there is no way around the problem at the shell level. As demonstrated by the followed program, curses resolves the problem by simply printing spaces to the screen, but the shell cannot be induced to do that due to hardware limitations. <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -O- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> /* * This program is a very simple demonstration of a way, using extended * curses, to paint a screen and draw boxes * * Compile command: * cc box.c -DNLS -obox -lcur */ #include #include main() { WINDOW *win; initscr(); win = newwin(LINES-1, COLS, 0, 0); wcolorout(win,B_MAGENTA); werase(win); wmove(win, 20, 29); wcolorout(win,F_BLACK|B_WHITE); waddstr(win," - How Now Brown Cow - "); wrefresh(win); win = newwin(10, 50, 6, 15); wcolorout(win,B_BLUE); werase(win); wcolorout(win,F_BLACK|B_WHITE); cbox(win); wmove(win, 5, 14); wcolorout(win,F_BLACK|B_RED); waddstr(win," - How Now Brown Cow - "); wrefresh(win); mvcur(0, 0, LINES-1, 0); wrefresh(win); endwin(); }