commit 30e77f6ad14985d6db8d179b7ed73dc4c8cab68a from: Mark Jamsek via: Thomas Adam date: Sun Sep 18 07:48:21 2022 UTC tog: don't embed utf8 glyphs into tog.c source code Reported by stsp: Embedded utf8 precludes developers running C locales from browsing the code. Fix was suggested by stsp with hints from the tmux(1) codebase. ok stsp@ commit - 2a7d3cd7fd18be5657ca71a452a73ba70a8530e5 commit + 30e77f6ad14985d6db8d179b7ed73dc4c8cab68a blob - d338b7cb55c642cdd9c04cf53565845ae158d065 blob + a2ad8c27009958805e6bb47498c2f321dd725a1a --- tog/tog.c +++ tog/tog.c @@ -8489,11 +8489,6 @@ max_key_str(int *ret, const struct tog_key_map *km, si * Write keymap section headers, keys, and key info in km to f. * Save line offset to *off. If terminal has UTF8 encoding enabled, * wrap control and symbolic keys in guillemets, else use <>. - * For example (top=UTF8, bottom=ASCII): - * Global - * k ❬C-p❭ ❬Up❭ Move cursor or page up one line - * Global - * k Move cursor or page up one line */ static const struct got_error * format_help_line(off_t *off, FILE *f, const struct tog_key_map *km, int width) @@ -8501,6 +8496,10 @@ format_help_line(off_t *off, FILE *f, const struct tog int n, len = width; if (km->keys) { + static const char *u8_glyph[] = { + "\xe2\x80\xb9", /* U+2039 (utf8 <) */ + "\xe2\x80\xba" /* U+203A (utf8 >) */ + }; char *t0, *t, *k; int cs, s, first = 1; @@ -8514,8 +8513,8 @@ format_help_line(off_t *off, FILE *f, const struct tog while ((k = strsep(&t, " ")) != NULL) { s = strlen(k) > 1; /* control or symbolic key */ n = fprintf(f, "%s%s%s%s%s", first ? " " : "", - cs && s ? "❬" : s ? "<" : "", k, - cs && s ? "❭" : s ? ">" : "", t ? " " : ""); + cs && s ? u8_glyph[0] : s ? "<" : "", k, + cs && s ? u8_glyph[1] : s ? ">" : "", t ? " " : ""); if (n < 0) { free(t0); return got_error_from_errno("fprintf");