3.7 KiB
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.
Configuration
Settings are read once at startup from $XDG_CONFIG_HOME/gassyterm/config, or
~/.config/gassyterm/config when XDG_CONFIG_HOME is unset. The file is
created with the defaults on first run, and changes apply the next time you
open the window (no rebuild needed).
# ~/.config/gassyterm/config
font = monospace:size=11
foreground = #cccccc
background = #0b0b0b
cursor = #cccccc
shell = /bin/sh
columns = 80
rows = 24
color4 = #2472c8 # optional: override any of color0..color15
fontis a fontconfig pattern, so size, family and style go in one string ("Iosevka:size=13:weight=medium"). If it cannot be matched, a generic monospace font is used instead.- Colours are
#rrggbb.cursorfalls back toforeground. shellis only used when no shell is given on the command line.columnsandrowsset the initial window size in cells.- Unknown keys and malformed values are reported on stderr and ignored, so a typo never stops the terminal from starting.
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/config.cppreads the startup settings from the XDG config directory and creates a commented default file when there is none.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.