Skip to content

Commit a3d119e

Browse files
committed
fullscreen wrap not required
1 parent 4286643 commit a3d119e

6 files changed

Lines changed: 52 additions & 156 deletions

File tree

demo/keyboard-node.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,31 +31,19 @@ type NodeScanResult = {
3131
pending?: { delay: number };
3232
};
3333

34-
let demo = createKeyboardDemo({
35-
close,
36-
fixed,
37-
grow,
38-
mouseTracking,
39-
open,
40-
progressiveInput,
41-
rgba,
42-
settings,
43-
text,
44-
} as Parameters<typeof createKeyboardDemo>[0]);
45-
46-
let diagnostics = {
47-
disableWindowsFullscreenHandling: process.argv.includes(
48-
"--no-windows-fullscreen-fix",
49-
),
50-
};
51-
52-
(globalThis as typeof globalThis & {
53-
__claytermDiagnostics__?: {
54-
disableWindowsFullscreenHandling?: boolean;
55-
};
56-
}).__claytermDiagnostics__ = {
57-
disableWindowsFullscreenHandling: diagnostics.disableWindowsFullscreenHandling,
58-
};
34+
let demo = createKeyboardDemo(
35+
{
36+
close,
37+
fixed,
38+
grow,
39+
mouseTracking,
40+
open,
41+
progressiveInput,
42+
rgba,
43+
settings,
44+
text,
45+
} as Parameters<typeof createKeyboardDemo>[0],
46+
);
5947

6048
let term: Awaited<ReturnType<typeof createTerm>> | null = null;
6149
let input: NodeInput | null = null;
@@ -251,4 +239,4 @@ try {
251239
cleanup();
252240
console.error(error);
253241
process.exit(1);
254-
}
242+
}

demo/keyboard-shared.ts

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// deno-lint-ignore-file no-fallthrough
12
import type { InputEvent, KeyEvent, Op, PointerEvent } from "../mod.ts";
23
import type { SizingAxis } from "../ops.ts";
34
import type { Setting } from "../settings.ts";
@@ -442,7 +443,9 @@ export function createKeyboardDemo(api: KeyboardDemoApi) {
442443
let mouseLabel = context["Capture mouse events"] ? "capture" : "system";
443444

444445
ops.push(
445-
open("badges", { layout: { direction: "ttb", gap: 1, padding: { top: 1 } } }),
446+
open("badges", {
447+
layout: { direction: "ttb", gap: 1, padding: { top: 1 } },
448+
}),
446449
open("badge:mode", {
447450
layout: { direction: "ltr", height: fixed(1), padding: { bottom: 1 } },
448451
}),
@@ -472,7 +475,9 @@ export function createKeyboardDemo(api: KeyboardDemoApi) {
472475
close(),
473476
);
474477

475-
ops.push(open("", { layout: { width: grow(), direction: "ltr", alignX: 1 } }));
478+
ops.push(
479+
open("", { layout: { width: grow(), direction: "ltr", alignX: 1 } }),
480+
);
476481
configPanel(ops, context);
477482
ops.push(close());
478483
ops.push(close());
@@ -495,11 +500,16 @@ export function createKeyboardDemo(api: KeyboardDemoApi) {
495500
ops.push(close());
496501
ops.push(close());
497502

498-
ops.push(open("event-log", { layout: { height: fixed(1), padding: { top: 1 } } }));
499503
ops.push(
500-
text(context.logged ? JSON.stringify(context.logged) : "Press any key...", {
501-
color: highlight,
502-
}),
504+
open("event-log", { layout: { height: fixed(1), padding: { top: 1 } } }),
505+
);
506+
ops.push(
507+
text(
508+
context.logged ? JSON.stringify(context.logged) : "Press any key...",
509+
{
510+
color: highlight,
511+
},
512+
),
503513
);
504514
ops.push(close());
505515
ops.push(close());
@@ -550,7 +560,11 @@ export function createKeyboardDemo(api: KeyboardDemoApi) {
550560
};
551561
}
552562

553-
function* recognizer(): Iterator<AppContext, never, InputEvent | PointerEvent> {
563+
function* recognizer(): Iterator<
564+
AppContext,
565+
never,
566+
InputEvent | PointerEvent
567+
> {
554568
let current = createInitialContext();
555569
let event = yield current;
556570
let mode = inputmode({ ...current, event });
@@ -597,7 +611,9 @@ export function createKeyboardDemo(api: KeyboardDemoApi) {
597611
}
598612
if (event.type === "keydown") {
599613
let keyEvent = event as KeyEvent;
600-
let entry = logEntries.find((candidate) => candidate.key === keyEvent.key);
614+
let entry = logEntries.find((candidate) =>
615+
candidate.key === keyEvent.key
616+
);
601617
if (entry) {
602618
context = {
603619
...context,
@@ -637,4 +653,4 @@ export function createKeyboardDemo(api: KeyboardDemoApi) {
637653
recognizer,
638654
ttyFlags,
639655
};
640-
}
656+
}

demo/keyboard.ts

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,8 @@ import {
88
type Stream,
99
until,
1010
} from "effection";
11-
import {
12-
createTerm,
13-
type PointerEvent,
14-
} from "../mod.ts";
15-
import {
16-
alternateBuffer,
17-
settings,
18-
} from "../settings.ts";
11+
import { createTerm, type PointerEvent } from "../mod.ts";
12+
import { alternateBuffer, settings } from "../settings.ts";
1913
import { close, fixed, grow, open, rgba, text } from "../mod.ts";
2014
import { cursor, mouseTracking, progressiveInput } from "../settings.ts";
2115
import { createKeyboardDemo } from "./keyboard-shared.ts";
@@ -34,20 +28,6 @@ const demo = createKeyboardDemo({
3428
text,
3529
});
3630

37-
let diagnostics = {
38-
disableWindowsFullscreenHandling: Deno.args.includes(
39-
"--no-windows-fullscreen-fix",
40-
),
41-
};
42-
43-
(globalThis as typeof globalThis & {
44-
__claytermDiagnostics__?: {
45-
disableWindowsFullscreenHandling?: boolean;
46-
};
47-
}).__claytermDiagnostics__ = {
48-
disableWindowsFullscreenHandling: diagnostics.disableWindowsFullscreenHandling,
49-
};
50-
5131
function writeAllSync(output: Uint8Array): void {
5232
// Deno's stdout writes are not guaranteed to drain the full buffer in one
5333
// call, so always loop until the entire frame chunk is written.

deno.lock

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

term.ts

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -38,71 +38,6 @@ export interface ElementInfo {
3838
bounds: BoundingBox;
3939
}
4040

41-
const WINDOWS_WRAP_DISABLE = new Uint8Array([0x1b, 0x5b, 0x3f, 0x37, 0x6c]);
42-
const WINDOWS_WRAP_ENABLE = new Uint8Array([0x1b, 0x5b, 0x3f, 0x37, 0x68]);
43-
44-
function windowsFullscreenHandlingDisabled(): boolean {
45-
let diagnostics = (globalThis as typeof globalThis & {
46-
__claytermDiagnostics__?: {
47-
disableWindowsFullscreenHandling?: boolean;
48-
};
49-
}).__claytermDiagnostics__;
50-
51-
return diagnostics?.disableWindowsFullscreenHandling === true;
52-
}
53-
54-
function normalizeWindowsLineOutput(output: Uint8Array): Uint8Array {
55-
// Empirically, Deno-on-Windows fullscreen redraws were more reliable when
56-
// line-mode output began with a home cursor move and used CRLF row
57-
// separators. Bare LF left later rows visually clipped in the tested
58-
// terminal stack, while localized redraws could still reveal the content.
59-
let extra = 0;
60-
for (let i = 0; i < output.length; i++) {
61-
if (output[i] === 0x0a && (i === 0 || output[i - 1] !== 0x0d)) {
62-
extra++;
63-
}
64-
}
65-
66-
let prefix = new Uint8Array([
67-
...WINDOWS_WRAP_DISABLE,
68-
0x1b,
69-
0x5b,
70-
0x48,
71-
]);
72-
let suffix = WINDOWS_WRAP_ENABLE;
73-
let normalized = new Uint8Array(
74-
prefix.length + output.length + extra + suffix.length,
75-
);
76-
normalized.set(prefix, 0);
77-
78-
let offset = prefix.length;
79-
for (let i = 0; i < output.length; i++) {
80-
let byte = output[i];
81-
if (byte === 0x0a && (i === 0 || output[i - 1] !== 0x0d)) {
82-
normalized[offset++] = 0x0d;
83-
}
84-
normalized[offset++] = byte;
85-
}
86-
87-
normalized.set(suffix, offset);
88-
89-
return normalized as Uint8Array;
90-
}
91-
92-
function wrapWindowsFullscreenOutput(output: Uint8Array): Uint8Array {
93-
// Preserve an explicit wrap-state boundary around fullscreen frames on
94-
// Windows. In the tested Deno path this avoided redraw glitches at the right
95-
// edge even though the same scene rendered cleanly in Node.
96-
// xterm defines CSI ? 7 h / CSI ? 7 l as auto-wrap on/off.
97-
let wrapped = new Uint8Array(
98-
WINDOWS_WRAP_DISABLE.length + output.length + WINDOWS_WRAP_ENABLE.length,
99-
);
100-
wrapped.set(WINDOWS_WRAP_DISABLE, 0);
101-
wrapped.set(output, WINDOWS_WRAP_DISABLE.length);
102-
wrapped.set(WINDOWS_WRAP_ENABLE, WINDOWS_WRAP_DISABLE.length + output.length);
103-
return wrapped;
104-
}
105-
10641
const ERROR_TYPES = [
10742
"TEXT_MEASUREMENT_FUNCTION_NOT_PROVIDED",
10843
"ARENA_CAPACITY_EXCEEDED",
@@ -135,10 +70,6 @@ export interface Term {
13570
render(ops: Op[], options?: RenderOptions): RenderResult;
13671
}
13772

138-
let runtimeIsWindows = (globalThis as typeof globalThis & {
139-
Deno?: { build?: { os?: string } };
140-
}).Deno?.build?.os === "windows";
141-
14273
export async function createTerm(options: TermOptions): Promise<Term> {
14374
let { width, height } = options;
14475
let native = await createTermNative(width, height);
@@ -153,18 +84,6 @@ export async function createTerm(options: TermOptions): Promise<Term> {
15384
let len = pack(ops, memory.buffer, opsBuf, memory.buffer.byteLength);
15485
let mode = options?.mode === "line" ? 1 : 0;
15586
let row = options?.row ?? 1;
156-
let autoLineMode = false;
157-
let windowsFullscreen = row === 1 && runtimeIsWindows &&
158-
!windowsFullscreenHandlingDisabled();
159-
160-
// Use the line-oriented render path by default for Windows fullscreen
161-
// renders. This was required for Deno to avoid
162-
// clipped rows during fullscreen redraw, while the equivalent Node path
163-
// did not show the same failure.
164-
if (mode === 0 && options?.mode === undefined && windowsFullscreen) {
165-
mode = 1;
166-
autoLineMode = true;
167-
}
16887

16988
native.reduce(statePtr, opsBuf, len, mode, row);
17089

@@ -179,12 +98,6 @@ export async function createTerm(options: TermOptions): Promise<Term> {
17998
native.length(statePtr),
18099
);
181100

182-
if (autoLineMode) {
183-
output = normalizeWindowsLineOutput(output);
184-
} else if (windowsFullscreen) {
185-
output = wrapWindowsFullscreenOutput(output);
186-
}
187-
188101
let current = new Set(
189102
options?.pointer ? native.getPointerOverIds() : [],
190103
);

test/term.test.ts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,6 @@ describe("term", () => {
130130
│ │
131131
│ │
132132
└──────────────────┘`.trim());
133-
134-
if (Deno.build.os === "windows") {
135-
expect(out.startsWith("\x1b[?7l")).toBe(true);
136-
expect(out.endsWith("\x1b[?7h")).toBe(true);
137-
}
138133
});
139134

140135
it("primes front buffer for subsequent diff render", async () => {
@@ -152,13 +147,7 @@ describe("term", () => {
152147
│ │
153148
└──────────────────┘`.trim());
154149

155-
if (Deno.build.os === "windows") {
156-
expect(second.startsWith("\x1b[?7l\x1b[H")).toBe(true);
157-
expect(second).toContain("\r\n");
158-
expect(second.endsWith("\x1b[?7h")).toBe(true);
159-
} else {
160-
expect(second.length).toBeLessThan(first.length);
161-
}
150+
expect(second.length).toBeLessThan(first.length);
162151
});
163152
});
164153

0 commit comments

Comments
 (0)