gcla / gowid

Compositional widgets for terminal user interfaces, written in Go, inspired by urwid.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hello World example panics on Windows

r-smith opened this issue · comments

examples\gowid-helloworld\helloworld.go panics on Windows.

time="2019-05-18T22:32:47-07:00" level=info msg="Terminal was resized" event="&{{13776608566125785016 4994801 0x6d7f40} 148 60}"
panic: Color RGBColor(#a0,#00,#60) of type gowid.RGBColor not supported in mode 16 colors

Go 1.12. Windows 10.

A quick debug - it looks like the errors happen when using gowid.MakeRGBColor() in the main application. During rendering, a call is being made to IColorToTCell with a ColorMode of Mode16Colors. Then a method call is made for color.ToTCellColor(mode). There's a switch/case for the various color modes, but Mode16Colors isn't accounted for, so it's defaulting to a panic.

So in .ToTCellColor we should account for Mode16Colors, and probably Mode8Colors and ModeMonochrome since those are also missing. And what if instead of panicing, we have it return something like:

default: return TCellColor{}, false

Since the calling function, IColorToTCell, already supports a fallback color if the lookup fails. Hope this helps!

Thanks, that does help!

Hi - I followed your suggestion :) Since the code already interpolates a color for 256-color and 88-color mode, I've tried to do that for 16, 8 and 2-color modes as well. I've lightly tested 8-color and 2-color - not 16 because I don't think I have a terminal that officially reports 16 colors via terminfo, which tcell respects. So 16 is probably wrong at the moment.

I've pushed this to a branch called rgbto8colors. Would you let me know if it fits the bill? You can use it with something like this:

$ export GO111MODULE=on
$ git clone https://github.com/gcla/gowid
$ cd gowid
$ git checkout rgbto8colors
$ GOOS=windows GOARCH=amd64 go install ./...

In termshark, I went in a different direction, following the model I'd seen in urwid:

https://github.com/gcla/termshark/blob/master/cmd/termshark/termshark.go#L148

modeswap.Color implements gowid.IColor and selects one of two colors based on the current color mode. That lets you programmatically fall back to an alternative that need not necessarily be "close" to the original RGB color.

I tried out the rgbto8colors branch and it looks like it's working great. No panics on the helloworld example and it renders like you'd expect on 16 colors. I ran through all the example programs to make sure there weren't any side effects and everything looks good. Thank you! And awesome job on termshark, btw.

Thanks :) I merged rgbto8colors to master, so I'll close this issue.