diff --git a/stand/common/gfx_fb.h b/stand/common/gfx_fb.h --- a/stand/common/gfx_fb.h +++ b/stand/common/gfx_fb.h @@ -277,6 +277,7 @@ int gfx_fb_putimage(png_t *, uint32_t, uint32_t, uint32_t, uint32_t, uint32_t); bool gfx_parse_mode_str(char *, int *, int *, int *); +void gfx_fb_setcolors(teken_attr_t *, ev_sethook_t, ev_unsethook_t); void term_image_display(teken_gfx_t *, const teken_rect_t *); void reset_font_flags(void); diff --git a/stand/common/gfx_fb.c b/stand/common/gfx_fb.c --- a/stand/common/gfx_fb.c +++ b/stand/common/gfx_fb.c @@ -232,6 +232,37 @@ return (true); } +void +gfx_fb_setcolors(teken_attr_t *attr, ev_sethook_t sethook, + ev_unsethook_t unsethook) +{ + const char *ptr; + char env[10]; + + /* + * On first run, we setup an environment hook to process any color + * changes. If the env is already set, we pick up fg and bg color + * values from the environment. + */ + ptr = getenv("teken.fg_color"); + if (ptr != NULL) { + attr->ta_fgcolor = strtol(ptr, NULL, 10); + ptr = getenv("teken.bg_color"); + attr->ta_bgcolor = strtol(ptr, NULL, 10); + + teken_set_defattr(&gfx_state.tg_teken, attr); + } else { + snprintf(env, sizeof(env), "%d", + attr->ta_fgcolor); + env_setenv("teken.fg_color", EV_VOLATILE, env, + sethook, unsethook); + snprintf(env, sizeof(env), "%d", + attr->ta_bgcolor); + env_setenv("teken.bg_color", EV_VOLATILE, env, + sethook, unsethook); + } +} + static uint32_t rgb_color_map(uint8_t index, uint32_t rmax, int roffset, uint32_t gmax, int goffset, uint32_t bmax, int boffset) diff --git a/stand/efi/libefi/efi_console.c b/stand/efi/libefi/efi_console.c --- a/stand/efi/libefi/efi_console.c +++ b/stand/efi/libefi/efi_console.c @@ -1041,28 +1041,7 @@ a = teken_get_defattr(&gfx_state.tg_teken); attr = *a; - /* - * On first run, we set up the efi_set_colors() - * callback. If the env is already set, we - * pick up fg and bg color values from the environment. - */ - ptr = getenv("teken.fg_color"); - if (ptr != NULL) { - attr.ta_fgcolor = strtol(ptr, NULL, 10); - ptr = getenv("teken.bg_color"); - attr.ta_bgcolor = strtol(ptr, NULL, 10); - - teken_set_defattr(&gfx_state.tg_teken, &attr); - } else { - snprintf(env, sizeof(env), "%d", - attr.ta_fgcolor); - env_setenv("teken.fg_color", EV_VOLATILE, env, - efi_set_colors, env_nounset); - snprintf(env, sizeof(env), "%d", - attr.ta_bgcolor); - env_setenv("teken.bg_color", EV_VOLATILE, env, - efi_set_colors, env_nounset); - } + gfx_fb_setcolors(&attr, efi_set_colors, env_nounset); } } diff --git a/stand/i386/libi386/vidconsole.c b/stand/i386/libi386/vidconsole.c --- a/stand/i386/libi386/vidconsole.c +++ b/stand/i386/libi386/vidconsole.c @@ -956,26 +956,7 @@ a = teken_get_defattr(&gfx_state.tg_teken); attr = *a; - /* - * On first run, we set up the vidc_set_colors() - * callback. If the env is already set, we - * pick up fg and bg color values from the environment. - */ - ptr = getenv("teken.fg_color"); - if (ptr != NULL) { - attr.ta_fgcolor = strtol(ptr, NULL, 10); - ptr = getenv("teken.bg_color"); - attr.ta_bgcolor = strtol(ptr, NULL, 10); - - teken_set_defattr(&gfx_state.tg_teken, &attr); - } else { - snprintf(env, sizeof(env), "%d", attr.ta_fgcolor); - env_setenv("teken.fg_color", EV_VOLATILE, env, - vidc_set_colors, env_nounset); - snprintf(env, sizeof(env), "%d", attr.ta_bgcolor); - env_setenv("teken.bg_color", EV_VOLATILE, env, - vidc_set_colors, env_nounset); - } + gfx_fb_setcolors(&attr, vidc_set_colors, env_nounset); /* Improve visibility */ if (attr.ta_bgcolor == TC_WHITE)