-
Notifications
You must be signed in to change notification settings - Fork 262
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
support 24bit true color #356
Comments
Would be nice to bump @XVilka https://gist.github.com/XVilka/8346728 |
As you noted in another comment this is a restriction of curses because the terminfo database doesn't currently handle 24bit color support. For our use case we don't actually need a lot of different colors. We just want to specify them via RGB values. Interestingly curses provides the If you are interested in this feature I suggest to:
As for completely ditching curses, a minimal vt100 compatible ui backend might be of interest for some usage scenarios. The re-drawing code of vis is currently intentionally very primitive. The window content is often redrawn from scratch and it is assumed that it can efficiently be "blitted" to the display. For curses this works because it uses double buffering to minimize actual terminal output. I don't know how bad the effects would be for a raw vt100 backend. |
I believe palette setting is fairly-widely supported, but frowned on because there's no good way to undo the changes after they're made, so you leave a mess for any later tools that run in the same terminal. There's a lot of useful functionality that is widely implemented but (for whatever reason) is not advertised in the |
Stumbled on this issue, I figured I could add some info I learned:
I tend to think palette + changing colors is the best way for a text editor, its very unlikely there would be more than 256 colors on screen at the same time, and 24bit colors support is not free in a terminal emulator either (depending on how it stores it screen data, but seems the common method is an array of char + attribute, where 24bit colors adds a big memory overhead). |
Hi Maxime, thanks for your insight, I agree. The "problem" is that my preferred terminal For reference I include my test program: #include <curses.h>
#include <string.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
const char *color = argc > 1 ? argv[1] : "abcdef";
short r, g, b;
if (strlen(color) != 6 || sscanf(color, "%2hx%2hx%2hx", &r, &g, &b) != 3) {
fprintf(stderr, "Invalid color, `RRGGBB' expected\n");
return 1;
}
if (!initscr()) {
fprintf(stderr, "Failed to initalize curses\n");
return 1;
}
if (start_color() != OK)
printw("Failed to start color mode\n");
if (!can_change_color())
printw("Dynamic color changes not supported by terminal\n");
int color_index = COLORS-1;
short oldr, oldg, oldb;
if (color_content(color_index, &oldr, &oldg, &oldb) == OK) {
printw("Old RGB value for color %d: #%02hx%02hx%02hx\n", color_index,
(short)(oldr*255/1000), (short)(oldg*255/1000), (short)(oldb*255/1000));
} else {
printw("Failed to read out value of color: %d\n", color_index);
}
if (init_color(color_index, r*1000/255, g*1000/255, b*1000/255) != OK)
printw("Failed to initialize color\n");
int colorpair_index = COLOR_PAIRS-2;
if (init_pair(colorpair_index, color_index, 0) != OK)
printw("Failed to initialize color pair\n");
attrset(COLOR_PAIR(colorpair_index));
printw("#%02hx%02hx%02hx\n", r, g, b);
getch();
if (can_change_color()) {
/* Reset palette, or should we manually change back all affected colors?
* Move after endwin()? */
puts("\033]104;\007");
fflush(stdout);
}
endwin();
return 0;
} Usage:
|
@mawww well, speaking about memory consumption - it's largely exaggerated. It wont eat more than a couple of megabytes. Considering modern operating systems (and computers, including embedded ones), it's a very small number. |
@martanne st supports 24-bit a long time ago. That's why I use st, about dvtm, I think they are planning to support it but it isn't being done yet. |
@martanne Do you think it would be difficult to implement |
I have implemented 24-bit color support via
[0] tmux/tmux@96d0e8a |
According to tmux/tmux#552 it looks like they are not against palette changing, they seem ready to accept a PR that would implement it. |
Oh, that's a much better situation than I'd thought - thanks for the correction. I'll look into how difficult it would be to do properly. |
@s-gilles thanks, I will take a more detailed look at the code once I have a bit more time. Working in tmux is not a prerequisite for a merge (as I understand the behavior would be the same as today?). Allowing themes to use terminal color indices was a mistake. In theory themes should be user interface agnostic. I'm fine with removing that again and forcing them to specify colors in RGB format. This should fix the theme changing bugs. We probably also need to save/restore the color palette in Also the existing color code uses two mostly redundant lookup tables |
you might want to check out this 50 line C program that paints an image using true-color RGB values via |
@martanne Sounds good, I'll try and update my branch to deal with the other save/restore cases, then PR it. I'm not positive, but I think we might be able to bypass reverse lookup. The ubiquitous 256colors.pl script actually sets the entire palette before displaying, so its RGB <-> index mapping could probably be used. It might be that this is even what tmux is doing with |
vis currently only supports 256 colors
The text was updated successfully, but these errors were encountered: