From d9f71e20bb5330bf9e0eac29a0d74b8fdd7dfa0e Mon Sep 17 00:00:00 2001 From: Nate Moore Date: Fri, 5 Jun 2026 01:11:14 -0500 Subject: [PATCH] fix: leave terminal default foreground for uncolored text Text with no explicit color was packed as concrete white (0xFFFFFFFF), forcing white on light-background terminals. Encode absent color as ATTR_DEFAULT (0x80 in the attrs byte) so the C path skips the foreground SGR entirely, mirroring how an unset background is already left alone. Fixes #62 --- ops.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ops.ts b/ops.ts index a52485d..776bfed 100644 --- a/ops.ts +++ b/ops.ts @@ -202,14 +202,18 @@ export function pack( case OP_TEXT: { view.setUint32(o, OP_TEXT, true); o += 4; - view.setUint32(o, op.color ?? 0xFFFFFFFF, true); + // No explicit color: leave the terminal default foreground by writing + // 0 and setting ATTR_DEFAULT (0x80 in the attrs byte). The C path ORs + // it into fg and emit_attr skips the foreground SGR (mirrors unset bg). + let textDefault = op.color === undefined; + view.setUint32(o, op.color ?? 0, true); o += 4; view.setUint32( o, (op.fontSize ?? 1) | ((op.fontId ?? 0) << 8) | ((op.wrap ?? 0) << 16) | - ((op.attrs ?? 0) << 24), + (((op.attrs ?? 0) | (textDefault ? 0x80 : 0)) << 24), true, ); o += 4; -- 2.51.2