Skip to content

Commit

Permalink
Tek: support config font changes and OSC font/colour changes while in…
Browse files Browse the repository at this point in the history
… Tek mode
  • Loading branch information
mintty committed Jul 14, 2020
1 parent e9f3357 commit 5552bf1
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
11 changes: 10 additions & 1 deletion src/tek.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static short tek_y, tek_x;
static short gin_y, gin_x;
static uchar lastfont = 0;
static int lastwidth = -1;
static wchar * tek_dyn_font = 0;

static int beam_glow = 1;
static int thru_glow = 5;
Expand Down Expand Up @@ -489,13 +490,21 @@ get_font_quality(void)
}[(int)cfg.font_smoothing];
}

void
tek_set_font(wchar * fn)
{
if (tek_dyn_font)
free(tek_dyn_font);
tek_dyn_font = fn;
}

static void
init_font(short f)
{
if (tekfonts[f].f)
DeleteObject(tekfonts[f].f);

wstring fn = *cfg.tek_font ? cfg.tek_font : cfg.font.name;
wstring fn = tek_dyn_font ?: *cfg.tek_font ? cfg.tek_font : cfg.font.name;
tekfonts[f].f = CreateFontW(
- tekfonts[f].hei, - tekfonts[f].wid,
0, 0, FW_NORMAL, 0, 0, 0,
Expand Down
1 change: 1 addition & 0 deletions src/tek.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ extern void tek_enq(void);
extern void tek_alt(bool);
extern void tek_copy(void);
extern void tek_clear(void);
extern void tek_set_font(wchar * fn);

extern void tek_move_to(int y, int x);
extern void tek_move_by(int dy, int dx);
Expand Down
27 changes: 17 additions & 10 deletions src/termout.c
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,8 @@ tek_esc(char c)
when CTRL('C'):
tek_mode = TEKMODE_OFF;
win_invalidate_all(false);
when ']': /* OSC: operating system command */
term.state = OSC_START;
}
}

Expand Down Expand Up @@ -3633,20 +3635,25 @@ do_cmd(void)
term.wide_extra = true;
}
when 52: do_clipboard();
when 50: {
uint ff = (term.curs.attr.attr & FONTFAM_MASK) >> ATTR_FONTFAM_SHIFT;
if (!strcmp(s, "?")) {
char * fn = cs__wcstombs(win_get_font(ff) ?: W(""));
child_printf("\e]50;%s\e\\", fn);
free(fn);
when 50:
if (tek_mode) {
tek_set_font(cs__mbstowcs(s));
tek_init(cfg.tek_glow);
}
else {
if (ff < lengthof(cfg.fontfams) - 1) {
wstring wfont = cs__mbstowcs(s); // let this leak...
win_change_font(ff, wfont);
uint ff = (term.curs.attr.attr & FONTFAM_MASK) >> ATTR_FONTFAM_SHIFT;
if (!strcmp(s, "?")) {
char * fn = cs__wcstombs(win_get_font(ff) ?: W(""));
child_printf("\e]50;%s\e\\", fn);
free(fn);
}
else {
if (ff < lengthof(cfg.fontfams) - 1) {
wstring wfont = cs__mbstowcs(s); // let this leak...
win_change_font(ff, wfont);
}
}
}
}
when 8: { // hyperlink attribute
char * link = s;
char * url = strchr(s, ';');
Expand Down
2 changes: 2 additions & 0 deletions src/winmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -2178,6 +2178,8 @@ font_cs_reconfig(bool font_changed)
{
if (font_changed) {
win_init_fonts(cfg.font.size);
if (tek_mode)
tek_init(cfg.tek_glow);
trace_resize((" (font_cs_reconfig -> win_adapt_term_size)\n"));
win_adapt_term_size(true, false);
}
Expand Down

0 comments on commit 5552bf1

Please sign in to comment.