Skip to content

Commit

Permalink
Add inverted colors mode
Browse files Browse the repository at this point in the history
Also use color constants in some more places.
  • Loading branch information
abbec committed May 6, 2024
1 parent ad0cd5c commit 292b278
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/dged/buffer_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,18 @@ static uint32_t render_line_numbers(struct buffer_view *view,
uint32_t relline = 0;

for (; relline < height && line < nlines_buf; ++line, ++relline) {
command_list_set_index_color_bg(commands, 8);
command_list_set_index_color_fg(commands, line == view->dot.line ? 15 : 7);
command_list_set_index_color_bg(commands, Color_BrightBlack);
command_list_set_index_color_fg(
commands, line == view->dot.line ? Color_BrightWhite : Color_White);
uint32_t chars = snprintf(buf, 16, "%*d", longest_nchars + 1, line + 1);
command_list_draw_text_copy(commands, 0, relline, (uint8_t *)buf, chars);
command_list_reset_color(commands);
command_list_draw_repeated(commands, longest_nchars + 1, relline, ' ', 1);
}

for (; relline < height; ++relline) {
command_list_set_index_color_bg(commands, 8);
command_list_set_index_color_fg(commands, 7);
command_list_set_index_color_bg(commands, Color_BrightBlack);
command_list_set_index_color_fg(commands, Color_White);
command_list_draw_repeated(commands, 0, relline, ' ', longest_nchars + 1);
command_list_reset_color(commands);
command_list_draw_repeated(commands, longest_nchars + 1, relline, ' ', 1);
Expand Down Expand Up @@ -363,7 +364,8 @@ static void render_modeline(struct modeline *modeline, struct buffer_view *view,
modeline->buffer[len] = '\0';
}

command_list_set_index_color_bg(commands, 8);
command_list_set_index_color_bg(commands, Color_BrightBlack);
command_list_set_index_color_fg(commands, Color_White);
command_list_draw_text(commands, 0, height - 1, modeline->buffer,
strlen((char *)modeline->buffer));
command_list_reset_color(commands);
Expand Down
7 changes: 7 additions & 0 deletions src/dged/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,13 @@ void command_list_set_color_bg(struct command_list *list, uint8_t red,
cmd->len = snprintf((char *)cmd->fmt, 64, "48;2;%d;%d;%d", red, green, blue);
}

void command_list_set_inverted_colors(struct command_list *list) {
struct push_fmt_cmd *cmd =
add_command(list, RenderCommand_PushFormat)->push_fmt;
cmd->fmt[0] = '7';
cmd->len = 1;
}

void command_list_reset_color(struct command_list *list) {
add_command(list, RenderCommand_ClearFormat);
}
Expand Down
7 changes: 7 additions & 0 deletions src/dged/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ void command_list_set_index_color_fg(struct command_list *list,
void command_list_set_color_fg(struct command_list *list, uint8_t red,
uint8_t green, uint8_t blue);

/**
* Set colors to be inverted.
*
* Sets background as foreground and vice versa.
*/
void command_list_set_inverted_colors(struct command_list *list);

/**
* Reset the color and styling information.
*
Expand Down

0 comments on commit 292b278

Please sign in to comment.