Gritty is a terminal emulator written in Go and Gio UI Framework, focusing on readability and documentation of the code.
You could use this emulator for normal work, but I created it as a reference implementation of vt100-ish terminal emulator. (I use kitty, and I'm happy with it. I only wanted to understand how terminals work.)
Ensure that Gio is installed on your system. Run with go run .
, test with go test .
. Gritty starts /bin/sh
.
graph LR;
subgraph Controller
E
C
I
end
C[Controller] --> B[Buffer]
C[Controller] --> E[EncodeKeys]
E --> PTY
PTY --> P[Parse input]
P --> I[Interpret control sequences]
I --> C
G[GUI] --"send keys"--> C
G --"read buffer"--> C
buffer
- Buffer is the model that contains a grid of characters, it also handles actions like "clear line" or "write rune".parser
- Parser is a control-sequence parser implemented based on the excellent state diagram by Paul Williams.controller
- Controller connects PTY and buffer.- It gives GUI the grid of runes to render and signal when to re-render.
- It receives key events from GUI.
main
- Main package contains the GUI code and starts the terminal emulator.
- Start by understanding the controller.Start method.
- it starts the shell command and starts processing the parsed PTY operations (
c.handleOp
)
- run the code with
gritty_debug=1 go run .
in themain
package. This also enables extended debug logging. - watch the log output when you interact with the terminal and find the log statements using a full-text search.
- VT510 user manual - Contents
- ANSI Control Functions Summary
- Digital VT100 User Guide: Programmer Information - chapter 3
- asciinema/avt - extremely clear implementation of vt100-ish terminal emulator in rust
- ANSI escape code - Wikipedia
- ASCII - Wikipedia
man ascii
- XtermJS - Supported Terminal Sequences - helpful overview of escape sequences
- XTerm Control Sequences