package miaou-core

  1. Overview
  2. Docs
Miaou core/widgets (no drivers, no SDL)

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.5.2.tar.gz
md5=60a3b9f181f24572a06a9492532bfdda
sha512=fcc35a275066be2900e6201782faf47503076fa4640f08cf78067835a6f447b74613009e55b2ac799adb7ca46f1bffa261fc5971753f2cc3c6bef327511c7ef6

doc/miaou-core.driver-common/Miaou_driver_common/Terminal_raw/index.html

Module Miaou_driver_common.Terminal_rawSource

Raw terminal operations shared between drivers.

Provides low-level terminal control: raw mode, mouse tracking, size detection, signal handling, and cleanup. Based on lambda-term driver's tested implementation.

Usage:

  let term = Terminal_raw.setup () in
  at_exit (fun () -> Terminal_raw.cleanup term);
  Terminal_raw.enter_raw term;
  Terminal_raw.enable_mouse term;
  (* ... main loop ... *)
  Terminal_raw.cleanup term
Sourcetype t

Terminal state handle.

Sourceval setup : unit -> t

Setup terminal for TUI use. Opens /dev/tty for reliable output.

  • raises Failure

    if stdin is not a terminal.

Get the input file descriptor (stdin).

Sourceval enter_raw : t -> unit

Enter raw mode: disable line buffering and echo.

Sourceval leave_raw : t -> unit

Leave raw mode: restore original terminal settings.

Sourceval enable_mouse : t -> unit

Enable SGR mouse tracking (1002h + 1006h). Writes to /dev/tty for consistency with other terminal operations.

Sourceval disable_mouse : t -> unit

Disable mouse tracking. Idempotent, safe to call multiple times. Uses multiple methods (tty, stdout, stderr) to ensure delivery.

Sourceval cleanup : t -> unit

Full cleanup: clear screen, show cursor, restore settings, disable mouse. Safe to call multiple times (idempotent for terminal restore).

Sourceval write : t -> string -> unit

Write string to terminal via /dev/tty with stdout fallback.

Sourceval size : t -> int * int

Detect terminal size. Uses cache; call invalidate_size_cache on resize. Falls back to environment variables or (24, 80) if detection fails.

  • returns

    (rows, cols)

Sourceval invalidate_size_cache : t -> unit

Invalidate the size cache. Call this on SIGWINCH.

Sourceval install_signals : t -> on_resize:(unit -> unit) -> on_exit:(unit -> unit) -> bool Atomic.t

Install signal handlers for resize and exit.

  • parameter on_resize

    Called on SIGWINCH (after cache invalidation)

  • parameter on_exit

    Called on SIGINT/SIGTERM/SIGHUP/SIGQUIT before exit

  • returns

    Atomic flag that becomes true when exit signal received

Sourceval install_signals' : t -> on_resize:(unit -> unit) -> on_exit:(unit -> unit) -> ?handle_sigint:bool -> unit -> bool Atomic.t

Like install_signals but with optional control over which signals are handled.

  • parameter handle_sigint

    If false, SIGINT (Ctrl+C) is not intercepted, allowing the app to receive it as a key event. Default: true

Sourceval resize_pending : t -> bool

Check if a resize signal was received since last clear.

Sourceval clear_resize_pending : t -> unit

Clear the resize pending flag.

Sourceval set_exit_screen_dump : t -> string -> unit

Set screen content to dump on exit for debugging. The content will be printed to stdout after exiting alternate screen mode, preserving the TUI output in terminal scrollback.

Sourceval set_alt_screen : t -> bool -> unit

Choose whether enter_raw switches to the alternate screen.

By default the terminal enters the alt-screen on enter_raw and leaves it on cleanup, restoring the prior shell content. Calling set_alt_screen t false before enter_raw switches to inline mode: the TUI renders directly over the current terminal contents and the final frame stays in the scrollback after the program exits. A trailing newline is appended on cleanup so the next shell prompt starts on a fresh line.

Inline mode trades the standard "take over the screen" experience for one where the rendered output is preserved as part of the user's terminal history — useful for short-running CLI helpers, debugging, and any tool you want to read after it exits.

Must be called before enter_raw to take effect.

Sourceval alt_screen_enabled : t -> bool

Whether the alternate screen is currently enabled (default true).