summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--term.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/term.c b/term.c
index 426cd7f..c268c77 100644
--- a/term.c
+++ b/term.c
@@ -15,6 +15,7 @@
  */
 
 #include <err.h>
+#include <stdarg.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -33,6 +34,17 @@ enum {
 	DEL = 0x7F,
 };
 
+static char unhandled(const char *format, ...) {
+	if (isatty(STDERR_FILENO)) return NUL;
+	va_list ap;
+	va_start(ap, format);
+	char buf[256];
+	vsnprintf(buf, sizeof(buf), format, ap);
+	warnx("unhandled %s", buf);
+	va_end(ap);
+	return NUL;
+}
+
 static const struct Style Default = { .bg = -1, .fg = -1 };
 
 static uint rows, cols;
@@ -81,21 +93,10 @@ static char updateNUL(wchar_t ch) {
 		}
 
 		break; default: {
-			// FIXME: Nowhere for these warnings to go.
-			if (ch < ' ') {
-				warnx("unhandled \\x%02X", ch);
-				return NUL;
-			}
-
 			int width = wcwidth(ch);
-			if (width < 0) {
-				warnx("unhandled \\u%X", ch);
-				return NUL;
-			}
-			if (x + width > cols) {
-				warnx("cannot fit '%lc'", ch);
-				return NUL;
-			}
+			if (ch < ' ') return unhandled("\\x%02X", ch);
+			if (width < 0) return unhandled("\\u%X", ch);
+			if (x + width > cols) return unhandled("'%lc' too wide", ch);
 
 			if (insert) {
 				move(cell(y, x + width), cell(y, x), cols - x - width);
@@ -131,8 +132,7 @@ static char updateESC(wchar_t ch) {
 		case '>': return NUL;
 		case CSI: return CSI;
 		case OSC: return OSC;
-		// FIXME: Nowhere for this warning to go.
-		default: warnx("unhandled ESC %lc", ch); return NUL;
+		default:  return unhandled("ESC %lc", ch);
 	}
 }
 
@@ -306,19 +306,16 @@ static char updateCSI(wchar_t ch) {
 			clear(cell(y, cols - i), cell(y, cols - 1));
 		}
 
-		// FIXME: Nowhere for these warnings to go.
 		break; case SM: {
-			if (dec) break;
 			switch (ps[0]) {
 				break; case Insert: insert = true;
-				break; default: warnx("unhandled SM %u", ps[0]);
+				break; default: unhandled("SM %s%u", (dec ? "? " : ""), ps[0]);
 			}
 		}
 		break; case RM: {
-			if (dec) break;
 			switch (ps[0]) {
 				break; case Insert: insert = false;
-				break; default: warnx("unhandled RM %u", ps[0]);
+				break; default: unhandled("RM %s%u", (dec ? "? " : ""), ps[0]);
 			}
 		}
 
@@ -330,8 +327,7 @@ static char updateCSI(wchar_t ch) {
 		}
 
 		break; case 't': // ignore
-		// FIXME: Nowhere for this warning to go.
-		break; default: warnx("unhandled CSI %lc", ch);
+		break; default: unhandled("CSI %s%lc", (dec ? "? " : ""), ch);
 	}
 
 	dec = false;