Parent: #77
Summary
Implement UnixConsole using termios for raw mode and POSIX signals for resize detection.
Files to Create
src/Termina/Platform/UnixConsole.cs
P/Invoke Requirements
termios
[DllImport("libc")]
static extern int tcgetattr(int fd, ref termios termios_p);
[DllImport("libc")]
static extern int tcsetattr(int fd, int optional_actions, ref termios termios_p);
Raw Mode Configuration
- Disable
ICANON (line buffering)
- Disable
ECHO (character echo)
- Disable
ISIG (signal generation for Ctrl+C)
- Set
VMIN=0, VTIME=0 for non-blocking reads
Input Polling
[DllImport("libc")]
static extern int poll(ref pollfd fds, uint nfds, int timeout);
Use poll() on stdin (fd 0) with timeout for cancellation support.
SIGWINCH Signal
[DllImport("libc")]
static extern int sigaction(int signum, ref sigaction act, ref sigaction oldact);
const int SIGWINCH = 28;
Register handler to emit resize events.
Key Behaviors
- Initialize(): Save current termios, enter raw mode
- ReadInputAsync(): Use
poll() with timeout, then read() stdin bytes, parse ANSI sequences
- Restore(): Reset termios to saved state
- Resized: Emit on SIGWINCH signal
ANSI Sequence Parsing
Need to parse escape sequences for special keys:
ESC[A = Up, ESC[B = Down, ESC[C = Right, ESC[D = Left
ESC[1;5A = Ctrl+Up (modifier codes)
- Function keys, Home, End, etc.
Acceptance Criteria
Parent: #77
Summary
Implement
UnixConsoleusing termios for raw mode and POSIX signals for resize detection.Files to Create
src/Termina/Platform/UnixConsole.csP/Invoke Requirements
termios
Raw Mode Configuration
ICANON(line buffering)ECHO(character echo)ISIG(signal generation for Ctrl+C)VMIN=0,VTIME=0for non-blocking readsInput Polling
Use
poll()on stdin (fd 0) with timeout for cancellation support.SIGWINCH Signal
Register handler to emit resize events.
Key Behaviors
poll()with timeout, thenread()stdin bytes, parse ANSI sequencesANSI Sequence Parsing
Need to parse escape sequences for special keys:
ESC[A= Up,ESC[B= Down,ESC[C= Right,ESC[D= LeftESC[1;5A= Ctrl+Up (modifier codes)Acceptance Criteria