Skip to content

terminal(feat[compat]): Add DECCOLM, CP437, DOCS (#58) - #61

Open
tony wants to merge 1 commit into
masterfrom
feat/deccolm-cp437-docs
Open

tony wants to merge 1 commit into
masterfrom
feat/deccolm-cp437-docs

Conversation

@tony

@tony tony commented Nov 29, 2026 •

Copy link
Copy Markdown
Member

Closes #58

Summary

  • Add mode-gated 80/132-column switching via DeccolmBehavior and DEC modes ?3, ?40, and ?95.
  • Add 'U' (CP437 0xA0..0xFF) graphic charset designations on G0..G3 in "latin-1" mode.
  • Add opt-in ISO-2022 DOCS (ESC % G and ESC % @) wire-encoding transitions.
  • Raise ValueError from Terminal.feed_str() while the parser wire encoding is "latin-1".
  • Disassemble ESC % G and ESC % @ sequences in libvt.codec.explain().

Changes

Modes, profiles, and configuration

  • src/libvt/modes.py: add Mode.DECCOLM (3), Mode.ALLOW_80_132 (40), and Mode.DECNCSM (95).
  • src/libvt/config.py: add 'U' to Charset, add DeccolmBehavior (IGNORE, GATED_BY_MODE_40, ALWAYS, CLEAR_ONLY), and add deccolm and allow_encoding_switch fields to ScreenBehavior.
  • src/libvt/profiles.py: set deccolm=DeccolmBehavior.IGNORE and allow_encoding_switch=True on LINUX_CONSOLE_PROFILE.
  • src/libvt/contrib/tmux/profile.py: set deccolm=DeccolmBehavior.CLEAR_ONLY in tmux_profile().

Parser, terminal, and codec

  • src/libvt/parser.py: add allow_encoding_switch and Parser.set_encoding(), switching wire encoding on ESC % G and ESC % @ (after ESC aborts any incomplete UTF-8 sequence as U+FFFD), clearing UTF-8 decoder state when entering "latin-1", and restoring the initial encoding on Parser.reset().
  • src/libvt/terminal.py: add Terminal.encoding, implement DECCOLM resize/clear/margin-reset/cursor-homing semantics, save and restore G0..G3/GL/single-shift state across DOCS switches, add the Unicode CP437 0xA0..0xFF table for 'U', order ?95/?3/?40 in XTRESTORE and Formatter VT output, wire RIS and DECRQM, and reject Terminal.feed_str() when parser.encoding == "latin-1".
  • src/libvt/codec.py: disassemble ESC % G (encoding -> UTF-8) and ESC % @ (encoding -> legacy) as DOCS spans in explain().

Tests and documentation

  • tests/test_pyte_compat.py: cover DECCOLM profiles, CP437 'U' shifts and DECSC/DECRC state, 'V' fallback, DOCS split-sequence transitions, and feed_str() in "latin-1" mode.
  • docs/api/config.md and CHANGES: add 'U' to the Charset API directive (DeccolmBehavior renders via automodule) and record the #58 changelog entry.

Design decisions

  • Default ScreenBehavior.deccolm to DeccolmBehavior.GATED_BY_MODE_40 with ?40 initially reset rather than ALWAYS to match xterm's c132=false default; tmux_profile() uses CLEAR_ONLY so tmux retains authoritative pane widths.
  • Select 80 columns unconditionally on CSI ? 3 l rather than restoring a pre-DECCOLM custom width so DECCOLM stays independent of host window resize state.
  • Keep allow_encoding_switch=False on DEFAULT_PROFILE, XTERM_PROFILE, and tmux profiles rather than enabling ESC % @ globally so untrusted output cannot flip UTF-8 sessions into 8-bit C1 parsing; LINUX_CONSOLE_PROFILE opts in with allow_encoding_switch=True.
  • Omit pyte's 'V' (VAX42) designation and keep the US-ASCII 'B' fallback because no clean-room standard mapping satisfies ADR 0001.

Test plan

  • Validate mode-40-gated, always-on, clear-only, and ?95h no-clear DECCOLM transitions in tests/test_pyte_compat.py
  • Validate CP437 'U' G0..G3 shifts, DECSC/DECRC save/restore, and 'V' fallback in tests/test_pyte_compat.py
  • Validate ESC % @ and ESC % G chunk boundaries, RIS reset, and feed_str() guard in tests/test_pyte_compat.py
  • Pass ruff format, ruff check, ty check, pytest, and just build-docs

why: Legacy VT streams and pyte callers rely on 80/132-column switching,
IBM PC CP437 graphic designations, and ISO-2022 wire-encoding switches
without weakening modern UTF-8 or tmux geometry defaults.

what:
- Add Mode.DECCOLM (?3), Mode.ALLOW_80_132 (?40), Mode.DECNCSM (?95),
  and DeccolmBehavior (default GATED_BY_MODE_40; CLEAR_ONLY on tmux)
- Add 'U' (IBM PC / CP437 0xA0..0xFF) G0..G3 charset mapping in latin-1
  mode while keeping 'V' as a documented US-ASCII fallback
- Add opt-in Parser.allow_encoding_switch for ESC % G / ESC % @ DOCS
  transitions, codec.explain disassembly, and feed_str() latin-1 guard

This branch was successfully deployed

1 active deployment
docs — 68357114 Deployed Nov 29, 2026 by tony via build (3.14) #127
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.

Add mode-40-gated DECCOLM, CP437 'U' charset, and DOCS switches

1 participant