|
CX Framework
Cross-platform C utility framework
|
Data Structures | |
| struct | ConStyle |
Macros | |
| #define | CON_ColorDefault 0u |
| #define | CON_Idx(n) (0x01000000u | (uint32)(uint8)(n)) |
| #define | CON_RGB(r, g, b) (0x02000000u | ((uint32)(uint8)(r) << 16) | ((uint32)(uint8)(g) << 8) | (uint32)(uint8)(b)) |
| #define | CONSTYLE(fg, attr) ((ConStyle) { (fg), CON_ColorDefault, (attr) }) |
| #define | CONSTYLE2(fg, bg, attr) ((ConStyle) { (fg), (bg), (attr) }) |
Typedefs | |
| typedef struct ConStyle | ConStyle |
Enumerations | |
| enum | CON_ATTR_FLAGS |
Functions | |
| void | conSetStyle (ConStream *con, ConStyle style) |
| void | conResetStyle (ConStream *con) |
| void | conGetStyle (ConStream *con, ConStyle *out) |
| bool | conWriteS (ConStream *con, ConStyle style, const void *buf, size_t sz) |
| bool | conPutsS (ConStream *con, ConStyle style, strref s) |
| bool | conPutszS (ConStream *con, ConStyle style, const char *sz) |
| bool | conPutcS (ConStream *con, ConStyle style, int32 codepoint) |
| bool | _conFmtS (ConStream *con, ConStyle style, strref fmt, int n, stvar *args) |
| #define CON_ColorDefault 0u |
The stream's own default foreground/background color – i.e. no color escape is emitted for this half of a ConStyle.
Definition at line 16 of file constyle.h.
| #define CON_Idx | ( | n | ) | (0x01000000u | (uint32)(uint8)(n)) |
uint32 CON_Idx(uint8 n);
A palette color, 0-255. 0-15 are the standard + bright ANSI 16-color entries; 16-255 are the 256-color cube and grayscale ramp popularized by the xterm terminal emulator and now supported by most terminals. Always representable exactly on a CON_Color256 or CON_ColorTrue stream; downgraded to the nearest of the 16 base colors on a CON_Color16 stream.
Definition at line 25 of file constyle.h.
| #define CON_RGB | ( | r, | |
| g, | |||
| b | |||
| ) | (0x02000000u | ((uint32)(uint8)(r) << 16) | ((uint32)(uint8)(g) << 8) | (uint32)(uint8)(b)) |
uint32 CON_RGB(uint8 r, uint8 g, uint8 b);
A 24-bit RGB color. Downgraded to the nearest representable color on streams below CON_ColorTrue.
Definition at line 31 of file constyle.h.
| #define CONSTYLE | ( | fg, | |
| attr | |||
| ) | ((ConStyle) { (fg), CON_ColorDefault, (attr) }) |
ConStyle CONSTYLE(uint32 fg, flags_t attr);
Builds a ConStyle with a foreground color and attributes, default background.
Definition at line 77 of file constyle.h.
| #define CONSTYLE2 | ( | fg, | |
| bg, | |||
| attr | |||
| ) | ((ConStyle) { (fg), (bg), (attr) }) |
ConStyle CONSTYLE2(uint32 fg, uint32 bg, flags_t attr);
Builds a ConStyle with both a foreground and background color, plus attributes.
Definition at line 82 of file constyle.h.
A text style: foreground color, background color, and attribute flags. Passed by value – 12 bytes, no lifetime of its own.
| enum CON_ATTR_FLAGS |
Text attribute flags for ConStyle::attr. Attributes unsupported by a stream (e.g. italic on the Windows legacy console) are dropped silently rather than emitting garbage.
Definition at line 56 of file constyle.h.
bool conFmtS(ConStream *con, ConStyle style, strref fmt, ...);
Formats arguments with cx's type-safe formatter (see Formatting) and writes the result with a style applied for the duration of the write, then restores whatever style was active beforehand.
| con | Destination stream |
| style | Style to apply for this write |
| fmt | Format string |
Example:
| void conGetStyle | ( | ConStream * | con, |
| ConStyle * | out | ||
| ) |
Retrieves the style most recently passed to conSetStyle() or conResetStyle() – exactly as requested, not the capability-downgraded form actually emitted.
| con | Stream to query |
| out | Receives a copy of the current style |
| bool conPutcS | ( | ConStream * | con, |
| ConStyle | style, | ||
| int32 | codepoint | ||
| ) |
Writes a single Unicode code point with a style applied for the duration of the write, then restores whatever style was active beforehand.
| con | Destination stream |
| style | Style to apply for this write |
| codepoint | Unicode code point to write |
| bool conPutsS | ( | ConStream * | con, |
| ConStyle | style, | ||
| strref | s | ||
| ) |
Writes a cx string with a style applied for the duration of the write, then restores whatever style was active beforehand. Rope-shaped strings are walked chunk by chunk with no flattening allocation.
| con | Destination stream |
| style | Style to apply for this write |
| s | String to write (NULL or empty writes nothing and returns true) |
| bool conPutszS | ( | ConStream * | con, |
| ConStyle | style, | ||
| const char * | sz | ||
| ) |
Writes a NUL-terminated C string with a style applied for the duration of the write, then restores whatever style was active beforehand.
| con | Destination stream |
| style | Style to apply for this write |
| sz | String to write (NULL or empty writes nothing and returns true) |
| void conResetStyle | ( | ConStream * | con | ) |
Restores a stream to its default (unstyled) appearance. Equivalent to conSetStyle(con, CONSTYLE(CON_ColorDefault, 0)).
| con | Stream to reset |
| void conSetStyle | ( | ConStream * | con, |
| ConStyle | style | ||
| ) |
Sets the stream's current style, downgrading colors and dropping unsupported attributes according to the stream's capabilities. Stays in effect for subsequent unstyled writes until the next conSetStyle()/conResetStyle() call.
| con | Stream to style |
| style | Style to apply |
| bool conWriteS | ( | ConStream * | con, |
| ConStyle | style, | ||
| const void * | buf, | ||
| size_t | sz | ||
| ) |
Writes raw bytes with a style applied for the duration of the write, then restores whatever style was active beforehand. Atomic with respect to other threads.
| con | Destination stream |
| style | Style to apply for this write |
| buf | Bytes to write |
| sz | Number of bytes |