tcg icon indicating copy to clipboard operation
tcg copied to clipboard

Terminal cell graphics library

Go Reference GitHub Action Coverage Status Go Report Card

TCG - terminal cell graphics

Go Graphics library for use in a text terminal. Only 1bit graphics can be used with two colors. Used unicode block symbols for drawing. 2x3 mode is supported by the latest versions of the Iosevka font.

Features

Install

go get -u github.com/msoap/tcg

Usage

package main

import (
	"log"

	"github.com/gdamore/tcell/v2"
	"github.com/msoap/tcg"
)

func main() {
	tg, err := tcg.New(tcg.Mode2x3) // each terminal symbol contains a 2x3 pixels grid, also you can use 1x1, 1x2, and 2x2 modes
	if err != nil {
		log.Fatalf("create tg: %s", err)
	}

	i := 0
	for {
		pixColor := tg.Buf.At(10, 10)       // get color of pixel
		tg.Buf.Set(11, 11, pixColor)        // draw one pixel with color from 10,10
		tg.Buf.Line(0, 0, 50, i, tcg.Black) // draw a diagonal line
		tg.Show()                           // synchronize buffer with screen

		if ev, ok := tg.TCellScreen.PollEvent().(*tcell.EventKey); ok && ev.Rune() == 'q' {
			break // exit by 'q' key
		}
		i++
	}

	tg.Finish() // finish application and restore screen
}

See more examples in examples folder.

Screenshot

Game of Life example in iTerm2 terminal with Iosevka font:

TCG example screenshot for Game of Life

TODO

  • [ ] fonts support
  • [ ] sprites, maybe with animation

See also

Unicode symbols:

Supported fonts: