From 99a4eaac23c61dcb98d8261f58b2fa000d72ac31 Mon Sep 17 00:00:00 2001 From: mintsuki Date: Tue, 22 Mar 2022 04:09:29 +0100 Subject: [PATCH] config: Sanitise names of terminal keys --- CONFIG.md | 37 +++++++++++++--------------- common/lib/gterm.c | 60 ++++++++++++++++------------------------------ test/limine.cfg | 7 +++--- 3 files changed, 40 insertions(+), 64 deletions(-) diff --git a/CONFIG.md b/CONFIG.md index 2b2fd3b6..21208bb5 100644 --- a/CONFIG.md +++ b/CONFIG.md @@ -66,26 +66,23 @@ Some keys take *URIs* as values; these are described in the next section. * `MENU_BRANDING` - A string that will be displayed on top of the Limine menu. * `MENU_BRANDING_COLOUR` - A value between 0 and 7 specifying the colour of the branding string. Default is cyan (6). * `MENU_BRANDING_COLOR` - Alias of `MENU_BRANDING_COLOUR`. -* `MENU_FONT` - URI path to a font file to be used instead of the default one for the menu and terminal. The font file must be a code page 437 character set comprised of 256 consecutive glyph bitmaps. Each glyph's bitmap must be expressed left to right (1 byte per row), and top to bottom (16 bytes per whole glyph by default; see `MENU_FONT_SIZE`). See e.g. the [VGA text mode font collection](https://github.com/viler-int10h/vga-text-mode-fonts) for fonts. -* `TERMINAL_FONT` - Alias of `MENU_FONT`. -* `MENU_FONT_SIZE` - The size of the font in dots, which must correspond to the font file or the display will be garbled. Note that glyphs are always one byte wide, and columns over 8 are empty. Many fonts may be used in both 8- and 9-dot wide variants. Defaults to `8x16`. Ignored if `MENU_FONT` or `TERMINAL_FONT` not set or if the font fails to load. -* `TERMINAL_FONT_SIZE` - Alias of `MENU_FONT_SIZE`. -* `MENU_FONT_SCALE` - Scaling for the font in the x and y directions. `2x2` would display the font in double size, which is useful on high-DPI displays at native resolution. `2x1` only makes the font twice as wide, similar to the VGA 40 column mode. `4x2` might be good for a narrow font on a high resolution display. Values over 8 are disallowed. Default is no scaling, i.e. `1x1`. -* `TERMINAL_FONT_SCALE` - Alias of `MENU_FONT_SCALE`. -* `MENU_FONT_SPACING` - Horizontal spacing, in pixels, between glyphs on screen. It is equivalent to setting a font width of `+`, except this value is preserved even in case font loading fails, and it also applies to the built-in Limine font. Defaults to 1. 0 is allowed. -* `TERMINAL_FONT_SPACING` - Alias of `MENU_FONT_SPACING`. -* `THEME_COLOURS` - Specifies the colour palette used by the terminal (AARRGGBB). It is a `;` separated array of 10 colours: black, red, green, brown, blue, magenta, cyan, gray, background, and foreground respectively. While an alpha transparency value can be specified for every colour, it is ignored for all but background. Ignored if `GRAPHICS` is not `yes`. -* `THEME_COLORS` - Alias of `THEME_COLOURS`. -* `THEME_BACKGROUND` - Alias of the background value in `THEME_COLOURS`. -* `THEME_FOREGROUND` - Alias of the foreground value in `THEME_COLOURS`. -* `THEME_BRIGHT_COLOURS` - Specifies the bright colour palette used by the terminal (XXRRGGBB). It is a `;` separated array of 8 bright colours: dark gray, bright red, bright green, yellow, bright blue, bright magenta, bright cyan, and white respectively. Alpha transparency values are ignored. Ignored if `GRAPHICS` is not `yes`. -* `THEME_BRIGHT_COLORS` - Alias of `THEME_BRIGHT_COLOURS`. -* `THEME_MARGIN` - Set the amount of margin around the terminal. Ignored if `GRAPHICS` is not `yes`. -* `THEME_MARGIN_GRADIENT` - Set the thickness in pixel for the gradient around the terminal. Ignored if `GRAPHICS` is not `yes`. -* `BACKGROUND_PATH` - URI where to find the background .BMP file. Ignored if `GRAPHICS` is not `yes`. -* `BACKGROUND_STYLE` - The style which will be used to display the background image: `tiled`, `centered`, or `stretched`. Default is `tiled`. -* `BACKDROP_COLOUR` - When the background style is `centered`, this specifies the colour of the backdrop for parts of the screen not covered by the background image, in RRGGBB format. -* `BACKDROP_COLOR` - Alias of `BACKDROP_COLOUR`. + +The following options control Limine's graphical terminal. They are ignored if using text mode. + +* `TERM_FONT` - URI path to a font file to be used instead of the default one for the menu and terminal. The font file must be a code page 437 character set comprised of 256 consecutive glyph bitmaps. Each glyph's bitmap must be expressed left to right (1 byte per row), and top to bottom (16 bytes per whole glyph by default; see `TERM_FONT_SIZE`). See e.g. the [VGA text mode font collection](https://github.com/viler-int10h/vga-text-mode-fonts) for fonts. +* `TERM_FONT_SIZE` - The size of the font in dots, which must correspond to the font file or the display will be garbled. Note that glyphs are always one byte wide, and columns over 8 are empty. Many fonts may be used in both 8- and 9-dot wide variants. Defaults to `8x16`. Ignored if `TERM_FONT` not set or if the font fails to load. +* `TERM_FONT_SCALE` - Scaling for the font in the x and y directions. `2x2` would display the font in double size, which is useful on high-DPI displays at native resolution. `2x1` only makes the font twice as wide, similar to the VGA 40 column mode. `4x2` might be good for a narrow font on a high resolution display. Values over 8 are disallowed. Default is no scaling, i.e. `1x1`. +* `TERM_FONT_SPACING` - Horizontal spacing, in pixels, between glyphs on screen. It is equivalent to setting a font width of `+`, except this value is preserved even in case font loading fails, and it also applies to the built-in Limine font. Defaults to 1. 0 is allowed. +* `TERM_PALETTE` - Specifies the colour palette used by the terminal (RRGGBB). It is a `;` separated array of 8 colours: black, red, green, brown, blue, magenta, cyan, and gray. Ignored if not using a graphical terminal. +* `TERM_PALETTE_BRIGHT` - Specifies the bright colour palette used by the terminal (RRGGBB). It is a `;` separated array of 8 bright colours: dark gray, bright red, bright green, yellow, bright blue, bright magenta, bright cyan, and white. Ignored if not using a graphical terminal. +* `TERM_BACKGROUND` - Terminal text background colour (TTRRGGBB). TT stands for transparency. +* `TERM_FOREGROUND` - Terminal text foreground colour (RRGGBB). +* `TERM_MARGIN` - Set the amount of margin around the terminal. +* `TERM_MARGIN_GRADIENT` - Set the thickness in pixel for the gradient around the terminal. +* `TERM_WALLPAPER` - URI where to find the .BMP file to use as wallpaper. +* `TERM_WALLPAPER_STYLE` - The style which will be used to display the wallpaper image: `tiled`, `centered`, or `stretched`. Default is `stretched`. +* `TERM_BACKDROP` - When the background style is `centered`, this specifies the colour of the backdrop for parts of the screen not covered by the background image, in RRGGBB format. + * `EDITOR_ENABLED` - If set to `no`, the editor will not be accessible. Defaults to `yes`. * `EDITOR_HIGHLIGHTING` - If set to `no`, syntax highlighting in the editor will be disabled. Defaults to `yes`. * `EDITOR_VALIDATION` - If set to `no`, the editor will not alert you about invalid keys / syntax errors. Defaults to `yes`. diff --git a/common/lib/gterm.c b/common/lib/gterm.c index d0e60f81..865e37c2 100644 --- a/common/lib/gterm.c +++ b/common/lib/gterm.c @@ -646,9 +646,6 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { margin = 64; margin_gradient = 4; - default_bg = 0x00000000; // background (black) - default_fg = 0x00aaaaaa; // foreground (grey) - ansi_colours[0] = 0x00000000; // black ansi_colours[1] = 0x00aa0000; // red ansi_colours[2] = 0x0000aa00; // green @@ -658,24 +655,16 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { ansi_colours[6] = 0x0000aaaa; // cyan ansi_colours[7] = 0x00aaaaaa; // grey - char *colours = config_get_value(NULL, 0, "THEME_COLOURS"); - if (colours == NULL) - colours = config_get_value(NULL, 0, "THEME_COLORS"); + char *colours = config_get_value(NULL, 0, "TERM_PALETTE"); if (colours != NULL) { const char *first = colours; size_t i; - for (i = 0; i < 10; i++) { + for (i = 0; i < 8; i++) { const char *last; uint32_t col = strtoui(first, &last, 16); if (first == last) break; - if (i < 8) { - ansi_colours[i] = col & 0xffffff; - } else if (i == 8) { - default_bg = col; - } else if (i == 9) { - default_fg = col & 0xffffff; - } + ansi_colours[i] = col & 0xffffff; if (*last == 0) break; first = last + 1; @@ -691,9 +680,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { ansi_bright_colours[6] = 0x0055ffff; // cyan ansi_bright_colours[7] = 0x00ffffff; // grey - char *bright_colours = config_get_value(NULL, 0, "THEME_BRIGHT_COLOURS"); - if (bright_colours == NULL) - bright_colours = config_get_value(NULL, 0, "THEME_BRIGHT_COLORS"); + char *bright_colours = config_get_value(NULL, 0, "TERM_PALETTE_BRIGHT"); if (bright_colours != NULL) { const char *first = bright_colours; size_t i; @@ -709,12 +696,15 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { } } - char *theme_background = config_get_value(NULL, 0, "THEME_BACKGROUND"); + default_bg = 0x00000000; // background (black) + default_fg = 0x00aaaaaa; // foreground (grey) + + char *theme_background = config_get_value(NULL, 0, "TERM_BACKGROUND"); if (theme_background != NULL) { default_bg = strtoui(theme_background, NULL, 16); } - char *theme_foreground = config_get_value(NULL, 0, "THEME_FOREGROUND"); + char *theme_foreground = config_get_value(NULL, 0, "TERM_FOREGROUND"); if (theme_foreground != NULL) { default_fg = strtoui(theme_foreground, NULL, 16) & 0xffffff; } @@ -723,7 +713,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { text_bg = 0xffffffff; background = NULL; - char *background_path = config_get_value(NULL, 0, "BACKGROUND_PATH"); + char *background_path = config_get_value(NULL, 0, "TERM_WALLPAPER"); if (background_path != NULL) { struct file_handle *bg_file; if ((bg_file = uri_open(background_path)) != NULL) { @@ -737,27 +727,26 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { margin_gradient = 0; } - char *theme_margin = config_get_value(NULL, 0, "THEME_MARGIN"); + char *theme_margin = config_get_value(NULL, 0, "TERM_MARGIN"); if (theme_margin != NULL) { margin = strtoui(theme_margin, NULL, 10); } - char *theme_margin_gradient = config_get_value(NULL, 0, "THEME_MARGIN_GRADIENT"); + char *theme_margin_gradient = config_get_value(NULL, 0, "TERM_MARGIN_GRADIENT"); if (theme_margin_gradient != NULL) { margin_gradient = strtoui(theme_margin_gradient, NULL, 10); } if (background != NULL) { - char *background_layout = config_get_value(NULL, 0, "BACKGROUND_STYLE"); + char *background_layout = config_get_value(NULL, 0, "TERM_WALLPAPER_STYLE"); if (background_layout != NULL && strcmp(background_layout, "centered") == 0) { - char *background_colour = config_get_value(NULL, 0, "BACKDROP_COLOUR"); - if (background_colour == NULL) - background_colour = config_get_value(NULL, 0, "BACKDROP_COLOR"); + char *background_colour = config_get_value(NULL, 0, "TERM_BACKDROP"); if (background_colour == NULL) background_colour = "0"; uint32_t bg_col = strtoui(background_colour, NULL, 16); image_make_centered(background, fbinfo.framebuffer_width, fbinfo.framebuffer_height, bg_col); - } else if (background_layout != NULL && strcmp(background_layout, "stretched") == 0) { + } else if (background_layout != NULL && strcmp(background_layout, "tiled") == 0) { + } else { image_make_stretched(background, fbinfo.framebuffer_width, fbinfo.framebuffer_height); } } @@ -786,9 +775,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { size_t tmp_font_width, tmp_font_height; - char *menu_font_size = config_get_value(NULL, 0, "MENU_FONT_SIZE"); - if (menu_font_size == NULL) - menu_font_size = config_get_value(NULL, 0, "TERMINAL_FONT_SIZE"); + char *menu_font_size = config_get_value(NULL, 0, "TERM_FONT_SIZE"); if (menu_font_size != NULL) { parse_resolution(&tmp_font_width, &tmp_font_height, NULL, menu_font_size); @@ -802,9 +789,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { font_bytes = tmp_font_bytes; } - char *menu_font = config_get_value(NULL, 0, "MENU_FONT"); - if (menu_font == NULL) - menu_font = config_get_value(NULL, 0, "TERMINAL_FONT"); + char *menu_font = config_get_value(NULL, 0, "TERM_FONT"); if (menu_font != NULL) { struct file_handle *f; if ((f = uri_open(menu_font)) == NULL) { @@ -821,9 +806,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) { no_load_font:; size_t font_spacing = 1; - char *font_spacing_str = config_get_value(NULL, 0, "MENU_FONT_SPACING"); - if (font_spacing_str == NULL) - font_spacing_str = config_get_value(NULL, 0, "TERMINAL_FONT_SPACING"); + char *font_spacing_str = config_get_value(NULL, 0, "TERM_FONT_SPACING"); if (font_spacing_str != NULL) { font_spacing = strtoui(font_spacing_str, NULL, 10); } @@ -865,10 +848,7 @@ no_load_font:; vga_font_scale_x = 1; vga_font_scale_y = 1; - char *menu_font_scale = config_get_value(NULL, 0, "MENU_FONT_SCALE"); - if (menu_font_scale == NULL) { - menu_font_scale = config_get_value(NULL, 0, "TERMINAL_FONT_SCALE"); - } + char *menu_font_scale = config_get_value(NULL, 0, "TERM_FONT_SCALE"); if (menu_font_scale != NULL) { parse_resolution(&vga_font_scale_x, &vga_font_scale_y, NULL, menu_font_scale); if (vga_font_scale_x > 8 || vga_font_scale_y > 8) { diff --git a/test/limine.cfg b/test/limine.cfg index f8a1f4f5..775cfc87 100644 --- a/test/limine.cfg +++ b/test/limine.cfg @@ -5,11 +5,10 @@ DEFAULT_ENTRY=1 TIMEOUT=3 VERBOSE=yes -THEME_BACKGROUND=68000000 +TERM_BACKGROUND=68000000 -BACKGROUND_PATH=${BACKGROUND_PATH} -BACKGROUND_STYLE=stretched -BACKDROP_COLOUR=008080 +TERM_WALLPAPER=${BACKGROUND_PATH} +TERM_BACKDROP=008080 :Limine Test