Skip to content

Commit 9ded66c

Browse files
committed
fix const ordering
1 parent a56b7b1 commit 9ded66c

2 files changed

Lines changed: 77 additions & 55 deletions

File tree

examples/inline-regions/index.ts

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,23 @@ import {
3131
import { cursor, settings } from "../../settings.ts";
3232
import { validated } from "../../validate.ts";
3333

34+
const encode = (s: string) => new TextEncoder().encode(s);
35+
const write = (b: Uint8Array) => process.stdout.write(Buffer.from(b));
36+
37+
const GREEN = rgba(80, 250, 123);
38+
const GRAY = rgba(100, 100, 100);
39+
const CYAN = rgba(139, 233, 253);
40+
41+
const RED = rgba(255, 0, 0);
42+
const ORANGE = rgba(255, 153, 0);
43+
const YELLOW = rgba(255, 255, 0);
44+
const NGREEN = rgba(51, 255, 0);
45+
const BLUE = rgba(0, 153, 255);
46+
const VIOLET = rgba(102, 0, 255);
47+
const RAINBOW = [RED, ORANGE, YELLOW, NGREEN, BLUE, VIOLET];
48+
49+
const BRAILLE = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
50+
3451
await main(function* () {
3552
let { columns } = terminalSize();
3653
setRawMode(true);
@@ -246,30 +263,25 @@ function setRawMode(enabled: boolean): void {
246263
}
247264
}
248265

249-
const encode = (s: string) => new TextEncoder().encode(s);
250-
const write = (b: Uint8Array) => process.stdout.write(Buffer.from(b));
251-
252-
const GREEN = rgba(80, 250, 123);
253-
const GRAY = rgba(100, 100, 100);
254-
const CYAN = rgba(139, 233, 253);
255-
256-
const RED = rgba(255, 0, 0);
257-
const ORANGE = rgba(255, 153, 0);
258-
const YELLOW = rgba(255, 255, 0);
259-
const NGREEN = rgba(51, 255, 0);
260-
const BLUE = rgba(0, 153, 255);
261-
const VIOLET = rgba(102, 0, 255);
262-
const RAINBOW = [RED, ORANGE, YELLOW, NGREEN, BLUE, VIOLET];
263-
264-
const BRAILLE = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
265-
266266
function* queryCursor(): Operation<CursorEvent> {
267267
let parser = yield* until(createInput({ escLatency: 100 }));
268268
write(DSR());
269269

270270
let buf = Buffer.allocUnsafe(32);
271271
while (true) {
272-
let n = readSync(process.stdin.fd, buf, 0, buf.length, null);
272+
let n: number;
273+
try {
274+
n = readSync(process.stdin.fd, buf, 0, buf.length, null);
275+
} catch (error) {
276+
if (
277+
error && typeof error === "object" &&
278+
("code" in error && (error.code === "EAGAIN" || error.code === "EINTR"))
279+
) {
280+
continue;
281+
}
282+
throw error;
283+
}
284+
273285
if (n === 0) continue;
274286
let result = parser.scan(buf.subarray(0, n));
275287
for (let ev of result.events) {
@@ -283,7 +295,19 @@ function* queryCursor(): Operation<CursorEvent> {
283295
function waitKey(): void {
284296
let buf = Buffer.allocUnsafe(32);
285297
while (true) {
286-
let n = readSync(process.stdin.fd, buf, 0, buf.length, null);
298+
let n: number;
299+
try {
300+
n = readSync(process.stdin.fd, buf, 0, buf.length, null);
301+
} catch (error) {
302+
if (
303+
error && typeof error === "object" &&
304+
("code" in error && (error.code === "EAGAIN" || error.code === "EINTR"))
305+
) {
306+
continue;
307+
}
308+
throw error;
309+
}
310+
287311
if (n === 0) continue;
288312
for (let i = 0; i < n; i++) {
289313
if (buf[i] === 0x03) {

examples/keyboard/index.ts

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ import {
3535
import { useInput } from "./use-input.ts";
3636
import { useStdin } from "./use-stdin.ts";
3737

38+
const active = rgba(60, 120, 220);
39+
const inactive = rgba(50, 50, 60);
40+
const on = rgba(40, 180, 80);
41+
const label = rgba(220, 220, 220);
42+
const dim = rgba(100, 100, 120);
43+
const highlight = rgba(255, 220, 80);
44+
45+
const KEY_W = 5;
46+
const GAP = 1;
47+
const hovered = rgba(80, 80, 100);
48+
49+
const flagNames:
50+
(keyof Omit<AppContext, "mode" | "event" | "logged" | "log" | "entered">)[] = [
51+
"Disambiguate escape codes",
52+
"Report event types",
53+
"Report alternate keys",
54+
"Report all keys as escapes",
55+
"Report associated text",
56+
];
57+
58+
const logEntries: { key: string; name: keyof EventFilter }[] = [
59+
{ key: "a", name: "keydown" },
60+
{ key: "b", name: "keyup" },
61+
{ key: "c", name: "keyrepeat" },
62+
{ key: "d", name: "mousedown" },
63+
{ key: "e", name: "mouseup" },
64+
{ key: "f", name: "mousemove" },
65+
{ key: "g", name: "wheel" },
66+
{ key: "h", name: "resize" },
67+
{ key: "i", name: "pointerenter" },
68+
{ key: "j", name: "pointerleave" },
69+
{ key: "k", name: "pointerclick" },
70+
];
71+
3872
await main(function* () {
3973
let { columns, rows } = terminalSize();
4074

@@ -164,16 +198,6 @@ function updateFlagsIfChanged(current: Setting, next: Setting): Setting {
164198
return next;
165199
}
166200

167-
const active = rgba(60, 120, 220);
168-
const inactive = rgba(50, 50, 60);
169-
const on = rgba(40, 180, 80);
170-
const label = rgba(220, 220, 220);
171-
const dim = rgba(100, 100, 120);
172-
const highlight = rgba(255, 220, 80);
173-
174-
const KEY_W = 5;
175-
const GAP = 1;
176-
177201
interface KeyDef {
178202
label: string;
179203
code: string;
@@ -189,8 +213,6 @@ function matches(k: KeyDef, event: InputEvent | PointerEvent): boolean {
189213
event.code.toUpperCase() === k.code.toUpperCase();
190214
}
191215

192-
const hovered = rgba(80, 80, 100);
193-
194216
function key(ops: Op[], k: KeyDef, ctx: AppContext): void {
195217
let pressed = ctx.event && matches(k, ctx.event);
196218
let hover = ctx.entered.has(`key:${k.code}`);
@@ -459,30 +481,6 @@ function toggle(ops: Op[], enabled: boolean, name: string): void {
459481
);
460482
}
461483

462-
const flagNames:
463-
(keyof Omit<AppContext, "mode" | "event" | "logged" | "log" | "entered">)[] =
464-
[
465-
"Disambiguate escape codes",
466-
"Report event types",
467-
"Report alternate keys",
468-
"Report all keys as escapes",
469-
"Report associated text",
470-
];
471-
472-
const logEntries: { key: string; name: keyof EventFilter }[] = [
473-
{ key: "a", name: "keydown" },
474-
{ key: "b", name: "keyup" },
475-
{ key: "c", name: "keyrepeat" },
476-
{ key: "d", name: "mousedown" },
477-
{ key: "e", name: "mouseup" },
478-
{ key: "f", name: "mousemove" },
479-
{ key: "g", name: "wheel" },
480-
{ key: "h", name: "resize" },
481-
{ key: "i", name: "pointerenter" },
482-
{ key: "j", name: "pointerleave" },
483-
{ key: "k", name: "pointerclick" },
484-
];
485-
486484
function logToggle(
487485
ops: Op[],
488486
entries: typeof logEntries,

0 commit comments

Comments
 (0)