The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import * as Clock from "effect/Clock"; |
| 2 | import * as Console from "effect/Console"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as LogLevel from "effect/LogLevel"; |
| 5 | import { prettyLine } from "../Util/ConsoleSink.ts"; |
| 6 | import { currentConsoleSettings } from "./GlobalLog.ts"; |
| 7 | |
| 8 | /** |
| 9 | * Print one line of plain renderer output: what the TUI would draw, for a |
| 10 | * terminal without it. Renderers present events, they don't log them — |
| 11 | * the events are already log records — so this writes to the console only, |
| 12 | * prints nothing under `--log-format json`, where the records are the |
| 13 | * output, and honors the console's `--log-level` floor like log lines do. |
| 14 | */ |
| 15 | export const present = ( |
| 16 | text: string, |
| 17 | options: { readonly resource?: string; readonly level?: LogLevel.Severity } = {}, |
| 18 | ): Effect.Effect<void> => |
| 19 | Effect.flatMap(currentConsoleSettings, ({ format, floor }) => |
| 20 | format === "json" || !LogLevel.isGreaterThanOrEqualTo(options.level ?? "Info", floor) |
| 21 | ? Effect.void |
| 22 | : Clock.currentTimeMillis.pipe( |
| 23 | Effect.flatMap((now) => |
| 24 | Console.log( |
| 25 | prettyLine({ |
| 26 | date: new Date(now), |
| 27 | level: options.level ?? "Info", |
| 28 | text, |
| 29 | resource: options.resource, |
| 30 | }), |
| 31 | ), |
| 32 | ), |
| 33 | ), |
| 34 | ); |