gchp / rustbox

Rust implementation of the termbox library
MIT License
467 stars 48 forks source link

256 color support #45

Closed FreeFull closed 8 years ago

FreeFull commented 9 years ago

It is currently available in termbox master, and hasn't made it into a release yet. It would be nice to add it to rustbox once termbox 1.1.0 lands.

gchp commented 9 years ago

Agreed!

sebglazebrook commented 9 years ago

I've been looking forward to this too.

I've been able to get it to work (https://github.com/sebglazebrook/rustbox/blob/add-colors/src/rustbox.rs)

Currently it only works with the nightly rust build as it used the feature "associated_consts" to keep the color API the same.

Another issue is that the value for the colors when in normal mode are not the same as the colors in 8-bit 256 color mode. i.e. Black = 1 in normal mode and 0 in 256 color mode, so the enum doesn't really work.

All things that can be sorted but might change the API a little to do it cleanly.

dbrodie commented 9 years ago

Would this also bring in Dim support? I haven't seen any support for it in termbox (and couldn't find an open issue about it) but it is something that I am missing and seems to be supported by all the other terminal coloring libraries.

ryanwilliams commented 8 years ago

I'd love to see 256 colour support.

@sebglazebrook Is the #[repr(C,u16)] really required on Color? If not I think you could use a tuple struct like struct Color(u16) for a cleaner syntax. But I'm kinda new to this rust stuff :)

ryanwilliams commented 8 years ago

I took a stab it at it based on seb's code. This version will show the right colours in both 16 and 256 colour mode using the same enum as before. However I had to drop the #[repr(C,u16)] as they no longer map directly to u16 values and instead a method translates the value. I also had to change the mutability in some places so I can keep track of the mode, this may be undesirable.

Here's my commit:

https://github.com/ryanwilliams/rustbox/commit/396f00606fe0306ddfa56f12666c1fe670c9b6d5

gchp commented 8 years ago

@ryanwilliams looks good! Want to submit a PR?

gchp commented 8 years ago

@ryanwilliams do I have your permission to include https://github.com/ryanwilliams/rustbox/commit/396f00606fe0306ddfa56f12666c1fe670c9b6d5 in rustbox?

Works really well, and I'd love to include it if possible!

ryanwilliams commented 8 years ago

Sure, go for it.

jmacdonald commented 8 years ago

I think this has been implemented as of ca49730ed37562ee5a1a690cfb4129faed80acee; is that correct?

gchp commented 8 years ago

Yep - just released 0.9.0 which contains this! Thanks @ryanwilliams for the patch @sebglazebrook for the original.