|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | ConCaps |
Macros | |
| #define | withConLock(con) blkWrap (conLock(con), conUnlock(con)) |
Typedefs | |
| typedef struct ConStream | ConStream |
| typedef enum ConColorDepth | ConColorDepth |
| Color depth a stream is able to render. | |
| typedef struct ConCaps | ConCaps |
Enumerations | |
| enum | ConColorDepth { CON_ColorNone = 0 , CON_Color16 , CON_Color256 , CON_ColorTrue } |
| Color depth a stream is able to render. More... | |
Functions | |
| ConStream * | conOut (void) |
| ConStream * | conErr (void) |
| ConStream * | conIn (void) |
| void | conShutdown (void) |
| ConStream * | conCreateMem (const ConCaps *caps) |
| void | conMemGet (ConStream *con, string *out) |
| void | conDestroy (ConStream **con) |
| void | conGetCaps (ConStream *con, ConCaps *out) |
| uint16 | conWidth (ConStream *con) |
| Current terminal width in columns, re-queried on every call. 0 if unknown or not a tty. | |
| uint16 | conHeight (ConStream *con) |
| Current terminal height in rows, re-queried on every call. 0 if unknown or not a tty. | |
| void | conLock (ConStream *con) |
| void | conUnlock (ConStream *con) |
void withConLock(ConStream *con) { ... }
Executes a block with the stream locked for its duration, unlocking automatically on every exit path (including early return or break).
Example:
| con | Stream to lock for the duration of the block |
Capabilities of a console stream, detected once at stream initialization from environment variables and a platform probe (never from a terminfo/termcap database).
| typedef struct ConStream ConStream |
| enum ConColorDepth |
| ConStream * conCreateMem | ( | const ConCaps * | caps | ) |
ConStream* conCreateMem(const ConCaps *caps)
Creates a memory-backed console stream for testing.
Writes are captured into an internal string instead of reaching any real terminal, and nothing this module does ever logs, so it is safe to use inside log-destination tests as well. Behaves exactly like a real stream to every other function in this module.
| caps | Capabilities to report for this stream (copied) |
Example:
| void conDestroy | ( | ConStream ** | con | ) |
Destroys a memory-backed stream created with conCreateMem(). Never call this on conOut()/conErr()/conIn() – they are process singletons and are never destroyed.
| con | Pointer to the stream handle; set to NULL on return |
| ConStream * conErr | ( | void | ) |
Returns the process-wide standard error stream, creating it on first call.
Always unbuffered – every write reaches the underlying stream immediately, so crash-adjacent diagnostics are never lost in a buffer.
| void conGetCaps | ( | ConStream * | con, |
| ConCaps * | out | ||
| ) |
Retrieves the current capabilities of a stream. Terminal size is re-queried; everything else was detected once at stream initialization.
| con | Stream to query |
| out | Receives a copy of the stream's capabilities |
| ConStream * conIn | ( | void | ) |
Returns the process-wide standard input stream, creating it on first call.
| void conLock | ( | ConStream * | con | ) |
Locks a stream for the calling thread.
Every public function in this module already locks internally, so explicit locking is only needed to group several calls into one sequence atomic with respect to other threads. Reentrant from the owning thread via an internal depth counter – nested conLock()/conUnlock() pairs on the same thread are supported and cheap – but never share a lock across threads without a matching unlock.
| con | Stream to lock |
| void conMemGet | ( | ConStream * | con, |
| string * | out | ||
| ) |
Copies everything written to a memory-backed stream so far into *out, replacing any value already there. Does not clear the stream's internal capture buffer.
| con | A stream created with conCreateMem() |
| out | Receives a copy of the captured output |
| ConStream * conOut | ( | void | ) |
Returns the process-wide standard output stream, creating it on first call.
The returned pointer is a permanent singleton; it is never destroyed and must not be passed to conDestroy(). Safe to call from any thread at any time.
| void conShutdown | ( | void | ) |
Restores terminal state changed by this module and flushes all singleton streams that have been created. Safe to call more than once. Does not free the singletons; they remain usable afterward.