Search code examples
ttyemacs24xtermiterm2terminfo

What do the @ (at symbols) in a terminfo manipulation code mean?


I'm trying to convert a terminfo string from xterm to something that will work with iTerm2 in order to get 24bit colors working in emacs. The investigating and research I've done so far leads me to believe that the terminfo manipulation codes I'm using to set stf24/setb24 are being incorrectly interpreted by iTerm2, so I want to understand what these are doing.

Here are the custom values that emacs requires:

xterm-24bit|xterm with 24-bit direct color mode,
   use=xterm-256color,
   setb24=\E[48:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm,
   setf24=\E[38:2:%p1%@{65536@}%/%d:%p1%@{256@}%/%@{255@}%&%d:%p1%@{255@}%&%dm,
# Use semicolon separators.
xterm-24bits|xterm with 24-bit direct color mode,
   use=xterm-256color,
   setb24=\E[48;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm,
   setf24=\E[38;2;%p1%@{65536@}%/%d;%p1%@{256@}%/%@{255@}%&%d;%p1%@{255@}%&%dm,

I know that the first bit e.g. \e[48:2: is the escape code specifying the colour location (in this case background) and the colour format (2 means full 24-bit RGB format requiring 3 control segments). Looking at this documentation 'Supported TERMINFO Manipulation Codes' I know that it is taking a parameter '1' from the stack with %p1, and performing a few other operations on this (%/ - division, %& - AND) but I'm not sure what %@ means or what the numbers in brackets mean %@{65536}, and also what the %dm does at the end. Can anyone assist?

Overall, I believe emacs only passes the one parameter (presumably a single number within 256^3 0-16,777,216), so I think this is somehow breaking it apart into the 3 constituent RGB colours that the terminal needs, but I haven't quite worked out how, and then whether there is an incompatibility and where it lies.


Solution

  • The @ marks are not part of the terminfo description; they are used in the original texinfo file to prevent the curly braces from being interpreted. What you're reading is cut/paste from someone who didn't understand either part of the markup...

    Without the @ marks, you'll have constants, e.g., %{65536} used in arithmetic.

    The "%dm on the end" is just the third parameter, i.e., the blue value in RGB (note that there are two other "%d" marks), with the final character "m".