nsf / termbox-go

Pure Go termbox implementation
http://godoc.org/github.com/nsf/termbox-go
MIT License
4.66k stars 372 forks source link

Support for full RGB mode and further attributes #227

Closed scrouthtv closed 3 years ago

scrouthtv commented 3 years ago

TL;DR:

I 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 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 (that termbox-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: termbox-go-rgb-preview (Here I showcased some random colors in my terminal) rgbdemo (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)

I found this functionality realy interesting, so I gave it a go (pun intended) to implement it in termbox. Some notes on my implementation:

On more attributes

Currently, upstream termbox supports bold, underline and reverse. During my research, I found out that some terminals support more than that: Many xterms have a blink, a cursive and a dim and a hidden mode: attributesdemo (Here is a demonstration of available attributes and their combination) I added those to the list of attributes, they all depend on the corresponding terminfo entry. I am using termite, and the corresponding terminfo doesn't specify a blink property even though \e[5m works: blinkdemo The terminfo for rxvt-unicode-256color on the other hand does specify that escape sequence:

 ~ infocmp rxvt-unicode-256color  | grep -i blink
    bel=^G, blink=\E[5m, bold=\E[1m, civis=\E[?25l, 

This is an issue I want to get in touch soon with either termite or ncurses 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: image 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 (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 using ColorLightRed, ColorLightMagenta, ... in OutputNormal mode.

On compatibility

Every introduced change should be backwards-compatible as no constants are renamed. The underlying values for AttrReverse and AttrUnderline 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 way termbox 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: image Displays the available colors to OutputNormal mode.

256ramp.go: image Displays the available 8bit colors to Output256 in an ordered fashion

rgbcolor.go: image A very basic UI that I programmed to test the Full RGB mode using 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

nsf commented 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.