How koteitan/koteiterm works
Project Type and Purpose
• This is a native Linux terminal emulator written in C, using X11/Xft for rendering.
• It includes an optional Windows-clipboard integration subproject (winclip).
File Structure
• Top-level: src/ (core modules), include/ (headers), test/ (shell integration tests), winclip/ (WSL/Win clipboard helper).
• Core modules in src/:
• main.c – program entry, main loop coordination
• input.c – keyboard & mouse event handling
• pty.c – pseudoterminal master/slave management
• terminal.c – VT100 escape‐sequence parser & terminal buffer
• display.c – X11 window management & rendering
• Build/deploy files: Makefile, winclip/Makefile.
Extract Key Architecture Notes from README
• stdin → input buffer → main loop → (Media Copy vs normal data) → PTY write → shell process → PTY read → VT100 parser → terminal buffer → (render or screenshot) → X11 window or stdout.
• External libs: X11, Xft, Fontconfig, Freetype, Imlib2, GIF.
• Optional: MinGW cross-compile for winclip.exe.
Main Components & Their Relationships
1. CLI Frontend
• Reads stdin (user input, piped commands)
• Presents command‐line flags
2. Input Manager (input.c)
• Handles keyboard/mouse events
• Dispatches to PTY master (key events) or selection logic
3. Media Copy Detector (terminal.c helper)
• Scans for ESC[5i/4i/4;0i sequences
• Branches to screenshot logic
4. PTY Layer (pty.c)
• PTY Master FD write: sends input to shell
• PTY Master FD read: reads shell output
5. Shell Process (external bash/zsh)
6. VT100 Parser & Terminal Buffer (terminal.c)
• Parses escape sequences, updates g_terminal.cells[]
• Maintains scrollback buffer
8. Screenshot Handler
• Captures buffer on ESC[5i → stores in screenshot buffer
• Emits on ESC[4i to stdout
9. WinClip Bridge (winclip/winclip.c)
• Invoked in WSL for Windows clipboard sync
• X11
• Xft / Fontconfig / Freetype
• Imlib2 / GIF libs
• Shell binary
Architectural Patterns & Design Principles
• Modular C architecture: each subsystem in its own module / header
• Event-driven loop: MainLoop polls stdin, PTY, X events
• Separation of concerns: input vs parsing vs rendering vs I/O
• Extensibility points: adding new VT100 sequences, custom cursors, additional escape commands
Detailed Elements
• Input/Output
• Core Parser/Buffer
• Rendering
• External processes & libs