@@ -13,6 +13,11 @@ const ESCAPE = kittyEncode("escape");
1313 const SHIFT_TAB = kittyEncode("shift+tab");
1414 const CTRL_S = kittyEncode("ctrl+s");
1515 const LEGACY_CTRL_R = "\x12";
16+const TITLE_SEQUENCE_RE = /\x1b\][02];([^\x07\x1b]*)(?:\x07|\x1b\\)/g;
17+
18+function extractTitlePayloads(output: string): string[] {
19+ return Array.from(output.matchAll(TITLE_SEQUENCE_RE), (match) => match[1]!);
20+}
1621
1722 describe("cel end-to-end", () => {
1823 let term: MockTerminal;
@@ -138,6 +143,43 @@ describe("cel end-to-end", () => {
138143 expect(term.output).toContain("\x1b[?2026l");
139144 });
140145
146+ describe("terminal title", () => {
147+ test("setTitle writes a terminal title OSC sequence with the requested text", () => {
148+ const term = setup();
149+
150+ cel.setTitle("cel-tui demo");
151+
152+ expect(extractTitlePayloads(term.output)).toEqual(["cel-tui demo"]);
153+ });
154+
155+ test("setTitle strips control characters from the title text", () => {
156+ const term = setup();
157+
158+ cel.setTitle("ab\x00c\nd\te\x1bf");
159+
160+ expect(extractTitlePayloads(term.output)).toEqual(["abcdef"]);
161+ });
162+
163+ test("setTitle can be called multiple times and writes each title update", () => {
164+ const term = setup();
165+
166+ cel.setTitle("first");
167+ cel.setTitle("second");
168+
169+ expect(extractTitlePayloads(term.output)).toEqual(["first", "second"]);
170+ });
171+
172+ test("stop does not emit a title restore sequence", () => {
173+ const term = setup();
174+ cel.setTitle("session");
175+ term.clearOutput();
176+
177+ cel.stop();
178+
179+ expect(extractTitlePayloads(term.output)).toEqual([]);
180+ });
181+ });
182+
141183 describe("input handling", () => {
142184 test("onClick fires on mouse click", async () => {
143185 const term = setup(20, 5);