gterm: Add config aliases and other minor fixes

This commit is contained in:
mintsuki 2021-08-18 21:02:03 +02:00
parent 3f0c97dbde
commit fa0aa6d7b9
4 changed files with 19 additions and 10 deletions

View File

@ -59,7 +59,9 @@ Some keys take *URIs* as values; these are described in the next section.
* `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`.
* `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`.
* `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`.

View File

@ -658,13 +658,15 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
gterm_bpp = fbinfo.framebuffer_bpp;
gterm_pitch = fbinfo.framebuffer_pitch;
size_t font_width = vga_font_width, font_height = vga_font_height;
char *menu_font_size = config_get_value(NULL, 0, "MENU_FONT_SIZE");
if (menu_font_size != NULL)
parse_resolution(&font_width, &font_height, NULL, menu_font_size);
if (menu_font_size == NULL) {
menu_font_size = config_get_value(NULL, 0, "TERMINAL_FONT_SIZE");
}
if (menu_font_size != NULL) {
parse_resolution(&vga_font_width, &vga_font_height, NULL, menu_font_size);
}
size_t font_bytes = (font_width * font_height * VGA_FONT_GLYPHS) / 8;
size_t font_bytes = (vga_font_width * vga_font_height * VGA_FONT_GLYPHS) / 8;
if (vga_font_bits == NULL) {
vga_font_bits = ext_mem_alloc(VGA_FONT_MAX);
@ -675,7 +677,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
char *menu_font = NULL;
if (font_bytes > VGA_FONT_MAX) {
print("Font would be too large (%x bytes, %x bytes allowed). Not loading.\n");
print("Font would be too large (%x bytes, %x bytes allowed). Not loading.\n", font_bytes, VGA_FONT_MAX);
} else {
menu_font = config_get_value(NULL, 0, "MENU_FONT");
if (menu_font == NULL)
@ -687,10 +689,7 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
if (!uri_open(&f, menu_font)) {
print("menu: Could not open font file.\n");
} else {
if (fread(&f, vga_font_bits, 0, font_bytes) == 0) {
vga_font_width = font_width;
vga_font_height = font_height;
}
fread(&f, vga_font_bits, 0, font_bytes);
}
}
@ -730,6 +729,9 @@ bool gterm_init(size_t *_rows, size_t *_cols, size_t width, size_t height) {
}
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");
}
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) {

View File

@ -80,7 +80,10 @@ static const char *VALID_KEYS[] = {
"MENU_BRANDING",
"MENU_FONT",
"MENU_FONT_SIZE",
"MENU_FONT_SCALE",
"TERMINAL_FONT",
"TERMINAL_FONT_SIZE",
"TERMINAL_FONT_SCALE",
"THEME_COLOURS",
"THEME_COLORS",
"THEME_BRIGHT_COLOURS",

View File

@ -3,6 +3,8 @@ TIMEOUT=3
GRAPHICS=yes
MENU_FONT=boot:///boot/font.bin
VERBOSE=yes
TERMINAL_FONT_SIZE=9x16
TERMINAL_FONT_SCALE=1x1
THEME_BACKGROUND=50000000