Skip to content

Platform-native console abstraction for event-driven input #77

@Aaronontheweb

Description

@Aaronontheweb

Summary

Replace the polling-based input system with a proper platform abstraction layer that provides event-driven console I/O. This addresses Windows compatibility issues and eliminates the 10ms input latency caused by the current polling architecture.

Problem

The current ConsoleInputSource uses a 10ms polling loop with Console.KeyAvailable + Console.ReadKey. This is an architectural flaw that causes:

  1. Input latency - Minimum 10ms delay before input is processed
  2. CPU usage - Constant polling even when idle
  3. Windows issues - No explicit VT100 enablement, causing rendering problems in some terminals (Cmder/ConEmu)
  4. No resize signals - Terminal resize is also polled instead of signal-based (Unix)

Solution

Create an IPlatformConsole interface with platform-specific implementations:

  • WindowsConsole - P/Invoke for SetConsoleMode (VT100), ReadConsoleInputW (event-driven)
  • UnixConsole - termios raw mode, select()/poll() on stdin, SIGWINCH signal handler
  • FallbackConsole - Current polling logic for unsupported platforms

Child Issues

Acceptance Criteria

  • No polling-based input on Windows and Unix
  • VT100 processing explicitly enabled on Windows
  • Ctrl+Q works to quit applications regardless of focused component
  • Terminal resize detected via signals on Unix
  • Input latency reduced to near-zero
  • Existing tests pass
  • Works on Windows Terminal, Cmder (best effort), Linux terminals, macOS Terminal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions