Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Understanding terminfo setf/setb

Status
Not open for further replies.

bwysocki

Programmer
Sep 19, 2001
38
US
I'm working on a ncurses application. Right now I have a customized ansi terminfo entry and it works mostly like I want it to.

However I'd like to tweak the colors a bit, but I'm having trouble deciphering the setf and setb entries. Right now I have..

setb=\E[4%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,

setf=\E[3%?%p1%{1}%=%t4%e%p1%{3}%=%t6%e%p1%{4}%=%t1%e%p1%{6}%=%t3%e%p1%d%;m,

The man page on terminfo seems simplistic when explaining setf and setb. Can someone please explain how this string is broken down into different parts?

I'm guessing that several colors are defined in each string, I'm just wondering where one part ends and another begins.

Thanks,
Bob

 
the response is from man 5 terminfo.. a bit long. Here it goes:

Code:
 Parameterized Strings
       Cursor  addressing and other strings requiring parameters in the termi-
       nal are described by a parameterized string(3,n) capability, with printf(1,3,1 builtins)(3S)
       like  escapes  %x  in  it.  For example, to address the cursor, the cup
       capability is given, using  two  parameters:  the  row  and  column  to
       address  to.  (Rows and columns are numbered from zero and refer to the
       physical screen visible to the user, not to any unseen memory.)  If the
       terminal  has  memory relative cursor addressing, that can be indicated
       by mrcup.

       The parameter mechanism uses a stack and special % codes to  manipulate
       it.   Typically  a  sequence  will  push one of the parameters onto the
       stack and then print it in some format.  Print (e.g., "%d") is  a  spe-
       cial case.  Other operations, including "%t" pop their operand from the
       stack.  It is noted that more complex operations are  often  necessary,
       e.g., in the sgr string.

       The % encodings have the following meanings:


       %%   outputs `%'

       %[[:]flags][width[.precision]][doxXs]
            as in printf(1,3,1 builtins), flags are [-+#] and space

       %c   print pop() like %c in printf(1,3,1 builtins)

       %s   print pop() like %s in printf(1,3,1 builtins)

       %p[1-9]
            push i'th parameter

       %P[a-z]
            set(7,n,1 builtins) dynamic variable [a-z] to pop()

       %g[a-z]
            get dynamic variable [a-z] and push it

       %P[A-Z]
            set(7,n,1 builtins) static variable [a-z] to pop()

       %g[A-Z]
            get static variable [a-z] and push it

            The  terms  "static"  and "dynamic" are misleading.  Historically,
            these are simply two different sets of variables, whose values are
            not reset(1,7,1 tput) between calls to tparm.  However, that fact is not docu-
            mented in other implementations.  Relying  on  it  will  adversely
            impact portability to other implementations.

       %'c' char constant c

       %{nn}
            integer constant nn

       %l   push strlen(pop)

       %+ %- %* %/ %m
            arithmetic (%m is mod): push(pop() op pop())

       %& %| %^
            bit operations: push(pop() op pop())

       %= %> %<
            logical operations: push(pop() op pop())

       %A, %O
            logical and & or operations (for conditionals)

       %! %~
            unary operations push(op pop())

       %i   add 1 to first two parameters (for ANSI terminals)

       %? expr(1,3,n) %t thenpart %e elsepart %;
            if-then-else,  %e  elsepart is optional.  else-if's are possible a
            la Algol 68:
            %? c1 %t b1 %e c2 %t b2 %e c3 %t b3 %e c4 %t b4 %e %;
            ci are conditions, bi are bodies.

       Binary operations are in postfix form with the operands  in  the  usual
       order.  That is, to get x-5 one would use "%gx%{5}%-".  %P and %g vari-
       ables are persistent across escape-string evaluations.

       Consider the HP2645, which, to get to row 3 and column 12, needs to  be
       sent  \E&a12c03Y padded for 6 milliseconds.  Note that the order of the
       rows and columns is inverted here, and that  the  row  and  column  are
       printed    as    two    digits.     Thus    its   cup   capability   is
       "cup=6\E&%p2%2dc%p1%2dY".

       The Microterm ACT-IV needs the current row and column sent preceded  by
       a   ^T,   with   the   row   and   column  simply  encoded  in  binary,
       "cup=^T%p1%c%p2%c".  Terminals which  use  "%c"  need  to  be  able  to
       backspace  the cursor (cub1), and to move(3x,7,3x curs_move) the cursor up one line on the
       screen (cuu1).  This is necessary because it  is  not  always  safe  to
       transmit  \n ^D and \r, as the system may change or discard them.  (The
       library routines dealing with terminfo set(7,n,1 builtins) tty(1,4) modes so that  tabs  are
       never  expanded, so \t is safe to send.  This turns out to be essential
       for the Ann Arbor 4080.)

       A final example is the LSI ADM-3a, which uses row and column offset  by
       a blank character, thus "cup=\E=%p1%' '%+%c%p2%' '%+%c".  After sending
       `\E=', this pushes the first parameter, pushes the ASCII  value  for  a
       space (32), adds them (pushing the sum on the stack in place of the two
       previous values) and outputs that value as a character.  Then the  same
       is  done for the second parameter.  More complex arithmetic is possible
       using the stack.

it follows...

Code:
For example, the DEC vt220 supports most of the modes:


                 tparm parameter   attribute    escape sequence

                 none              none         \E[0m
                 p1                standout     \E[0;1;7m
                 p2                underline    \E[0;4m
                 p3                reverse      \E[0;7m
                 p4                blink        \E[0;5m
                 p5                dim          not available
                 p6                bold         \E[0;1m
                 p7                invis        \E[0;8m
                 p8                protect      not used
                 p9                altcharset   ^O (off) ^N (on)

       We begin each escape sequence by turning off any existing modes,  since
       there  is  no quick way to determine whether they are active.  Standout
       is set(7,n,1 builtins) up to be the combination of reverse and bold.  The vt220  termi-
       nal  has  a protect mode, though it is not commonly used in sgr because
       it protects characters on the screen from  the  host(1,5)'s  erasures.   The
       altcharset  mode  also  is  different  in  that  it is either ^O or ^N,
       depending on whether it is off or on.  If all modes are turned on,  the
       resulting sequence is \E[0;1;4;5;7;8m^N.

       Some  sequences are common to different modes.  For example, ;7 is out-
       put when either p1 or p3 is  true,  that  is,  if(3,n)  either  standout  or
       reverse modes are turned on.

       Writing out the above sequences, along with their dependencies yields


               sequence    when to output     terminfo translation

               \E[0       always              \E[0
               ;1         if(3,n) p1 or p6         %?%p1%p6%|%t;1%;
               ;4         if(3,n) p2               %?%p2%|%t;4%;
               ;5         if(3,n) p4               %?%p4%|%t;5%;
               ;7         if(3,n) p1 or p3         %?%p1%p3%|%t;7%;
               ;8         if(3,n) p7               %?%p7%|%t;8%;
               m          always              m
               ^N or ^O   if(3,n) p9 ^N, else ^O   %?%p9%t^N%e^O%;

       Putting this all together into the sgr sequence gives:

           sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;
               %?%p4%t;5%;%?%p7%t;8%;m%?%p9%t\016%e\017%;,

       Remember that if(3,n) you specify sgr, you must also specify sgr0.

source:


almost at the end.

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top