|
| 1 | ++++ |
| 2 | +title = "Configuration" |
| 3 | +description = "Compile-time #defines and the bundled ANSI macros" |
| 4 | +weight = 60 |
| 5 | ++++ |
| 6 | + |
| 7 | +All tuning is performed via compile-time `#define`s; no runtime configuration is provided. A default can be overridden by defining the corresponding macro before including the header, or by passing `-D...` to the compiler. |
| 8 | + |
| 9 | +## Line Buffer and Tokens |
| 10 | + |
| 11 | +| Macro | Default | Effect | |
| 12 | +|------------------------|---------|--------| |
| 13 | +| `TCLI_CMDLINE_MAX_LEN` | `64` | Maximum number of characters that fit on the command line (excluding the null terminator). The full buffer is embedded in `tcli_t`, so this value directly affects the struct size. | |
| 14 | +| `TCLI_MAX_TOKENS` | `12` | Maximum number of whitespace-separated tokens produced by the tokenizer. Lines with more tokens are rejected before the executor is invoked. | |
| 15 | + |
| 16 | +## History |
| 17 | + |
| 18 | +| Macro | Default | Effect | |
| 19 | +|-----------------------|---------|--------| |
| 20 | +| `TCLI_HISTORY_BUF_LEN`| `512` | Size of the ring buffer that stores history lines. Setting it to `0` compiles history out entirely: no {{ kbd(key="Up") }}/{{ kbd(key="Down") }}, no {{ kbd(key="Ctrl+r") }}, smaller `tcli_t`. | |
| 21 | + |
| 22 | +## Output Buffering |
| 23 | + |
| 24 | +| Macro | Default | Effect | |
| 25 | +|-----------------------|---------|--------| |
| 26 | +| `TCLI_OUTPUT_BUF_LEN` | `256` | Size of the buffer used to coalesce `tcli_out` writes before they reach the output callback. Setting it to `0` disables buffering; every byte is forwarded to the callback immediately. | |
| 27 | + |
| 28 | +## Tab-Completion |
| 29 | + |
| 30 | +| Macro | Default | Effect | |
| 31 | +|-----------------|---------|--------| |
| 32 | +| `TCLI_COMPLETE` | `1` | Setting to `0` compiles out tab-completion entirely (smaller binary, `tcli_compl_fn_t` removed). | |
| 33 | + |
| 34 | +## Default Prompts |
| 35 | + |
| 36 | +Each prompt is a string. The defaults wrap the visible text in ANSI color escapes; the same form can be used in custom prompts to retain coloring. |
| 37 | + |
| 38 | +| Macro | Default | Rendered | |
| 39 | +|---|---|---| |
| 40 | +| `TCLI_DEFAULT_PROMPT` | `(TCLI_COLOR_GREEN "> " TCLI_COLOR_DEFAULT)` | <code style="background:#000000;color:#00bb00">> </code> | |
| 41 | +| `TCLI_DEFAULT_ERROR_PROMPT` | `(TCLI_COLOR_RED "> " TCLI_COLOR_DEFAULT)` | <code style="background:#000000;color:#bb0000">> </code> | |
| 42 | +| `TCLI_DEFAULT_SEARCH_PROMPT` | `(TCLI_COLOR_GREEN "? " TCLI_COLOR_DEFAULT)` | <code style="background:#000000;color:#00bb00">? </code> | |
| 43 | + |
| 44 | +These are the starting values. The prompts can also be overridden at runtime via [`tcli_set_prompt`](@/tcli.md#prompts) and the corresponding setters. |
| 45 | + |
| 46 | +## `tclie`-Specific |
| 47 | + |
| 48 | +| Macro | Default | Effect | |
| 49 | +|--------------------------------|---------|--------| |
| 50 | +| `TCLIE_ENABLE_USERS` | `1` | Compiles in users and login. Set to `0` for command-only CLIs. | |
| 51 | +| `TCLIE_ENABLE_USERNAMES` | `1` | Enables usernames in addition to passwords. Set to `0` for password-only login (matched against any user). | |
| 52 | +| `TCLIE_LOGIN_ATTEMPTS` | `3` | Number of incorrect password attempts before the login is rejected. | |
| 53 | +| `TCLIE_PATTERN_MATCH` | `1` | Compiles in [pattern matching](@/pattern-matching.md). Set to `0` to reduce footprint when not used. | |
| 54 | +| `TCLIE_PATTERN_MATCH_MAX_TOKENS` | `TCLI_MAX_TOKENS` | Maximum number of tokens considered during pattern matching. More tokens require a deeper stack depth. | |
| 55 | +| `TCLIE_PATTERN_MATCH_BUF_LEN` | `64` | Scratch buffer used for pattern-derived tab-completion candidates. | |
| 56 | + |
| 57 | +## ANSI Color and Format Macros |
| 58 | + |
| 59 | +A set of ANSI escape constants is provided for use in prompts and command output. They are referenced by name; the samples below show how each renders in a terminal. |
| 60 | + |
| 61 | +### Foreground Colors |
| 62 | + |
| 63 | +| Macro | Sample | |
| 64 | +|---|---| |
| 65 | +| `TCLI_COLOR_BLACK` | <code style="background:#000000;color:#000000">Sample</code> | |
| 66 | +| `TCLI_COLOR_RED` | <code style="background:#000000;color:#bb0000">Sample</code> | |
| 67 | +| `TCLI_COLOR_GREEN` | <code style="background:#000000;color:#00bb00">Sample</code> | |
| 68 | +| `TCLI_COLOR_YELLOW` | <code style="background:#000000;color:#bbbb00">Sample</code> | |
| 69 | +| `TCLI_COLOR_BLUE` | <code style="background:#000000;color:#0000bb">Sample</code> | |
| 70 | +| `TCLI_COLOR_MAGENTA` | <code style="background:#000000;color:#bb00bb">Sample</code> | |
| 71 | +| `TCLI_COLOR_CYAN` | <code style="background:#000000;color:#00bbbb">Sample</code> | |
| 72 | +| `TCLI_COLOR_WHITE` | <code style="background:#000000;color:#bbbbbb">Sample</code> | |
| 73 | +| `TCLI_COLOR_BRIGHT_BLACK` | <code style="background:#000000;color:#555555">Sample</code> | |
| 74 | +| `TCLI_COLOR_BRIGHT_RED` | <code style="background:#000000;color:#ff5555">Sample</code> | |
| 75 | +| `TCLI_COLOR_BRIGHT_GREEN` | <code style="background:#000000;color:#55ff55">Sample</code> | |
| 76 | +| `TCLI_COLOR_BRIGHT_YELLOW` | <code style="background:#000000;color:#ffff55">Sample</code> | |
| 77 | +| `TCLI_COLOR_BRIGHT_BLUE` | <code style="background:#000000;color:#5555ff">Sample</code> | |
| 78 | +| `TCLI_COLOR_BRIGHT_MAGENTA` | <code style="background:#000000;color:#ff55ff">Sample</code> | |
| 79 | +| `TCLI_COLOR_BRIGHT_CYAN` | <code style="background:#000000;color:#55ffff">Sample</code> | |
| 80 | +| `TCLI_COLOR_BRIGHT_WHITE` | <code style="background:#000000;color:#ffffff">Sample</code> | |
| 81 | +| `TCLI_COLOR_DEFAULT` | Restores the terminal's default foreground color. | |
| 82 | + |
| 83 | +### Background Colors |
| 84 | + |
| 85 | +| Macro | Sample | |
| 86 | +|---|---| |
| 87 | +| `TCLI_BG_COLOR_BLACK` | <code style="background:#000000;color:#bbbbbb">Sample</code> | |
| 88 | +| `TCLI_BG_COLOR_RED` | <code style="background:#bb0000;color:#ffffff">Sample</code> | |
| 89 | +| `TCLI_BG_COLOR_GREEN` | <code style="background:#00bb00;color:#ffffff">Sample</code> | |
| 90 | +| `TCLI_BG_COLOR_YELLOW` | <code style="background:#bbbb00;color:#000000">Sample</code> | |
| 91 | +| `TCLI_BG_COLOR_BLUE` | <code style="background:#0000bb;color:#ffffff">Sample</code> | |
| 92 | +| `TCLI_BG_COLOR_MAGENTA` | <code style="background:#bb00bb;color:#ffffff">Sample</code> | |
| 93 | +| `TCLI_BG_COLOR_CYAN` | <code style="background:#00bbbb;color:#000000">Sample</code> | |
| 94 | +| `TCLI_BG_COLOR_WHITE` | <code style="background:#bbbbbb;color:#000000">Sample</code> | |
| 95 | +| `TCLI_BG_COLOR_DEFAULT` | Restores the terminal's default background color. | |
| 96 | + |
| 97 | +### Text Formatting |
| 98 | + |
| 99 | +| Macro | Sample | |
| 100 | +|---|---| |
| 101 | +| `TCLI_FORMAT_BOLD` | <code style="background:#000000;color:#bbbbbb;font-weight:700">Sample</code> | |
| 102 | +| `TCLI_FORMAT_DIM` | <code style="background:#000000;color:#bbbbbb;opacity:0.55">Sample</code> | |
| 103 | +| `TCLI_FORMAT_ITALIC` | <code style="background:#000000;color:#bbbbbb;font-style:italic">Sample</code> | |
| 104 | +| `TCLI_FORMAT_UNDERLINE` | <code style="background:#000000;color:#bbbbbb;text-decoration:underline">Sample</code> | |
| 105 | +| `TCLI_FORMAT_RESET` | Clears all color and formatting. | |
| 106 | + |
| 107 | +### Combinations |
| 108 | + |
| 109 | +Format and color macros concatenate; any number can be combined. |
| 110 | + |
| 111 | +| Macros | Sample | |
| 112 | +|---|---| |
| 113 | +| `TCLI_FORMAT_BOLD TCLI_COLOR_RED` | <code style="background:#000000;color:#bb0000;font-weight:700">Sample</code> | |
| 114 | +| `TCLI_FORMAT_BOLD TCLI_FORMAT_UNDERLINE TCLI_COLOR_CYAN` | <code style="background:#000000;color:#00bbbb;font-weight:700;text-decoration:underline">Sample</code> | |
| 115 | +| `TCLI_FORMAT_ITALIC TCLI_COLOR_GREEN` | <code style="background:#000000;color:#00bb00;font-style:italic">Sample</code> | |
| 116 | +| `TCLI_FORMAT_DIM TCLI_COLOR_YELLOW` | <code style="background:#000000;color:#bbbb00;opacity:0.55">Sample</code> | |
| 117 | +| `TCLI_BG_COLOR_BLUE TCLI_COLOR_BRIGHT_WHITE` | <code style="background:#0000bb;color:#ffffff">Sample</code> | |
| 118 | +| `TCLI_FORMAT_BOLD TCLI_BG_COLOR_WHITE TCLI_COLOR_RED` | <code style="background:#bbbbbb;color:#bb0000;font-weight:700">Sample</code> | |
| 119 | + |
| 120 | +The constants concatenate at compile time and can be composed directly into a single string literal: |
| 121 | + |
| 122 | +```c |
| 123 | +#define TCLI_DEFAULT_PROMPT \ |
| 124 | + (TCLI_FORMAT_BOLD TCLI_COLOR_CYAN "device> " TCLI_FORMAT_RESET) |
| 125 | +``` |
| 126 | +
|
| 127 | +The format macros used by `tclie` and the `help` command are also overridable: |
| 128 | +
|
| 129 | +| Macro | Default | Rendered | |
| 130 | +|---|---|---| |
| 131 | +| `TCLIE_SUCCESS_FORMAT` | `TCLI_COLOR_GREEN` | <code style="background:#000000;color:#00bb00">Sample</code> | |
| 132 | +| `TCLIE_FAILURE_FORMAT` | `TCLI_COLOR_RED` | <code style="background:#000000;color:#bb0000">Sample</code> | |
| 133 | +| `TCLIE_COMMAND_FORMAT` | `(TCLI_FORMAT_BOLD TCLI_FORMAT_UNDERLINE TCLI_COLOR_CYAN)` | <code style="background:#000000;color:#00bbbb;font-weight:700;text-decoration:underline">Sample</code> | |
| 134 | +| `TCLIE_USAGE_FORMAT` | `TCLI_COLOR_CYAN` | <code style="background:#000000;color:#00bbbb">Sample</code> | |
| 135 | +| `TCLIE_OPTION_FORMAT` | `(TCLI_FORMAT_ITALIC TCLI_COLOR_CYAN)` | <code style="background:#000000;color:#00bbbb;font-style:italic">Sample</code> | |
| 136 | +
|
| 137 | +Setting any of these to an empty string removes the corresponding color or formatting from the help output, e.g. for log capture or terminals that do not render escape sequences. |
| 138 | +
|
| 139 | +The tab-completion display has two further format macros: |
| 140 | +
|
| 141 | +| Macro | Default | Rendered | Effect | |
| 142 | +|---|---|---|---| |
| 143 | +| `TCLI_MATCH_FORMAT` | `TCLI_COLOR_BRIGHT_BLACK` | <code style="background:#000000;color:#555555">Sample</code> | Format of the common-prefix match hint shown while completing. | |
| 144 | +| `TCLI_SELECTION_FORMAT` | `(TCLI_BG_COLOR_WHITE TCLI_COLOR_BLACK)` | <code style="background:#bbbbbb;color:#000000">Sample</code> | Format of the currently-selected candidate when cycling through matches. | |
| 145 | +
|
| 146 | +## Version |
| 147 | +
|
| 148 | +The library version is available at compile time through macros defined in `tcli.h`: `TCLI_VERSION_MAJOR`, `TCLI_VERSION_MINOR`, `TCLI_VERSION_PATCH`, and `TCLI_VERSION_STR`. |
0 commit comments