Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hterm

A minimal terminal emulator in C99. SDL2 + SDL_ttf for display, everything else hand-rolled. The goal is small, readable code, not feature parity with xterm.

Layout

file role
term.c/h backend-agnostic core: cell grid, UTF-8 decoder, VT parser
pty.c/h forks $SHELL on a pseudo-terminal
config.h compile-time configuration: font, colors, cursor
main.c SDL2 shell: window, font, glyph cache, event loop, keyboard
test_term.c headless checks for the core (make check)

The core has no SDL dependency, so the renderer is swappable.

Build

Needs sdl2 and SDL2_ttf development packages, e.g. on Void Linux:

sudo xbps-install SDL2-devel SDL2_ttf-devel

Then:

make        # build ./hterm
make check  # run core tests, no display needed

Configuration

Compile-time, st-style: edit config.h and rebuild. It holds the font path and size (empty path = autodetect via fc-match monospace), initial geometry, default foreground/background, the 16-color ANSI palette, and the cursor's color, shape (block / underline / beam) and blink.

What works

  • Full UTF-8: streaming decoder, invalid input → U+FFFD, double-width (CJK, emoji) via wcwidth
  • CSI: cursor movement, erase, insert/delete lines/chars, scroll regions, save/restore cursor, DSR/DA reports, DECSCUSR cursor styles
  • SGR: bold, italic, underline, reverse, 16/256/truecolor; real bold and italic font faces
  • Scrollback history (grows on demand; Shift+PageUp/PageDown, mouse wheel) and the alternate screen, so TUI apps stay out of it
  • Mouse reporting (X10/normal/button/any-motion modes, SGR encoding), so tmux mouse on, vim etc. get clicks, drags and wheel; Shift bypasses reporting for hterm's own scrollback
  • Autowrap with deferred wrap, window resize, Ctrl keys, xterm modifier encodings (Ctrl/Alt/Shift + arrows etc.), Alt-as-Meta, Shift+Tab backtab, Ctrl+Shift+V paste, Ctrl+plus/minus font zoom
  • -e command [args...] to run a command instead of $SHELL
  • OSC 52: applications can set the system clipboard (hed's clipboard plugin, tmux set-clipboard)

Deliberately not (yet) implemented

Selection/copy, combining characters, font fallback (missing glyphs render as tofu), blinking text, OSC other than 52 (title sequences are parsed and discarded).

About

c99, sdl2 based suckless terminal emulator

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages