Skip to content

feat: add optional CP437G code page for VGA text mode - #31

Closed
asmello wants to merge 3 commits into
bonega:masterfrom
asmello:feat/cp437g
Closed

feat: add optional CP437G code page for VGA text mode#31
asmello wants to merge 3 commits into
bonega:masterfrom
asmello:feat/cp437g

Conversation

@asmello

@asmello asmello commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Part 2 of 2 addressing #29 — the optional CP437G code page.

Stacked on #30 — please review that first. Cross-fork PRs can't target a fork branch, so the base here is master. Until #30 merges, this diff also contains #30's commit; the CP437G-only changes are the final commit (feat: add optional CP437G code page for VGA text mode). Once #30 lands, this diff reduces to just CP437G automatically.

What this does

Adds CP437G behind an off-by-default cp437g cargo feature. It's CP437 overlaid with the IBM-Graphics glyphs at the C0 control byte range (0x010x1F and 0x7F), per unicode.org's IBMGRAPH.TXT — i.e. what the VGA BIOS glyph ROM actually renders for those bytes (☺ ♥ ♪ → ⌂ …). Pairs naturally with the encode_char/decode_byte primitives from #30 for driving a text buffer from a no_std kernel.

[dependencies]
yore = { version = "1.5.0", features = ["cp437g"] }
use yore::code_pages::CP437G;

assert_eq!(CP437G.encode_char('☺'), Some(0x01));
assert_eq!(CP437G.decode_byte(0x01), '☺');

Notes

  • Generated like every other code page: the mapping is built in codegen by overlaying the glyphs onto CP437, and the cp437g module is #[cfg(feature = "cp437g")]-gated. Off by default, so no impact on existing builds.
  • Some glyphs share a byte with an ASCII control character (0x09 ○, 0x0A ◙, 0x0D ♪). yore's ASCII fast-path still encodes '\t'/'\n'/'\r' to those bytes, so a caller that needs newline semantics should intercept the source char first. This is covered by tests and documented in the README.

Testing

  • cargo test --all-features (unit + doctests, incl. CP437G round-trip and ASCII fast-path): pass
  • cargo clippy -- -D warnings across the default, all-features, and reduced (--no-default-features [--features alloc|cp437g] --lib) sets: clean
  • cargo build --no-default-features --features cp437g --lib --target thumbv7em-none-eabi
  • cd codegen && cargo run produces no diff

Adds a third feature tier so the crate scales down to no_std targets without
an allocator. The existing no_std (alloc) tier from bonega#28 is preserved.

- Cargo.toml: add an `alloc` feature gating the Cow-returning encode/decode
  API; `std` now implies `alloc`, so the default build is unchanged.
- New allocation-free per-codepage primitives, available without `alloc`:
  - `encode_char(c: char) -> Option<u8>`
  - `decode_byte(b: u8) -> char` (complete) / `Option<char>` (incomplete)
- gate the Cow API, decode helpers, and table-write paths behind `alloc`
  across lib.rs, encoder/decoder, and the codegen templates (regenerated
  code_pages match).
- CI: the bare-metal job now also builds the no_std + alloc tier; the
  no-features build doubles as the no-allocator guard.
- docs: document the three tiers; bump version to 1.5.0.

BREAKING for no_std users of 1.4.0: `default-features = false` now selects the
no-allocator tier. Add `features = ["alloc"]` to keep the full API.
asmello added 2 commits June 14, 2026 14:44
Per maintainer review on bonega#30: the new no-allocator default-features tier is
a breaking change for default-features = false users, so bump the major
version. The default build is unaffected.
Adds CP437G behind an off-by-default `cp437g` feature, per the request in bonega#29.
It is CP437 overlaid with the IBM-Graphics glyphs at the C0 control byte range
(per unicode.org's IBMGRAPH.TXT), matching what the VGA BIOS glyph ROM renders
for bytes 0x01-0x1F and 0x7F. Pairs with `encode_char`/`decode_byte` for
driving a text buffer from a no_std kernel.

- codegen: build the CP437G mapping by overlaying the glyphs onto CP437
- code_pages: gate the generated `cp437g` module behind the feature
- tests: feature-gated round-trip and ASCII fast-path coverage
- CI: exercise the feature via --all-features and a bare-metal build
- docs: README section + CHANGELOG entry

Glyphs that share a byte with an ASCII control (0x09 ○, 0x0A ◙, 0x0D ♪) are
representable; the ASCII fast-path still encodes '\t'/'\n'/'\r' to those bytes,
so callers intercept the source char if they need newline semantics.
bonega added a commit that referenced this pull request Jun 16, 2026
* feat: add optional CP437G code page for VGA text mode

Adds CP437G behind an off-by-default `cp437g` feature, per the request in #29.
It is CP437 overlaid with the IBM-Graphics glyphs at the C0 control byte range
(per unicode.org's IBMGRAPH.TXT), matching what the VGA BIOS glyph ROM renders
for bytes 0x01-0x1F and 0x7F. Pairs with `encode_char`/`decode_byte` for
driving a text buffer from a no_std kernel.

- codegen: build the CP437G mapping by overlaying the glyphs onto CP437
- code_pages: gate the generated `cp437g` module behind the feature
- tests: feature-gated round-trip and ASCII fast-path coverage
- CI: exercise the feature via --all-features and a bare-metal build
- docs: README section + CHANGELOG entry

Glyphs that share a byte with an ASCII control (0x09 ○, 0x0A ◙, 0x0D ♪) are
representable; the ASCII fast-path still encodes '\t'/'\n'/'\r' to those bytes,
so callers intercept the source char if they need newline semantics.

* docs: move no_std section to the end of the README

It had grown into a multi-tier feature table and code samples sitting in
the middle of the Usage section, ahead of the basic examples. Move it to
its own top-level section near the end and collapse the two Features
bullets into one line that links to it.

* release: 2.1.0

Minor release for the new optional cp437g code page (#31). Bumps version,
finalizes the CHANGELOG entry, and updates README version references.

* docs: clarify CP437G codegen comment

The glyphs are transcribed from IBMGRAPH.TXT inline, not parsed from it, so
say 'transcribed from' rather than 'per'. Also note that 0x00 is left as NUL
deliberately (the VGA glyph ROM renders it blank).

---------

Co-authored-by: André Sá de Mello <codasm@pm.me>
@bonega bonega closed this in #35 Jun 16, 2026
@bonega

bonega commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Merged this as part of a rebase and other changes in #35
Thank you for the feature @asmello

@asmello

asmello commented Jun 16, 2026

Copy link
Copy Markdown
Contributor Author

Perfect, thanks a lot. I meant to clean this up but haven't had a chance, glad to see you found a way around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants