Files
gassyterm/README.md
T
2026-11-12 16:49:04 -04:00

3.7 KiB
Raw Blame History

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
  • font is 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. cursor falls back to foreground.
  • shell is only used when no shell is given on the command line.
  • columns and rows set 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.cpp opens a pty pair (posix_openpt), forks, attaches the slave as the child's controlling terminal and execs the shell; also handles TIOCSWINSZ.
  • src/ansi.cpp is 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.cpp consumes 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.h is the cell grid; each cell keeps up to four bytes of UTF-8, foreground/background palette indices and attribute bits.
  • src/config.cpp reads the startup settings from the XDG config directory and creates a commented default file when there is none.
  • src/x11.cpp is the window: display and window setup, fontconfig/Xft font loading, the 256-colour palette, key mapping (modelled on st), and cell-by-cell rendering into a pixmap that is blitted on expose.
  • src/main.cpp runs a select loop 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 8 and CSI s/CSI u cursor save/restore, ESC M reverse index
  • CSI ? 25 h/l cursor 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.