ci_edit
ci_edit copied to clipboard
Program crashes on some (8 color) terminals
I traced this error to applyPalette in ci_program.py. setUpPalette has a try-catch block where it's try block and the catch block currently do the same thing, causing the crash. This happens because some terminals only support 8 colors so curses.COLORS will return 8 instead of 256. However, the default palette assumes there are 256 colors. I think that we should have maybe a barebones 8-bit colored version of the program to support these types of terminals. I may see if I can figure out how to play around with the color schemes, but you probably are better at dealing with this than I am @dschuyler.
Found a workaaround for some terminals if they do support 256 colors, but just are set to 8 colors. You can try the command TERM=xterm-256color python2 ci.py to see if your terminal will run the program with 256 colors.
I tried making the program run this command using the subprocess module, but I think because the program is already started, curses.COLORS doesn't change even if you import curses after running the shell command.
@dschuyler What is the reason for the colorDelta variable when drawing the text buffer? Because the program seems to add some large number like 192 to the color Index, it becomes difficult to tell what color you're trying to pick out.
Thanks for the question. I can see that's not clear in code.
The color palette is arranged into a 'banks' of colors. Where a bank of N color indexes all have the same background color with different foreground colors. Then the next N color indexes repeat the same foreground colors with a different background color. So if we're drawing in color index 5 for example (where 5 might have a blue text on a tan background (not that is does, this is an example)) and we at N or some multiple of N to 5 we'll get blue text on some other color background.
In the code, the value for N is calculated in app/ci_program.py line 576 cycle = len(foreground)
There's a bug in that 192 number because it's assuming that N will evenly divide 192 (which it did/does because there are 32 foreground colors). It's bad that the value 192 is hardcoded.
What that 192 value should be is an offset index within the palette for the bank of colors to be used when the line of text exceeds the |self.lineLimitIndicator| value. And that value should be an even multiple of len(foreground). Maybe that value should be set directly/explicitly in the app/default_prefs.py for each palette (allowing the designer of the palette to control which bank is used).
This seems quite thought out. I'll probably need a while to fully understand how all the color is used. I'm not sure if I can smoothly implement an 8 color version of the program and I might have to just revamp all the color work to make it work more nicely with multiple palettes. I think I'll hold this off for a little bit and work on other stuff for now.
It should no longer crash on an 8 color terminal. The colors are unsightly, but it now seems to work.