opencode/packages/cli-rs/parity/sim/clock.ts
Simon Klee 6b1df0cceb
feat(cli-rs): add the native CLI and TUI (#63477)
Add packages/cli-rs, an OpenCode client written in Rust on OpenTUI's Rust crates. It is a client only.
2026-11-22 00:07:01 +01:00

14 lines
792 B
TypeScript

// P-TUI fixed clock, preloaded into the TS server and client of a scenario that sets `now`: with
// OPENCODE_DRIVE_NOW (milliseconds since the epoch), `Date` starts at that instant and runs on, so dates the screen
// shows do not follow the day of the run. The Rust client reads the same variable in `opencode_util::time::now_ms`.
const start = Number(process.env.OPENCODE_DRIVE_NOW)
if (start) {
const real = Date
const offset = start - real.now()
const now = () => real.now() + offset
globalThis.Date = new Proxy(real, {
construct: (target, args, newTarget) => Reflect.construct(target, args.length ? args : [now()], newTarget),
apply: () => new real(now()).toString(),
get: (target, key, receiver) => (key === "now" ? now : Reflect.get(target, key, receiver)),
})
}