log: allow locking the terminal #65

Open
opened 2026-01-10 17:36:43 -08:00 by clo · 0 comments
Owner

Lines 192 to 205 in 53be102
export interface HeadlessWidgetEnv {
/** Recieves ANSI escape sequences for interactive data. */
writeInteractive(text: string): void;
/** Recieves log content (from `writeLine`). */
writeOutput(text: string): void;
/** Monotonic. */
now(): ReturnType<typeof performance.now>;
/** 0ms indicates "one frame". */
wait(ms: number, cb: () => void): () => void;
/** Called often. */
getSize(): { columns: number; rows: number };
/** Called to enable input events */
onInput?(write: (bytes: Uint8Array | string) => void): () => void;
}

problem is for pichu's runtime, they state that it'll be like console.stream.out.getWriter(), but that means you need a lock on the standard io to implement this interface. but obviously, youre cooked if you just always hold a lock.

i propose changing this interface to

  getDrawLock(): Promise<{
    /** Recieves ANSI escape sequences for interactive data. */
    writeInteractive(text: string): void;
    /** Recieves log content (from `writeLine`). */
    writeOutput(text: string): void;
    /** Release the lock */
    releaseLock(): void;
  }>

the write lock is held whenever a widget is visible, but it can be freed by calling getDrawLock(). now we can also avoid injecting to console on Node.js unconditionally.

https://git.paperclover.net/clo/sitegen/src/commit/53be1026a725b3eda02dec2d85db6a46055126f2/lib/log.ts#L192-L205 problem is for pichu's runtime, they state that it'll be like `console.stream.out.getWriter()`, but that means you need a lock on the standard io to implement this interface. but obviously, youre cooked if you just always hold a lock. i propose changing this interface to ```ts getDrawLock(): Promise<{ /** Recieves ANSI escape sequences for interactive data. */ writeInteractive(text: string): void; /** Recieves log content (from `writeLine`). */ writeOutput(text: string): void; /** Release the lock */ releaseLock(): void; }> ``` the write lock is held whenever a widget is visible, but it can be freed by calling getDrawLock(). now we can also avoid injecting to console on Node.js unconditionally.
clo added this to the progress blog post milestone 2026-02-02 03:54:39 -08:00
Sign in to join this conversation.
No labels
bug
chore
feat
lib
site
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
clo/sitegen#65
No description provided.