CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
console.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include <cx/cx.h>
7#include <cx/meta/block.h>
8#include <cx/string/strbase.h>
9#include <cx/stype/stvar.h>
11
12CX_C_BEGIN
13
17
20typedef struct ConStream ConStream;
21
29
32typedef struct ConCaps {
33 bool istty;
34 bool vt;
35 bool unicode;
36 bool cursor;
37 bool altscreen;
40 uint16 width;
41 uint16 height;
43
50_Ret_valid_ ConStream* conOut(void);
51
58_Ret_valid_ ConStream* conErr(void);
59
62_Ret_valid_ ConStream* conIn(void);
63
67void conShutdown(void);
68
91_Ret_valid_ ConStream* conCreateMem(_In_ const ConCaps* caps);
92
97void conMemGet(_In_ ConStream* con, _Inout_ string* out);
98
102void conDestroy(_Pre_valid_ _Post_invalid_ ConStream** con);
103
108void conGetCaps(_In_ ConStream* con, _Out_ ConCaps* out);
109
111uint16 conWidth(_In_ ConStream* con);
112
114uint16 conHeight(_In_ ConStream* con);
115
124void conLock(_In_ ConStream* con);
125
129void conUnlock(_In_ ConStream* con);
130
145#define withConLock(con) blkWrap (conLock(con), conUnlock(con))
146
148
152
159bool conWrite(_In_ ConStream* con, _In_reads_bytes_(sz) const void* buf, size_t sz);
160
166bool conPuts(_In_ ConStream* con, _In_opt_ strref s);
167
172bool conPutsz(_In_ ConStream* con, _In_opt_z_ const char* sz);
173
179bool conPutc(_In_ ConStream* con, int32 codepoint);
180
186bool conNL(_In_ ConStream* con);
187
191bool conFlush(_In_ ConStream* con);
192
208bool _conFmt(_In_ ConStream* con, _In_ strref fmt, int n, _In_ stvar* args);
209#define conFmt(con, fmt, ...) \
210 _conFmt(con, fmt, count_macro_args(__VA_ARGS__), (stvar[]) { __VA_ARGS__ })
211
213
214CX_C_END
Macro argument counting utilities.
Block wrapping macros for automatic resource management.
void conMemGet(ConStream *con, string *out)
ConStream * conCreateMem(const ConCaps *caps)
struct ConStream ConStream
Definition console.h:20
ConStream * conErr(void)
void conShutdown(void)
ConColorDepth
Color depth a stream is able to render.
Definition console.h:23
void conGetCaps(ConStream *con, ConCaps *out)
void conDestroy(ConStream **con)
void conLock(ConStream *con)
uint16 conHeight(ConStream *con)
Current terminal height in rows, re-queried on every call. 0 if unknown or not a tty.
uint16 conWidth(ConStream *con)
Current terminal width in columns, re-queried on every call. 0 if unknown or not a tty.
ConStream * conOut(void)
ConStream * conIn(void)
void conUnlock(ConStream *con)
@ CON_ColorTrue
24-bit RGB
Definition console.h:27
@ CON_Color16
Standard + bright ANSI 16-color palette.
Definition console.h:25
@ CON_Color256
256-color palette (6x6x6 cube + grayscale ramp + 16 base)
Definition console.h:26
@ CON_ColorNone
No color support; styling is a no-op.
Definition console.h:24
bool conFlush(ConStream *con)
bool conNL(ConStream *con)
bool conPutc(ConStream *con, int32 codepoint)
bool conPuts(ConStream *con, strref s)
bool conPutsz(ConStream *con, const char *sz)
bool _conFmt(ConStream *con, strref fmt, int n, stvar *args)
bool conWrite(ConStream *con, const void *buf, size_t sz)
#define stvar(typen, val)
Definition stvar.h:162
Core string types and fundamental operations.
bool altscreen
The alternate screen buffer is available.
Definition console.h:37
bool cursorquery
conGetCursor() can report the real cursor position
Definition console.h:38
ConColorDepth color
Highest color depth the stream will render.
Definition console.h:39
uint16 height
Terminal height in rows, 0 if unknown.
Definition console.h:41
bool istty
The underlying handle is an interactive terminal.
Definition console.h:33
bool vt
VT/ANSI escape sequences are accepted on output.
Definition console.h:34
uint16 width
Terminal width in columns, 0 if unknown.
Definition console.h:40
bool unicode
Non-ASCII UTF-8 output is safe to write directly.
Definition console.h:35
bool cursor
Cursor addressing (conSetCursor and friends) is available.
Definition console.h:36
Variant type containers and type-safe variadic argument support.