Skip to content

Commit

Permalink
cfg: error text color
Browse files Browse the repository at this point in the history
New config variable: `err_color`
  • Loading branch information
0x501D committed Feb 14, 2024
1 parent 8225ef1 commit cae8505
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
v3.3.1 - future
------------------------
- Feature: error text color config option

v3.3.0 - 04.10.2023
------------------------
- Feature: support vga none option
Expand Down
3 changes: 3 additions & 0 deletions nemu.cfg.sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ db = /home/user/.nemu.db
# override highlight color of running VM's. Example:
# hl_color = 00afd7

# override error text color. Example:
# err_color = ff45c1

# glyph_checkbox = 1
# glyph_separator = 0

Expand Down
18 changes: 18 additions & 0 deletions src/nm_cfg_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static const char NM_INI_S_DMON[] = "nemu-monitor";
static const char NM_INI_P_VM[] = "vmdir";
static const char NM_INI_P_DB[] = "db";
static const char NM_INI_P_HL[] = "hl_color";
static const char NM_INI_P_ERR[] = "err_color";
static const char NM_INI_P_CS[] = "cursor_style";
static const char NM_INI_P_DEBUG_PATH[] = "debug_path";
static const char NM_INI_P_PROT[] = "spice_default";
Expand Down Expand Up @@ -295,6 +296,21 @@ void nm_cfg_init(bool bypass_cfg)
cfg.hl_color.r, cfg.hl_color.g, cfg.hl_color.b);
}
nm_str_trunc(&tmp_buf, 0);
if (nm_get_opt_param(ini, NM_INI_S_MAIN, NM_INI_P_ERR, &tmp_buf) == NM_OK) {
if (tmp_buf.len != 6) {
nm_bug(_("cfg: incorrect color value %s, example:cd1430"),
tmp_buf.data);
}

nm_cfg_get_color(0, &cfg.err_color.r, &tmp_buf);
nm_cfg_get_color(2, &cfg.err_color.g, &tmp_buf);
nm_cfg_get_color(4, &cfg.err_color.b, &tmp_buf);

cfg.err_is_set = 1;
nm_debug("Error color: r:%d g:%d b:%d\n",
cfg.err_color.r, cfg.err_color.g, cfg.err_color.b);
}
nm_str_trunc(&tmp_buf, 0);
if (nm_get_opt_param(ini, NM_INI_S_MAIN, NM_INI_P_CS, &tmp_buf) == NM_OK) {
if (tmp_buf.len != 1) {
nm_bug(_("cfg: incorrect cursor style value %s, example:1"),
Expand Down Expand Up @@ -580,6 +596,8 @@ static void nm_generate_cfg(const char *home, const nm_str_t *cfg_path)
"debug_path = /tmp/nemu_debug.log\n\n");
fprintf(cfg_file, "# override highlight color of running VM's. "
"Example:\n# hl_color = 00afd7\n\n");
fprintf(cfg_file, "# override error text color. "
"Example:\n# err_color = cd1430\n\n");
fprintf(cfg_file, "# glyph_checkbox = 1\n# "
"glyph_separator = 0\n\n");
fprintf(cfg_file,
Expand Down
2 changes: 2 additions & 0 deletions src/nm_cfg_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ typedef struct {
nm_str_t qemu_bin_path;
nm_vect_t qemu_targets;
nm_rgb_t hl_color;
nm_rgb_t err_color;
nm_glyph_t glyphs;
nm_str_t debug_path;
uint64_t daemon_sleep;
Expand All @@ -63,6 +64,7 @@ typedef struct {
uint32_t spice_default:1;
uint32_t log_enabled:1;
uint32_t hl_is_set:1;
uint32_t err_is_set:1;
uint32_t debug:1;
} nm_cfg_t;

Expand Down
8 changes: 7 additions & 1 deletion src/nm_main_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ void nm_start_main_loop(void)

nm_filter = NM_INIT_FILTER;
init_pair(NM_COLOR_BLACK, COLOR_BLACK, COLOR_WHITE);
init_pair(NM_COLOR_RED, COLOR_RED, COLOR_WHITE);
if (cfg->hl_is_set && can_change_color()) {
init_color(COLOR_WHITE + 1,
cfg->hl_color.r, cfg->hl_color.g, cfg->hl_color.b);
init_pair(NM_COLOR_HIGHLIGHT, COLOR_WHITE + 1, -1);
} else {
init_pair(NM_COLOR_HIGHLIGHT, COLOR_GREEN, -1);
}
if (cfg->err_is_set && can_change_color()) {
init_color(COLOR_WHITE + 2,
cfg->err_color.r, cfg->err_color.g, cfg->err_color.b);
init_pair(NM_COLOR_RED, COLOR_WHITE + 2, COLOR_WHITE);
} else {
init_pair(NM_COLOR_RED, COLOR_RED, COLOR_WHITE);
}

nm_create_windows();
nm_init_help_main();
Expand Down

0 comments on commit cae8505

Please sign in to comment.