Skip to content

feat: implement keyboard input function #22

@mjm918

Description

@mjm918

Summary

Add keyboard input capability to naml runtime to enable interactive programs.

Proposed API

// Blocking read - waits for user input
fn read_line() -> string;

// Non-blocking key read (for games) - returns key code or -1 if no key pressed
fn read_key() -> int;

Use Cases

  • Interactive CLI applications
  • Games (snake, tetris, etc.)
  • User prompts and menus

Implementation Notes

  • read_line() - blocking, reads until newline
  • read_key() - non-blocking, requires terminal raw mode
  • Platform considerations:
    • Native: use std::io::stdin() with raw mode via termios
    • Server WASM: WASI stdin
    • Browser: Not applicable (use DOM events instead)

Acceptance Criteria

  • read_line() reads a line of text from stdin
  • read_key() returns key code without blocking
  • Arrow keys return distinct codes
  • Works on native platform

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