ctrl+/- change font size on mintty terminal.
However, the steps in some place are quite large. Can I change the progression so I can fit to my window better?
Short answer: there’s no way to configure this behaviour without modifying the source.
Since mintty is free software (GPL), I checked out its source code from the mintty GitHub repository. It’s written in C and the code turns out to be fairly readable (I’m a sysadmin, not a programmer) and I’ve copied some of the relevant code here.
You can see from the following code in wininput.c
that the zooming happens in discrete steps of 1 (increase the font size) or -1 (decrease) that are added to the current font size and that no configuration settings are used to control the size of the steps.
// Font zooming
if (cfg.zoom_shortcuts && mods == MDK_CTRL) {
int zoom;
switch (key) {
when VK_OEM_PLUS or VK_ADD: zoom = 1;
when VK_OEM_MINUS or VK_SUBTRACT: zoom = -1;
when '0' or VK_NUMPAD0: zoom = 0;
otherwise: goto not_zoom;
}
win_zoom_font(zoom);
return 1;
not_zoom:;
}
The relevant functions are defined in wintext.c
:
void
win_set_font_size(int size)
{
size = size ? sgn(font_size) * min(size, 72) : cfg.font.size;
if (size != font_size) {
win_init_fonts(size);
win_adapt_term_size();
}
}
void
win_zoom_font(int zoom)
{
win_set_font_size(zoom ? max(1, abs(font_size) + zoom) : 0);
}
The win_adapt_term_size
function ensures that the window size adapts to display the rows and lines in units of the new font size.
Note that sgn
is a macro which returns the sign of a number (represented as an integer). From std.h
:
#define sgn(x) ({ typeof(x) x_ = (x); (x_ > 0) - (x_ < 0); })
From config.c
, we can see that the initial font size is taken from the FontHeight
configured in ~/.minttyrc
.
{"FontHeight", OPT_INT, offcfg(font.size)},
How the differences in font size are displayed depends on the both the selected font and the font rendering software.
I’ve attached a screenshot showing how Lucida Console and Consolas are displayed at different font sizes in Windows 7 using DirectWrite, the newer font rendering API released with Windows 7 to replace the older GDI rendering engine.
As you can see, the variation in the rendered size of the font is not exactly linearly in proportion to the specified font size. I remember spending time choosing a font that displayed well at different sizes and Consolas (with ClearType enabled) gave me the best results.