Skip to content

viktomas/gritty

Repository files navigation

gritty

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.)

Gritty GIF

Using Gritty

Ensure that Gio is installed on your system. Run with go run ., test with go test .. Gritty starts /bin/sh.

Architecture

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
Loading

Packages

  • 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.

Code walkthrough

  1. Start by understanding the controller.Start method.
  • it starts the shell command and starts processing the parsed PTY operations (c.handleOp)
  1. run the code with gritty_debug=1 go run . in the main package. This also enables extended debug logging.
  2. watch the log output when you interact with the terminal and find the log statements using a full-text search.

Resources

About

Terminal emulator written in Go and Gio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages