Closed scrouthtv closed 3 years ago
I appreciate the effort, but....
This project is no longer maintained (as it says in the top of the README). Did you consider switching to https://github.com/gdamore/tcell? It seems it also has 24 bit color support. Tcell seems to be better maintained, there is no point in using termbox-go anymore.
TL;DR:
OutputRGB
to print 24bit colors.AttrCursive
,AttrHidden
,AttrDim
,AttrBlink
ColorLightRed
,ColorLightGreen
,ColorLightYellow
,ColorLightBlue
,ColorLightMagenta
,ColorLightCyan
,ColorLightGray
to work inOutputNormal
modeI used
termbox-go
in the past quite often and still do today. Recently, when writing a batch script for a different thing, I found out that most terminals nowaday even have full rgb support.On full rgb support
You can read more about it in the man page for
(Here I showcased some random colors in my terminal)
(Here is a script I wrote to test the rgb colorspace, test it from my GitHub: https://github.com/scrouthtv/bash-colorpicker/blob/main/rgbtest.sh)
console_codes
. This manpage isn't supplied with my system, so you can read it online via https://man7.org/linux/man-pages/man4/console_codes.4.html (I am not related to that website). In the section about ECMA-48 Set Graphics Rendition it mentions the\e[38
/\e[48
escape code (thattermbox-go
) already uses to draw the 8bit color palette. After the list, it states that 38 / 48 can be used with either;5;x
for one of the 256 colors:I found this functionality realy interesting, so I gave it a go (pun intended) to implement it in
termbox
. Some notes on my implementation:Attribute
type to be anuint64
instead of anuint16
. The lowest bits are still the same, however, afterAttrReverse
the next 25 bits are used for the rgb color: The first 8 for the blue component, the next 8 for the green component, and the highest 8 bits for the red component. The 25th bit is set to recognize rgb colors and differentiate between ColorDefault and rgb(0, 0, 0) (see 5951683).OutputRGB
mode. When it is applied, the attribute setting is bit-shifted back into the rgb triplet and drawn using the escape code above. Only if the 25th bit of the rgb part is set, an escape code is printed. That way, if ColorDefault is supplied (which doesn't have this bit set), no escape code will be printed.On more attributes
Currently, upstream
(Here is a demonstration of available attributes and their combination)
I added those to the list of attributes, they all depend on the corresponding
The terminfo for
termbox
supportsbold
,underline
andreverse
. During my research, I found out that some terminals support more than that: Many xterms have ablink
, acursive
and adim
and ahidden
mode:terminfo
entry. I am usingtermite
, and the corresponding terminfo doesn't specify ablink
property even though\e[5m
works:rxvt-unicode-256color
on the other hand does specify that escape sequence:This is an issue I want to get in touch soon with either
termite
orncurses
upstream. The point is, that these new escape sequences that I introduce work on most of the newer terminals.On bright colors
With modern escape sequences, for every one of the main 8 colors there is one bright variant:
Those are also (partly) supported in the tty or other basic terminals and work similarly to the 8 main colors.
I thought it would be a good idea to also draw these in
(
OutputNormal
mode (8093db4) and also added a demo to showcase this functionality (964f63e):16colortest.go
) This showcases all combinations of the basic 16 colors. The upper left quadrant (up to 08 on 08) should be familiar as these are the very first 8 colors. The next 8 are their brighter counterparts. With my changes, those can be used usingColorLightRed
,ColorLightMagenta
, ... inOutputNormal
mode.On compatibility
Every introduced change should be backwards-compatible as no constants are renamed. The underlying values for
AttrReverse
andAttrUnderline
were changed in b53f34a and a08d44e but the user should be using the named constants anyways instead of magic number literals.I tested this code only very very sparsely under windows. RGB colors do not work. Many of the old and new escape codes do not work. I just moved a function to have a compilable version for windows (e788edd). I did not and can not test any other OSs / arches besides Linux and Windows
I did not change the builtin terminfo to include the new escape codes I added For now, I didn't make it so far as to understand what exactly is happening in the
terminfo_builtin.go
and how to test it. I guess I simply mask the existing terminfo file of my system and this waytermbox
uses the builtin? I made a change to the python script to get it to run on my system (a325f32) but I didn't use it yet. That is still to be done.I also want to support 256 colorspace and full rgb at some time in the new Windows Terminal to close #198 .
On the added examples
16colortest.go
:OutputNormal
mode.256ramp.go
:Output256
in an ordered fashionrgbcolor.go
:OutputRGB
as well as the combination of different attributes.These demos are all very, very basic and can only test one single thing. If you don't want one of them, feel free to delete them, I used them to test things during development.
Thanks for reading so far! Sorry if my text was a bit longer, I wanted to make sure that everyone gets it right the first time. Here are some more notes on the implementation that I don't expect you to read: termbox-changes.txt