Skip to content

Implement fallback console (polling) for unsupported platforms #81

@Aaronontheweb

Description

@Aaronontheweb

Parent: #77

Summary

Implement FallbackConsole that wraps the existing polling-based logic for platforms where native P/Invoke isn't available.

Files to Create

  • src/Termina/Platform/FallbackConsole.cs

Implementation

Essentially wrap the current ConsoleInputSource logic:

public sealed class FallbackConsole : IPlatformConsole
{
    public async Task<ConsoleInputEvent?> ReadInputAsync(CancellationToken ct)
    {
        while (!ct.IsCancellationRequested)
        {
            if (Console.KeyAvailable)
            {
                var key = Console.ReadKey(intercept: true);
                return new KeyEvent(key);
            }
            
            // Check for resize
            var (w, h) = GetSize();
            if (w != _lastWidth || h != _lastHeight)
            {
                _lastWidth = w;
                _lastHeight = h;
                return new ResizeEvent(w, h);
            }
            
            await Task.Delay(1, ct);  // Reduced from 10ms
        }
        return null;
    }
}

Key Differences from Current

  1. Reduced polling delay (1ms instead of 10ms)
  2. Implements IPlatformConsole interface
  3. Returns ConsoleInputEvent records instead of writing to channel directly

Acceptance Criteria

  • Implements IPlatformConsole interface
  • Works on any .NET-supported platform
  • Reduced polling delay for lower latency
  • Resize detection via polling
  • Graceful cancellation

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