Skip to content

feat: implement terminal control functions #25

@mjm918

Description

@mjm918

Summary

Add terminal control functions to naml runtime for building TUI applications and games.

Proposed API

// Clear the terminal screen
fn clear_screen();

// Move cursor to position (0-indexed)
fn set_cursor(x: int, y: int);

// Hide/show cursor
fn hide_cursor();
fn show_cursor();

// Get terminal dimensions
fn terminal_width() -> int;
fn terminal_height() -> int;

Use Cases

  • Terminal games (snake, tetris, roguelikes)
  • TUI applications
  • Progress bars and animations
  • Dashboard displays

Implementation Notes

  • Use ANSI escape sequences for cross-platform compatibility
  • Platform considerations:
    • Native: Write ANSI sequences to stdout, use ioctl for dimensions
    • Server WASM: Same ANSI sequences via WASI stdout
    • Browser: Not applicable

ANSI Reference

  • Clear screen: \x1b[2J
  • Move cursor: \x1b[{row};{col}H
  • Hide cursor: \x1b[?25l
  • Show cursor: \x1b[?25h

Acceptance Criteria

  • clear_screen() clears terminal content
  • set_cursor(x, y) positions cursor correctly
  • hide_cursor() / show_cursor() work
  • terminal_width() / terminal_height() return correct dimensions
  • Works on native platform with standard terminals

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions