Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port 256 Color, 216 Color and Grayscale modes from termbox.c. #52

Merged
merged 6 commits into from
Dec 1, 2014

Conversation

mesilliac
Copy link
Contributor

This includes the change to attributes to support bold, underline and reverse.

The only thing I really changed from the C version was output.go to better show what the higher colour depths can do. It allows switching output mode with the arrow keys, and all output fits into an 80x24 terminal.

Tommy added 3 commits November 30, 2014 14:38
Ported from the C version of Termbox.
Right and left arrows switch output mode,
up and down arrows similarly.
write_sgr(fgcol, bgcol)
case OutputGrayscale:
fgcol = fg & 0xFF; if fgcol > 23 { fg = 23 }
bgcol = bg & 0xFF; if bgcol > 23 { bg = 0 }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right to me, but i copied it directly from termbox.c. If this is wrong, it should probably be fixed there, too. (assigning to fg and bg in stead of fgcol and bgcol)

@nsf
Copy link
Owner

nsf commented Nov 30, 2014

Yes, seems like a bug. I'll take a look and merge this pull request and fix C version of the termbox in the following 1-3 days.

What worries me though is how you handle windows OS. Go version, unlike C one has a windows port, so we need to handle it somehow gracefully there, because there are no 256 color modes. You set the output mode and then doesn't use it on windows at all. Maybe windows version should always return OutputNormal? Indicating that it doesn't support other modes. And add that to the comments, something like: "If SetOutputMode returns other mode than the requested one, then it means the requested mode is not supported on the target platform".

@mesilliac
Copy link
Contributor Author

Oh! I don't have any Windows machine to test on, so i just assumed it would also support 256-colour output. Yeah, always returning OutputNormal seems like the best solution there. As it's already returning the value in all cases, it can be expected to possibly be different from the mode that was requested.

What do you think about 24-bit colour support? I'm tempted to add it in, but it would require at least making Attributes 32 bit, and i'm not sure if that's acceptable. It also seems quite hard to tell whether it's supported by the current terminal.

@nsf
Copy link
Owner

nsf commented Nov 30, 2014

I think 24-bit color is too much for text-based applications. You can only see difference between 16-bit and 24-bit in gradients and it's impossible to make smooth gradients with text, they all will have "stairs". So, why bother..

@nsf
Copy link
Owner

nsf commented Nov 30, 2014

Well, I compared it with 16 bit, even though we have only 256 colors, but it's actually quite the same for 256 colors vs. 16 bit. Text is okay with 256 colors, imho.

@mesilliac
Copy link
Contributor Author

The use case i'm thinking of is a character-based game like a roguelike. Some of the modern ones seem to be making heavy use of colour gradients for artistic effect – off the top of my head Brogue and Ultima Ratio Regum are good examples, i'll fish up some screenshots.

The problem is that they are actually using SDL (via libtcod) to display characters as graphical tiles. It would be nice if it were possible to do this as an actual terminal app, but i don't think there are any libraries currently supporting it.

Brogue is colourful with smooth gradients and quite popular.

brogue
https://sites.google.com/site/broguegame/home/screenshots/IlluminatedChasm.png
https://sites.google.com/site/broguegame/home/screenshots/Fireboltkilledpixie.png

Looking at those, they'd probably be fine with 256 colours. Especially if the palette can be changed.

Something like Ultima Ratio Regum would be impossible without true color support, though.

ultima ratio regum title screen
ultima ratio regnum game shot

I think that one hits the limit of what can be achieved using only unicode and fg/bg colour.

@nsf
Copy link
Owner

nsf commented Dec 1, 2014

Just use SDL, if you're making a game.

@mesilliac
Copy link
Contributor Author

"Termbox isn't intended for games" i could accept, but "Just use SDL if you're making a game" is simply myopic.

@nsf
Copy link
Owner

nsf commented Dec 1, 2014

I mean in your case. If you're doing a text-based rogue-like, use SDL, implement on top of it your own "termbox" with 32 bit colors if you want. Or if you don't like SDL, use allegro or any other library, that wasn't the point.

@nsf
Copy link
Owner

nsf commented Dec 1, 2014

Termbox is okay for games, terminals aren't.

@nsf nsf merged commit 609e376 into nsf:master Dec 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants