From 7927e392483cf80924483a92f7f7fef9cec6956d Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 6 Sep 2026 20:46:44 +1200 Subject: [PATCH 1/2] Manual: recommend -fexec-charset=cp437, add CP437 and colour references From the follow-up on #411. The Character Encoding section offered two routes for a UTF-8 source file (decode as UTF-8, or CP437 with hex escapes); the better third route is CP437 in NinjaTerm with readable glyph literals in the source and GCC's -fexec-charset=cp437, which keeps one byte per glyph in flash and on the wire. It is now listed first, with where to set it in STM32CubeIDE. New CP437 Box-Drawing Reference: the 40 box-drawing bytes grouped by line style, plus blocks and shades, each with decimal and hex. A note explains why 18 of them come out as accented letters when typed with Windows Alt codes on a CP850 (European) install. The SGR section gains a colour table and an example; bold brightening the foreground is now stated (.f31.b shares its colour with .f91). Also fixes the Terminal Font table, which the padding tip had split in two, stranding the System monospace and Custom rows below it. --- docs/docs/manual.mdx | 85 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 7 deletions(-) diff --git a/docs/docs/manual.mdx b/docs/docs/manual.mdx index e866887e..44088f6b 100644 --- a/docs/docs/manual.mdx +++ b/docs/docs/manual.mdx @@ -209,11 +209,22 @@ The current rows in view are ignored when performing Erase in Display commands, Sets the text style for subsequent characters. Multiple codes can be combined, separated by `;` (e.g. `ESC[1;31m` for bold red). The supported codes are: - `0` — reset all styles (also the default when no code is given, i.e. `ESC[m`) -- `1` — bold / increased intensity +- `1` — bold / increased intensity (also brightens the foreground color) - `30`–`37` — foreground color, `90`–`97` — bright foreground color - `40`–`47` — background color, `100`–`107` — bright background color -These can override the default background/TX/RX colors set in `Settings > Display`. +| Color | Foreground | Bright foreground | Background | Bright background | +| --- | --- | --- | --- | --- | +| Black | 30 | 90 | 40 | 100 | +| Red | 31 | 91 | 41 | 101 | +| Green | 32 | 92 | 42 | 102 | +| Yellow | 33 | 93 | 43 | 103 | +| Blue | 34 | 94 | 44 | 104 | +| Magenta | 35 | 95 | 45 | 105 | +| Cyan | 36 | 96 | 46 | 106 | +| White | 37 | 97 | 47 | 107 | + +For example `ESC[31;44m` is red on blue, and `ESC[91;44;1m` is bright red on blue, bold. These can override the default background/TX/RX colors set in `Settings > Display`. ## Timestamps @@ -292,14 +303,74 @@ All three agree on the bytes below `0x80` — control characters below `0x20`, p CP437 is the one to pick for DOS-style text-mode output, where a single byte is a single box-drawing character — e.g. byte `0xDA` is `┌` and `0xC4` is `─`. Devices that send UTF-8 (three bytes per box-drawing character) want the UTF-8 option instead. -Which to use is really a question about your firmware's source file, not your device. If your toolchain saves source as UTF-8 (STM32CubeIDE does, for example) you have two options: +Which to use is really a question about your firmware's source file, not your device. If your toolchain saves source as UTF-8 (STM32CubeIDE does, for example) you have three options: -- Pick **UTF-8** in NinjaTerm and write the box-drawing characters directly in your source: `printf("┌───┐")`. The compiler encodes them as UTF-8 and NinjaTerm decodes them back. -- Pick **CP437** and emit the raw bytes with hex escapes: `printf("\xDA\xC4\xC4\xC4\xBF")`. More faithful to a real DOS device, but harder to read in the source. +- **Recommended:** pick **CP437** in NinjaTerm, write the box-drawing characters directly in your source (`printf("┌───┐")`), and tell the compiler to emit them as CP437. With GCC, add `-fexec-charset=cp437` to the compiler flags (in STM32CubeIDE: Project Properties → C/C++ Build → Settings → MCU GCC Compiler → Miscellaneous). The source stays readable and each box-drawing character is one byte in flash and on the wire. +- Pick **UTF-8** in NinjaTerm and write the characters directly in your source, with no compiler flag. The compiler encodes them as UTF-8 and NinjaTerm decodes them back — but each box-drawing character costs three bytes. +- Pick **CP437** and emit the raw bytes with hex escapes: `printf("\xDA\xC4\xC4\xC4\xBF")`. One byte per character with no compiler flag, but harder to read in the source. The byte values are in the reference below. This setting decides how bytes are *decoded*; the Terminal Font setting below decides whether the resulting characters have glyphs to draw with. You need both for text-mode frames to display. +### CP437 Box-Drawing Reference + +The 40 box-drawing characters in CP437, as the byte your device sends. Decimal is what a Windows Alt code uses; the hex form is what you write in a C string. + +**Single line** + +| Glyph | Decimal | Hex | Glyph | Decimal | Hex | +| :---: | --- | --- | :---: | --- | --- | +| ┌ | 218 | `\xDA` | ┐ | 191 | `\xBF` | +| └ | 192 | `\xC0` | ┘ | 217 | `\xD9` | +| ─ | 196 | `\xC4` | │ | 179 | `\xB3` | +| ├ | 195 | `\xC3` | ┤ | 180 | `\xB4` | +| ┬ | 194 | `\xC2` | ┴ | 193 | `\xC1` | +| ┼ | 197 | `\xC5` | | | | + +**Double line** + +| Glyph | Decimal | Hex | Glyph | Decimal | Hex | +| :---: | --- | --- | :---: | --- | --- | +| ╔ | 201 | `\xC9` | ╗ | 187 | `\xBB` | +| ╚ | 200 | `\xC8` | ╝ | 188 | `\xBC` | +| ═ | 205 | `\xCD` | ║ | 186 | `\xBA` | +| ╠ | 204 | `\xCC` | ╣ | 185 | `\xB9` | +| ╦ | 203 | `\xCB` | ╩ | 202 | `\xCA` | +| ╬ | 206 | `\xCE` | | | | + +**Mixed: single vertical, double horizontal** + +| Glyph | Decimal | Hex | Glyph | Decimal | Hex | +| :---: | --- | --- | :---: | --- | --- | +| ╒ | 213 | `\xD5` | ╕ | 184 | `\xB8` | +| ╘ | 212 | `\xD4` | ╛ | 190 | `\xBE` | +| ╞ | 198 | `\xC6` | ╡ | 181 | `\xB5` | +| ╤ | 209 | `\xD1` | ╧ | 207 | `\xCF` | +| ╪ | 216 | `\xD8` | | | | + +**Mixed: double vertical, single horizontal** + +| Glyph | Decimal | Hex | Glyph | Decimal | Hex | +| :---: | --- | --- | :---: | --- | --- | +| ╓ | 214 | `\xD6` | ╖ | 183 | `\xB7` | +| ╙ | 211 | `\xD3` | ╜ | 189 | `\xBD` | +| ╟ | 199 | `\xC7` | ╢ | 182 | `\xB6` | +| ╥ | 210 | `\xD2` | ╨ | 208 | `\xD0` | +| ╫ | 215 | `\xD7` | | | | + +**Blocks and shades** + +| Glyph | Decimal | Hex | Glyph | Decimal | Hex | +| :---: | --- | --- | :---: | --- | --- | +| ░ | 176 | `\xB0` | ▒ | 177 | `\xB1` | +| ▓ | 178 | `\xB2` | █ | 219 | `\xDB` | +| ▄ | 220 | `\xDC` | ▀ | 223 | `\xDF` | +| ▌ | 221 | `\xDD` | ▐ | 222 | `\xDE` | + +:::note +Typing these on Windows with Alt + decimal on the numpad goes through Windows' *OEM* code page, which is CP437 only on a US install. Many European installs use CP850, where the 18 mixed single/double characters (181–184, 189, 190, 198, 199 and 207–216) are replaced by accented letters, so those Alt codes type the wrong character. Use the hex escapes instead, or copy the glyphs from the tables above. +::: + ### Terminal Font The font used to display data in the terminal can be changed in `Settings > Display`: @@ -309,12 +380,12 @@ The font used to display data in the terminal can be changed in `Settings > Disp | NinjaTerm (default) | NinjaTerm's own font. Covers ASCII only. | | IBM VGA (DOS/CP437) | The bundled IBM VGA 8x16 DOS text-mode font. Covers the CP437 box-drawing and block characters, so text-mode frames and borders drawn with `─│┌┐└┘├┤` render properly. | | Perfect DOS VGA 437 | The bundled Perfect DOS VGA 437 font, another DOS text-mode font that also covers the CP437 box-drawing characters. | +| System monospace | Whatever monospace font your operating system provides (Consolas, Menlo, DejaVu Sans Mono, ...). | +| Custom... | Any monospace font already installed on your computer, named in the "Custom Font Family" box that appears — e.g. `Perfect DOS VGA 437`. | :::tip Both DOS fonts are bitmap fonts whose glyphs fill their cell exactly, so set **Vertical Row Padding** to `0` when you use one. Any padding leaves a gap between rows, and the vertical strokes of a box-drawing frame stop joining up. The "DOS text-mode (CP437)" preset does this for you. NinjaTerm's own font has built-in spacing and looks better with a few pixels of padding. ::: -| System monospace | Whatever monospace font your operating system provides (Consolas, Menlo, DejaVu Sans Mono, ...). | -| Custom... | Any monospace font already installed on your computer, named in the "Custom Font Family" box that appears — e.g. `Perfect DOS VGA 437`. | Characters missing from the selected font fall back to a system monospace font, so the terminal's character grid always stays aligned. Combined with the cursor positioning escape codes above, this is what makes full-screen text-mode user interfaces display correctly. From bfbcb201c6ab489ae5c6c9a113a266682eccfcff Mon Sep 17 00:00:00 2001 From: Geoffrey Hunter Date: Sun, 6 Sep 2026 21:22:23 +1200 Subject: [PATCH 2/2] Manual: wording tweaks to the character encoding section --- docs/docs/manual.mdx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/docs/docs/manual.mdx b/docs/docs/manual.mdx index 44088f6b..bdd60620 100644 --- a/docs/docs/manual.mdx +++ b/docs/docs/manual.mdx @@ -291,11 +291,11 @@ Tailor your terminal's appearance by setting default colors for the background, ### Character Encoding -The character encoding of received data — how the incoming bytes are turned into the characters you see — is set in `Settings > RX Settings`: +The character encoding of received data (how the incoming bytes are turned into the characters you see) is set in `Settings > RX Settings`: | Option | Description | | --- | --- | -| ASCII only (default) | 7-bit ASCII. Bytes `0x80`+ aren't text, so they're shown as hex glyphs (or swallowed) per the non-visible character setting. Best for general debugging, where the raw byte value is what matters. | +| ASCII only (default) | 7-bit ASCII. Bytes `0x80`+ aren't text, so they're shown as hex glyphs (or swallowed) per the non-visible character setting. Best for simple use cases and general purpose debugging. | | UTF-8 | Decode bytes `0x80`+ as UTF-8. Characters split across separate reads from the port are handled. Bytes that aren't valid UTF-8 fall back to hex glyphs so they stay visible. | | CP437 (DOS) | Decode bytes `0x80`+ as code page 437, the original IBM PC / MS-DOS character set. | @@ -303,13 +303,12 @@ All three agree on the bytes below `0x80` — control characters below `0x20`, p CP437 is the one to pick for DOS-style text-mode output, where a single byte is a single box-drawing character — e.g. byte `0xDA` is `┌` and `0xC4` is `─`. Devices that send UTF-8 (three bytes per box-drawing character) want the UTF-8 option instead. -Which to use is really a question about your firmware's source file, not your device. If your toolchain saves source as UTF-8 (STM32CubeIDE does, for example) you have three options: +Which to use depends on your firmware source code and build settings. If your toolchain saves source as UTF-8 (STM32CubeIDE does, for example) you have three options: - **Recommended:** pick **CP437** in NinjaTerm, write the box-drawing characters directly in your source (`printf("┌───┐")`), and tell the compiler to emit them as CP437. With GCC, add `-fexec-charset=cp437` to the compiler flags (in STM32CubeIDE: Project Properties → C/C++ Build → Settings → MCU GCC Compiler → Miscellaneous). The source stays readable and each box-drawing character is one byte in flash and on the wire. -- Pick **UTF-8** in NinjaTerm and write the characters directly in your source, with no compiler flag. The compiler encodes them as UTF-8 and NinjaTerm decodes them back — but each box-drawing character costs three bytes. +- Pick **UTF-8** in NinjaTerm and write the characters directly in your source, with no compiler flag. The compiler encodes them as UTF-8 and NinjaTerm decodes them back. Just be aware that each box-drawing character costs three bytes. - Pick **CP437** and emit the raw bytes with hex escapes: `printf("\xDA\xC4\xC4\xC4\xBF")`. One byte per character with no compiler flag, but harder to read in the source. The byte values are in the reference below. - This setting decides how bytes are *decoded*; the Terminal Font setting below decides whether the resulting characters have glyphs to draw with. You need both for text-mode frames to display. ### CP437 Box-Drawing Reference