mirror of
https://github.com/neovim/neovim.git
synced 2025-09-23 19:48:32 +00:00
Changes for new VTermColor struct
This commit is contained in:

committed by
Björn Linse

parent
2a590e2293
commit
d57250ae64
@@ -152,7 +152,6 @@ static VTermScreenCallbacks vterm_screen_callbacks = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static PMap(ptr_t) *invalidated_terminals;
|
static PMap(ptr_t) *invalidated_terminals;
|
||||||
static Map(int, int) *color_indexes;
|
|
||||||
static int default_vt_fg, default_vt_bg;
|
static int default_vt_fg, default_vt_bg;
|
||||||
static VTermColor default_vt_bg_rgb;
|
static VTermColor default_vt_bg_rgb;
|
||||||
|
|
||||||
@@ -163,33 +162,13 @@ void terminal_init(void)
|
|||||||
// refresh_timer_cb will redraw the screen which can call vimscript
|
// refresh_timer_cb will redraw the screen which can call vimscript
|
||||||
refresh_timer.events = multiqueue_new_child(main_loop.events);
|
refresh_timer.events = multiqueue_new_child(main_loop.events);
|
||||||
|
|
||||||
// initialize a rgb->color index map for cterm attributes(VTermScreenCell
|
|
||||||
// only has RGB information and we need color indexes for terminal UIs)
|
|
||||||
color_indexes = map_new(int, int)();
|
|
||||||
VTerm *vt = vterm_new(24, 80);
|
VTerm *vt = vterm_new(24, 80);
|
||||||
VTermState *state = vterm_obtain_state(vt);
|
VTermState *state = vterm_obtain_state(vt);
|
||||||
|
|
||||||
for (int color_index = 255; color_index >= 0; color_index--) {
|
|
||||||
VTermColor color;
|
|
||||||
// Some of the default 16 colors has the same color as the later
|
|
||||||
// 240 colors. To avoid collisions, we will use the custom colors
|
|
||||||
// below in non true color mode.
|
|
||||||
if (color_index < 16) {
|
|
||||||
color.red = 0;
|
|
||||||
color.green = 0;
|
|
||||||
color.blue = (uint8_t)(color_index + 1);
|
|
||||||
} else {
|
|
||||||
vterm_state_get_palette_color(state, color_index, &color);
|
|
||||||
}
|
|
||||||
map_put(int, int)(color_indexes,
|
|
||||||
RGB_(color.red, color.green, color.blue),
|
|
||||||
color_index + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
VTermColor fg, bg;
|
VTermColor fg, bg;
|
||||||
vterm_state_get_default_colors(state, &fg, &bg);
|
vterm_state_get_default_colors(state, &fg, &bg);
|
||||||
default_vt_fg = RGB_(fg.red, fg.green, fg.blue);
|
default_vt_fg = RGB_(fg.rgb.red, fg.rgb.green, fg.rgb.blue);
|
||||||
default_vt_bg = RGB_(bg.red, bg.green, bg.blue);
|
default_vt_bg = RGB_(bg.rgb.red, bg.rgb.green, bg.rgb.blue);
|
||||||
default_vt_bg_rgb = bg;
|
default_vt_bg_rgb = bg;
|
||||||
vterm_free(vt);
|
vterm_free(vt);
|
||||||
}
|
}
|
||||||
@@ -200,7 +179,6 @@ void terminal_teardown(void)
|
|||||||
multiqueue_free(refresh_timer.events);
|
multiqueue_free(refresh_timer.events);
|
||||||
time_watcher_close(&refresh_timer, NULL);
|
time_watcher_close(&refresh_timer, NULL);
|
||||||
pmap_free(ptr_t)(invalidated_terminals);
|
pmap_free(ptr_t)(invalidated_terminals);
|
||||||
map_free(int, int)(color_indexes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public API {{{
|
// public API {{{
|
||||||
@@ -256,15 +234,6 @@ Terminal *terminal_open(TerminalOptions opts)
|
|||||||
rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size);
|
rv->sb_buffer = xmalloc(sizeof(ScrollbackLine *) * rv->sb_size);
|
||||||
|
|
||||||
if (!true_color) {
|
if (!true_color) {
|
||||||
// Change the first 16 colors so we can easily get the correct color
|
|
||||||
// index from them.
|
|
||||||
for (int i = 0; i < 16; i++) {
|
|
||||||
VTermColor color;
|
|
||||||
color.red = 0;
|
|
||||||
color.green = 0;
|
|
||||||
color.blue = (uint8_t)(i + 1);
|
|
||||||
vterm_state_set_palette_color(state, i, &color);
|
|
||||||
}
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -286,9 +255,10 @@ Terminal *terminal_open(TerminalOptions opts)
|
|||||||
|
|
||||||
if (color_val != -1) {
|
if (color_val != -1) {
|
||||||
VTermColor color;
|
VTermColor color;
|
||||||
color.red = (uint8_t)((color_val >> 16) & 0xFF);
|
vterm_color_rgb(&color,
|
||||||
color.green = (uint8_t)((color_val >> 8) & 0xFF);
|
(uint8_t)(color_val >> 16) & 0xFF,
|
||||||
color.blue = (uint8_t)((color_val >> 0) & 0xFF);
|
(uint8_t)(color_val >> 8) & 0xFF,
|
||||||
|
(uint8_t)(color_val >> 0) & 0xFF);
|
||||||
vterm_state_set_palette_color(state, i, &color);
|
vterm_state_set_palette_color(state, i, &color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -630,17 +600,14 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr,
|
|||||||
VTermScreenCell cell;
|
VTermScreenCell cell;
|
||||||
fetch_cell(term, row, col, &cell);
|
fetch_cell(term, row, col, &cell);
|
||||||
// Get the rgb value set by libvterm.
|
// Get the rgb value set by libvterm.
|
||||||
int vt_fg = RGB_(cell.fg.red, cell.fg.green, cell.fg.blue);
|
int vt_fg = RGB_(cell.fg.rgb.red, cell.fg.rgb.green, cell.fg.rgb.blue);
|
||||||
int vt_bg = RGB_(cell.bg.red, cell.bg.green, cell.bg.blue);
|
int vt_bg = RGB_(cell.bg.rgb.red, cell.bg.rgb.green, cell.bg.rgb.blue);
|
||||||
vt_fg = vt_fg != default_vt_fg ? vt_fg : - 1;
|
vt_fg = vt_fg != default_vt_fg ? vt_fg : - 1;
|
||||||
vt_bg = vt_bg != default_vt_bg ? vt_bg : - 1;
|
vt_bg = vt_bg != default_vt_bg ? vt_bg : - 1;
|
||||||
// Since libvterm does not expose the color index used by the program, we
|
int vt_fg_idx = VTERM_COLOR_IS_DEFAULT_FG(&cell.fg) ? 0 :
|
||||||
// use the rgb value to find the appropriate index in the cache computed by
|
VTERM_COLOR_IS_INDEXED(&cell.fg) ? cell.fg.indexed.idx + 1 : 0;
|
||||||
// `terminal_init`.
|
int vt_bg_idx = VTERM_COLOR_IS_DEFAULT_BG(&cell.bg) ? 0 :
|
||||||
int vt_fg_idx = vt_fg != -1 ?
|
VTERM_COLOR_IS_INDEXED(&cell.bg) ? cell.bg.indexed.idx + 1 : 0;
|
||||||
map_get(int, int)(color_indexes, vt_fg) : 0;
|
|
||||||
int vt_bg_idx = vt_bg != -1 ?
|
|
||||||
map_get(int, int)(color_indexes, vt_bg) : 0;
|
|
||||||
|
|
||||||
int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0)
|
int hl_attrs = (cell.attrs.bold ? HL_BOLD : 0)
|
||||||
| (cell.attrs.italic ? HL_ITALIC : 0)
|
| (cell.attrs.italic ? HL_ITALIC : 0)
|
||||||
|
Reference in New Issue
Block a user