|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | ConKeyEvent |
| A single decoded key press. More... | |
Typedefs | |
| typedef enum ConKey | ConKey |
| Logical key identity, independent of the byte/escape sequence a terminal happened to send. | |
| typedef struct ConKeyEvent | ConKeyEvent |
| A single decoded key press. | |
| typedef enum ConInputMode | ConInputMode |
| Input mode for a stream. See conSetMode(). | |
Enumerations | |
| enum | ConKey { CON_Key_None = 0 , CON_Key_Char , CON_Key_Enter , CON_Key_Tab , CON_Key_Backspace , CON_Key_Escape , CON_Key_Up , CON_Key_Down , CON_Key_Left , CON_Key_Right , CON_Key_Home , CON_Key_End , CON_Key_PageUp , CON_Key_PageDown , CON_Key_Insert , CON_Key_Delete , CON_Key_F1 , CON_Key_F2 , CON_Key_F3 , CON_Key_F4 , CON_Key_F5 , CON_Key_F6 , CON_Key_F7 , CON_Key_F8 , CON_Key_F9 , CON_Key_F10 , CON_Key_F11 , CON_Key_F12 , CON_Key_Resize } |
| Logical key identity, independent of the byte/escape sequence a terminal happened to send. More... | |
| enum | CON_MOD_FLAGS |
| Modifier flags for ConKeyEvent::mods. | |
| enum | ConInputMode { CON_Cooked , CON_Raw } |
| Input mode for a stream. See conSetMode(). More... | |
Functions | |
| bool | conSetMode (ConStream *con, ConInputMode mode) |
| bool | conSetEcho (ConStream *con, bool echo) |
| bool | conInWait (ConStream *con, int64 timeout) |
| bool | conReadKey (ConStream *con, ConKeyEvent *out, int64 timeout) |
| bool | conReadLine (ConStream *con, string *out) |
| bool | conReadPassword (ConStream *con, string *out) |
| enum ConInputMode |
Input mode for a stream. See conSetMode().
| Enumerator | |
|---|---|
| CON_Cooked | Line-buffered, terminal-echoed, signal-generating – the default. |
| CON_Raw | Keystrokes available immediately, one at a time. |
| enum ConKey |
Logical key identity, independent of the byte/escape sequence a terminal happened to send.
| Enumerator | |
|---|---|
| CON_Key_None | No key (conReadKey() failed/timed out); never appears in a successful ConKeyEvent |
| CON_Key_Char | A printable/control character; the codepoint is in ConKeyEvent::ch. |
| CON_Key_Resize | Synthetic: the terminal size changed (Windows only – see conReadKey()) |
| bool conInWait | ( | ConStream * | con, |
| int64 | timeout | ||
| ) |
Waits for input to become available without consuming it.
| con | Stream to poll (only conIn() is meaningful) |
| timeout | Maximum time to wait (microseconds; timeForever to block indefinitely) |
| bool conReadKey | ( | ConStream * | con, |
| ConKeyEvent * | out, | ||
| int64 | timeout | ||
| ) |
Reads and decodes a single key press.
On Windows, a console resize while waiting is reported as CON_Key_Resize (query the new size with conWidth()/conHeight()) rather than being silently swallowed; unix/wasm never produce it – poll conWidth()/conHeight() there instead (see ConCaps for why this module does not install a SIGWINCH handler).
| con | Stream to read from (only conIn() is meaningful) |
| out | Receives the decoded key |
| timeout | Maximum time to wait (microseconds; timeForever to block indefinitely) |
| bool conReadLine | ( | ConStream * | con, |
| string * | out | ||
| ) |
Reads a line of input with basic editing (Backspace), echoing each character typed.
When con is a real interactive terminal, switches it to CON_Raw for the duration of the call and restores CON_Cooked before returning, success or not. When con is redirected (ConCaps::istty is false – a pipe or a file), there is no terminal to put in raw mode and nothing to echo, so this instead reads plain bytes up to the next '
' (tolerating a preceding '\r'), same as a stdio fgets() – no editing, no echo, and indistinguishable from conReadPassword() in that case.
| con | Stream to read from (only conIn() is meaningful) |
| out | Receives the line, replacing any previous value. Never includes the terminating ' ' (or the interactive form's Enter). |
| bool conReadPassword | ( | ConStream * | con, |
| string * | out | ||
| ) |
Like conReadLine(), but never echoes typed characters – for password entry.
Same redirected-input fallback as conReadLine(): when con is not a real terminal, there is no terminal echo to suppress, so this just reads a plain line like conReadLine() would.
| con | Stream to read from (only conIn() is meaningful) |
| out | Receives the line, replacing any previous value |
| bool conSetEcho | ( | ConStream * | con, |
| bool | echo | ||
| ) |
Enables or disables the terminal's own echoing of typed characters.
Independent of conSetMode() – conReadLine()/conReadPassword() manage this themselves. Only meaningful on conIn(); requires a real interactive terminal.
| con | Stream to configure (only conIn() is meaningful) |
| echo | true to echo typed characters, false to suppress |
| bool conSetMode | ( | ConStream * | con, |
| ConInputMode | mode | ||
| ) |
Switches a stream between cooked and raw input mode.
CON_Raw disables canonical (line-buffered) input so conReadKey() sees each keystroke as soon as it arrives, and disables software flow control (Ctrl+S/Ctrl+Q) so those pass through as ordinary key events instead of freezing output. It does not touch signal generation: Ctrl+C/Ctrl+Z/Ctrl+\ still raise SIGINT/SIGTSTP/SIGQUIT as usual, the same way this module never touches SIGWINCH, the Unix signal sent on a terminal resize (see ConCaps). A caller that wants Ctrl+C delivered as a keystroke instead of a signal must block or ignore the signal itself.
Only meaningful on conIn(); requires a real interactive terminal (ConCaps::istty). Automatically restored to cooked on conShutdown(), and on process crash where the crash handler (cx/debug/crash.h) is active, so an abnormal exit never leaves the shell in raw mode with echo off.
| con | Stream to switch (only conIn() is meaningful) |
| mode | CON_Cooked or CON_Raw |