termimg

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2023 License: MIT Imports: 8 Imported by: 0

README

PkgGoDev Go Report Card Lines of code MIT license

TermImg

termimg tries to draw images into terminals.

The rectangular drawing area is given in cell coordinates (not pixels). Origin is the upper left corner.

VERY EXPERIMENTAL!!

implemented drawing methods: sixel, iTerm2, kitty, Terminology, DomTerm, urxvt, X11, GDI+, block characters

Example CLI Tool

timg CLI Tool

installation:

go install github.com/srlehn/termimg/cmd/timg@master

The cell coordinates are passed in this format: <x>,<y>,<w>x<h> where x is the column, y the row, w the width and h the height.

The show command draws the image in the current terminal:

timg show -p 10,10,15x15 picture.png

If an error occurs the --debug=true argument shows where in the code it happens.

The runterm command starts the terminal specified with the -t flag. If no drawer is enforced by the optional -d flag, the best fitting one is used. This command is probably only useful for testing.

timg --debug=true runterm -t mlterm -d sixel -p 10,10,15x15 picture.png

Library Usage

One-Off Image Draw

import (
    _ "github.com/srlehn/termimg/drawers/all"
	_ "github.com/srlehn/termimg/terminals"
)

func main(){
    defer termimg.CleanUp()
    _ = termimg.DrawFile(`picture.png`, image.Rect(10,10,40,25))
}

with NewImage…()

For repeated image drawing create a term.Image via the NewImage…() functions. This allows caching of the encoded image.

import (
    _ "github.com/srlehn/termimg/drawers/all"
	_ "github.com/srlehn/termimg/terminals"
)

func main(){
	tm, _ := termimg.Terminal()
    defer tm.Close()
    timg := termimg.NewImageFileName(`picture.png`)
    _ = tm.Draw(timg, image.Rect(10,10,40,25))
}

Advanced

import (
    _ "github.com/srlehn/termimg/drawers/sane"
	_ "github.com/srlehn/termimg/terminals"
)

func main(){
	wm.SetImpl(wmimpl.Impl())
	opts := &term.Options{
		PTYName:         `dev/pts/2`,
		TTYProvFallback: gotty.New,
		Querier:         qdefault.NewQuerier(),
		Resizer:         &rdefault.Resizer{},
	}
	tm, err := term.NewTerminal(opts)
	if err != nil {
		log.Fatal(err)
	}
    defer tm.Close()
    var img image.Image // TODO load image
    timg := termimg.NewImage(img)
    if err := tm.Draw(timg, image.Rect(10,10,40,25)); err != nil {
		log.Fatal(err)
    }
}

Documentation

Overview

TODO add some documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanUp

func CleanUp() error

CleanUp ...

func Draw

func Draw(img image.Image, bounds image.Rectangle) error

Draw ...

func DrawBytes

func DrawBytes(imgBytes []byte, bounds image.Rectangle) error

DrawBytes - for use with "embed", etc. requires the prior registration of a decoder. e.g.:

import _ "image/png"

func DrawFile

func DrawFile(imgFile string, bounds image.Rectangle) error

DrawFile ...

func NewImage

func NewImage(img image.Image) *term.Image

NewImage ...

func NewImageBytes

func NewImageBytes(imgBytes []byte) *term.Image

NewImageBytes ...

func NewImageFileName

func NewImageFileName(imgfile string) *term.Image

NewImageFileName ...

func NewTerminal

func NewTerminal(ptyName string) (*term.Terminal, error)

NewTerminal ...

func Query

func Query(qs string, p term.Parser) (string, error)

Query ...

func Terminal

func Terminal() (*term.Terminal, error)

Terminal ...

Types

This section is empty.

Directories

Path Synopsis
cmd
drawers
all
x11
env
exc
xdg
query
resize
caire
Seam Carving for Content-Aware Image Resizing
Seam Carving for Content-Aware Image Resizing
rez
tty
gotty
Package gotty provides an implementation of term.TTY via github.com/mattn/go-tty.
Package gotty provides an implementation of term.TTY via github.com/mattn/go-tty.
tui
wm
wmimpl
actual implementation (for X11, Windows)
actual implementation (for X11, Windows)
x11

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL