"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
tog: don't embded utf8 glyphs in tog.c
To:
Game of Trees <gameoftrees@openbsd.org>
Date:
Sun, 18 Sep 2022 02:05:35 +1000

Download raw body.

Thread
This fixes the problem stsp reported of making utf8 enabled editors
necessary to browse the code.

I also found prettier single guillemets to wrap the control chars.

-----------------------------------------------
commit 52463cd85fca4c6634b1be23cbe2ba8ebcbbe872 (main)
from: Mark Jamsek <mark@jamsek.dev>
date: Sat Sep 17 16:00:38 2022 UTC
 
 tog: don't embded utf8 glyphs into tog.c source code
 
 Suggested by stsp. Embedded utf8 precludes developers running C locales
 from browsing the code.
 
diff eaf2c13e05bf70e2d0819292768dad7bbadaa8f3 52463cd85fca4c6634b1be23cbe2ba8ebcbbe872
commit - eaf2c13e05bf70e2d0819292768dad7bbadaa8f3
commit + 52463cd85fca4c6634b1be23cbe2ba8ebcbbe872
blob - cd0eb94e4774f59e2fb7433accbb170c140d3053
blob + 718c6aa923bbf38b917e3e3902ff58f1920a570a
--- tog/tog.c
+++ tog/tog.c
@@ -8484,11 +8484,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 <C-p> <Up>               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)
@@ -8496,6 +8491,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;
 
@@ -8509,8 +8508,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");

-- 
Mark Jamsek <fnc.bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68