256 color support

97 views
Skip to first unread message

Brad Wood

unread,
Jan 10, 2018, 1:18:13 AM1/10/18
to jline...@googlegroups.com
I wanted to check and see if 256 ANSI colors are supported in all the terminals yet.  This is finally one thing that didn't work in Jline2 :)  I whipped up the following CFML script to output all colors:

var i = -1;
while( ++i < 256 ) {
  shell.printString( '#chr(27)#[38;5;#i#m#i##chr(27)#[0m   ' );
  if( (i+1) % 16 == 0 ) {
    shell.printString( chr(10) );
  }
}

It works great on Cygwin and produces a table full of beautiful colors.  On ConEMU or cmd.exe though, I just get a bunch of plain jane white numbers with no colors at all.

And in case you can't make out what the code above is doing, I'm using the ANSI sequence:

ESC[38;5;<i>m

Where <i> is a number 0 through 255. 

I figured I'd check and see what the expectation was of this working before I spent too much time messing with it.

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 

Brad Wood

unread,
Jan 16, 2018, 6:08:09 PM1/16/18
to jline-users
Any update on whether these ANSI escape codes for 256 colors ( like ESC[38;5;42m )are expected to work in all terminals like cmd.exe?  If not, that's cool but I can't get a straight answer after quite a bit of Googling.  The fact that 256 colors work on Cygwin give me a glimmer of hope, but I'm unclear on whether terminals like cmd.exe and ConEMU aren't working due to their own deficiencies, or JLine failing to detect them correctly.  

Thanks!

~Bra

Guillaume Nodet

unread,
Jan 17, 2018, 2:51:01 AM1/17/18
to jline...@googlegroups.com
I have absolutely no idea on which exact terminals it is supported.
Afaik, cmd.exe only support 16 colors, which is why jline has colors=16 for the "windows" terminal
  https://github.com/jline/jline3/blob/master/terminal/src/main/resources/org/jline/utils/windows.caps#L3
The number of supported colors should come from the infocmp capability, as it's used when actually outputing ansi sequences:

So from a jline's perspective, the expectation is that it will only use the number of colors from the infocmp capability.
As a jline's user, you should try to use AttributedString instead of raw ansi sequences, because if they are not fully supported, there will be some kind of emulation (colors will be rounded).
You can also detect if that's "supported" by checking the terminal's color capability as done in the above code.

That said, there may be bugs, especially on windows.  So if a terminal indicates the wrong number of colors, please raise an issue and give the full combination to replicate the problem.


--
You received this message because you are subscribed to the Google Groups "jline-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jline-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Brad Wood

unread,
Jan 17, 2018, 11:24:04 AM1/17/18
to jline...@googlegroups.com
Thanks for the additional information.  I did a quick test on cmd.exe and ConEMU with this code 

caps = createObject( 'java', 'org.jline.utils.InfoCmp$Capability' )
$shell.getReader().getTerminal().getNumericCapability(caps.max_colors)

And it returns 16 for both.  I believe that's correct for cmd, but I don't think it's correct for ConEMU.  That said, the internet is not very clear whatsoever on how the heck ConEMU is supposed to work which is sort of frustrating.  I'm 99.9% positive ConEMU should support 256 colors (heck, it has settings for 24-bit colors!) but I'm not that positive that I have all the little checkboxes ticked to make it work.  I'll put in a ticket so we can investigate further. 


As a jline's user, you should try to use AttributedString instead of raw ansi sequences,

Well, to be clear, I was using raw sequences in my examples just to simplify everything.  CommandBox has a print helper that generates ANSI strings based on a chainable fluent DSL I've shown here before.  

print.boldGreenOnWhiteLine( 'foo' );

That said, are you saying that even my print helper should create attributed strings always behind the scenes?  I was considering writing my own code to do rounding and such of colors, so that would be nice if JLine could help handle that for me.



Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


Brad Wood

unread,
Jan 23, 2018, 8:06:02 PM1/23/18
to jline...@googlegroups.com
Good news, as I reported in GitHub your ConEMU branch seems to work great for outputting 256 colors.  I still have an outstanding question (or two) on this color rounding you spoke of.  Outputting colors like ESC[38;5;71m just shows up as white in cmd.exe, even when I try to pass the formatted string through your Java class:

string = createObject("java","org.jline.utils.AttributedString").init( string ).toString();

I'll need more information from you on how to tap into this color rounding logic.  I can really only try to start using these fancy colors if I know it will fall back nicely on older terminals like cmd.exe.

Thanks!

~Brad

Developer Advocate
Ortus Solutions, Corp 

ColdBox Platform: http://www.coldbox.org 


Reply all
Reply to author
Forward
0 new messages