MCPcopy Index your code
hub / github.com/BigJk/crt

github.com/BigJk/crt @v0.0.15

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.15 ↗ · + Follow
173 symbols 367 edges 26 files 39 documented · 23% updated 2y agov0.0.15 · 2024-05-09★ 108
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

crt — cathode-ray tube

Screenshot

About

CRT is a library to provide a simple terminal emulator that can be attached to a tea.Program. It uses ebitengine to render a terminal. It supports TrueColor, Mouse and Keyboard input. It interprets the CSI escape sequences coming from bubbletea and renders them to the terminal.

This started as a simple proof of concept for the game I'm writing with the help of bubbletea, called End Of Eden. I wanted to give people who have no clue about the terminal a simple option to play the game without interacting with the terminal directly. It's also possible to apply shaders to the terminal to give it a more retro look which is a nice side effect.

Usage

go get github.com/BigJk/crt@latest
package main

import (
    "github.com/BigJk/crt"
    bubbleadapter "github.com/BigJk/crt/bubbletea"
    tea "github.com/charmbracelet/bubbletea"
    "github.com/charmbracelet/lipgloss"
    "image/color"
)

// Some tea.Model ...

func main() {
    // Load fonts for normal, bold and italic text styles.
    fonts, err := crt.LoadFaces("./fonts/SomeFont-Regular.ttf", "./fonts/SomeFont-Bold.ttf", "./fonts/SomeFont-Italic.ttf", crt.GetFontDPI(), 16.0)
    if err != nil {
        panic(err)
    }

    // Just pass your tea.Model to the bubbleadapter, and it will render it to the terminal.
    win, _, err := bubbleadapter.Window(1000, 600, fonts, someModel{}, color.Black, tea.WithAltScreen())
    if err != nil {
        panic(err)
    }

    // Star the terminal with the given title.
    if err := win.Run("Simple"); err != nil {
        panic(err)
    }
}

See more examples in the /examples folder!

Limitations

  • ~~Only supports TrueColor at the moment (no 256 color support) so you need to use TrueColor colors in lipgloss (e.g. lipgloss.Color("#ff0000"))~~ Now supported.
  • Not all CSI escape sequences are implemented but the ones that are used by bubbletea are implemented
  • Key handling is a bit quirky atm. Ebiten to bubbletea key mapping is not perfect and some keys are not handled correctly yet.
  • A lot of testing still needs to be done and there are probably edge cases that are not handled correctly yet

Credits

  • Basic CRT Shader ./shader/crt_basic: https://quasilyte.dev/blog/post/ebitengine-shaders/
  • Lottes CRT Shader ./shader/crt_lotte: Elias Daler https://github.com/eliasdaler/crten and Timothy Lottes.

Extension points exported contracts — how you extend this code

Core symbols most depended-on inside this repo

Shape

Method 72
Struct 50
Function 44
TypeAlias 3
FuncType 2
Interface 2

Languages

Go100%

Modules by API surface

crt.go29 symbols
csi.go22 symbols
sgr.go11 symbols
bubbletea/adapter_bubbletea.go11 symbols
adapter.go11 symbols
examples/shader/main.go10 symbols
examples/package-manager/main.go10 symbols
examples/split-editor/main.go9 symbols
examples/glamour/main.go7 symbols
adapter_empty.go7 symbols
read_writer.go5 symbols
font.go5 symbols

For agents

$ claude mcp add crt \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page