Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions test/default-foreground.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { text } from "../ops.ts";
import { createTerm } from "../term.ts";
import { describe, expect, it } from "./suite.ts";

const decode = (b: Uint8Array) => new TextDecoder().decode(b);

describe("true default foreground", () => {
it("emits uncolored text with no concrete foreground", async () => {
let term = await createTerm({ width: 12, height: 1 });
let ansi = decode(term.render([text("hi")]).output);

expect(ansi).toContain("hi");
expect(ansi).not.toContain("\x1b[38;2;255;255;255");
});
});
Loading