gassyterm
A small ANSI terminal emulator in C++17 that runs your shell in a real X11 window. It forks the shell onto a pseudo-terminal, parses the escape sequences the shell and its programs emit, and paints the result with Xft.
Build
Requires a C++17 compiler, CMake ≥ 3.16, and the X11 + Xft development
packages (libx11-dev, libxft-dev, libfontconfig1-dev on Debian/Ubuntu).
cmake -S . -B build
cmake --build build -j
Run
./build/gassyterm [shell]
The shell defaults to /bin/sh; pass another one as the first argument. Close
the window or leave the shell (exit, ^D) to quit. The window resizes in whole character
cells and tells the shell about it via SIGWINCH.
How it works
src/pty.cppopens a pty pair (posix_openpt), forks, attaches the slave as the child's controlling terminal andexecs the shell; also handlesTIOCSWINSZ.src/ansi.cppis a byte-level escape sequence state machine (ground, escape, CSI, OSC, DCS). It turns pty output into print/execute/CSI/ESC events without touching the screen.src/terminal.cppconsumes those events: cursor movement, erasing, inserting and deleting characters and lines, scrolling, SGR attributes, saved/restored cursor, and UTF-8 decoding into cells.src/screen.his the cell grid; each cell keeps up to four bytes of UTF-8, foreground/background palette indices and attribute bits.src/x11.cppis the window: display and window setup, fontconfig/Xft font loading, the 256-colour palette, key mapping (modelled onst), and cell-by-cell rendering into a pixmap that is blitted on expose.src/main.cppruns aselectloop over the X connection and the pty, feeds pty output to the terminal and repaints when the screen is dirty.
Keys
Return, Backspace (^H and ^?), Tab, Shift+Tab, Escape, arrows, Home, End,
Insert, Delete, Page Up/Down and F1–F12 send the usual xterm sequences.
Ctrl+letter sends the matching control code; Alt+key prefixes ESC.
Supported
- Cursor movement (
A B C D E F G H f d), insert/delete (@ P L M X), erase (J K), scroll (S T) - SGR attributes (
0 1 2 3 4 7 22 23 24 27) and 16/256 colour (30-37 40-47 90-97 100-107 38;5 48;5 38;2 48;2) ESC 7/ESC 8andCSI s/CSI ucursor save/restore,ESC Mreverse indexCSI ? 25 h/lcursor visibility, UTF-8 output, tab, bell
Not supported
Scroll regions (CSI r), alternate screen buffers, scrollback, mouse reporting,
text selection/clipboard, and OSC title or clipboard sequences. Unrecognised
sequences are parsed and ignored rather than printed literally.