Terminal raw mode and window size for IO.FS.Handle / stdin

Aperta
#16,868 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
38/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Ambito
backend

Direzione di ricerca

Start by reading the existing IO.FS.Handle terminal API, the libuv bindings, and the issue’s references to uv_tty_set_mode, uv_tty_reset_mode, and uv_tty_get_winsize. The proposal identifies the desired operations and return type, but leaves API placement and platform behavior open. Done means Lean can set and reset terminal mode and read window dimensions without spawning shell commands.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

Lean can tell whether a handle is a terminal (Handle.isTty), but cannot change the terminal's mode or read its size. Terminal UIs written in Lean (lean-tea's TUI, and the TUI and attach command of Aether, github.com/Verilean/aether) spawn a shell for each change:

IO.Process.output { cmd := "sh", args := #["-c", "stty raw -echo min 0 time 1 < /dev/tty"] }
IO.Process.output { cmd := "sh", args := #["-c", "stty size < /dev/tty"] }

This costs a process per call, needs /bin/sh and stty on PATH, and cannot restore the mode if the program is killed between the two calls. They also use min 0 time 1 to get a read timeout on stdin, because a read on stdin cannot otherwise be bounded.

libuv already has the primitives: uv_tty_set_mode (UV_TTY_MODE_NORMAL, _RAW, _IO), uv_tty_reset_mode (async-signal-safe, for restoring at exit) and uv_tty_get_winsize. Std.Async.Signal.sigwinch already exists for resize notifications.

Proposal:

namespace IO.FS.Handle   -- or on the tty `Handle` of RFC #13638
inductive TtyMode | normal | raw | io
opaque setTtyMode (h : @& Handle) (mode : TtyMode) : IO Unit
opaque ttySize (h : @& Handle) : IO (UInt16 × UInt16)   -- (rows, columns)
end IO.FS.Handle
opaque IO.resetTtyMode : IO Unit                         -- uv_tty_reset_mode

A second, larger request, for a separate discussion if preferred: spawning a child on a pseudo-terminal (openpty + posix_spawn, or forkpty), returning the master side as a handle with resize. Running interactive programs (shells, REPLs, coding agents) under a Lean program requires this in C today. libuv has no PTY support, so this would be Lean's own code (POSIX, or ConPTY on Windows).

Steps to Reproduce

There is no API to call. The cost of the workaround on Linux, 50 calls each: sh -c true 5.8 ms, sh -c 'stty size < /dev/tty' 6.6 ms per call.

Expected behavior: raw mode, reset and window size without spawning processes.

Actual behavior: isTty only.

Versions

Lean 4.36.0 (x86_64-unknown-linux-gnu), checked against v4.37.0-rc1.

Impact

Add 👍 to issues you consider important. If others benefit from the changes in this issue, please add 👍 to it.

Lingua principale
Lean
Stelle
10.3k
Fork
1.1k
Merge medio
16h 45m
PR unite (30g)
361

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di leanprover/lean4

Tutte le issue di leanprover/lean4

Issue simili

Altre issue su Backend & API Design

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.