term

package
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: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CheckTermPassed = `passed`
	CheckTermFailed = `failed`
	CheckTermDummy  = `dummy` // promoted dummy core method
)
View Source
const (
	QueryStringDA1 = "\033[0c"  // https://terminalguide.namepad.de/seq/csi_sc/
	QueryStringDA2 = "\033[>0c" // https://terminalguide.namepad.de/seq/csi_sc__q/
	QueryStringDA3 = "\033[=0c" // https://terminalguide.namepad.de/seq/csi_sc__r/
)

Variables

This section is empty.

Functions

func CachedQuery

func CachedQuery(qu Querier, qs string, tty TTY, p Parser, prIn, prOut environ.Proprietor) (string, error)

func DisableDrawer

func DisableDrawer(name string)

func DisableTerminal

func DisableTerminal(name string)

func Draw

func Draw(img image.Image, bounds image.Rectangle, rsz Resizer, term *Terminal) error

Draw ...

func DrawWith

func DrawWith(img image.Image, bounds image.Rectangle, dr Drawer, rsz Resizer, term *Terminal) error

DrawWith ...

func GetCursorQuery

func GetCursorQuery(qu Querier, tty TTY) (widthCells, heightCells uint, err error)

GetCursorQuery

func QueryDeviceAttributes

func QueryDeviceAttributes(qu Querier, tty TTY, prIn, prOut environ.Proprietor) error

func RegisterDrawer

func RegisterDrawer(d Drawer)

RegisterDrawer ...

func RegisterTermChecker

func RegisterTermChecker(t TermChecker)

RegisterTerminal ...

func ResetDrawerList

func ResetDrawerList()

func ResetTerminalCheckerList

func ResetTerminalCheckerList()

ResetTerminalCheckerList

func SetCursorQuery

func SetCursorQuery(widthCells, heightCells uint, qu Querier, tty TTY) (err error)

SetCursorQuery

func SizeInCellsAndPixels

func SizeInCellsAndPixels(tty TTY) (widthCells, heightCells, widthPixels, heightPixels uint, err error)

func SizeInCellsQuery

func SizeInCellsQuery(qu Querier, tty TTY) (widthCells, heightCells uint, e error)

SizeInCellsQuery - dtterm window manipulation CSI 18 t

func SizeInPixelsQuery

func SizeInPixelsQuery(qu Querier, tty TTY) (widthPixels, heightPixels uint, e error)

SizeInPixelsQuery - dtterm window manipulation CSI 14 t

func XTGetTCap

func XTGetTCap(tcap string, qu Querier, tty TTY, prIn, prOut environ.Proprietor) (string, error)

Types

type CachedQuerier

type CachedQuerier interface {
	CachedQuery(string, TTY, Parser, environ.Proprietor) (string, error)
}

CachedQuerier ...

func NewCachedQuerier

func NewCachedQuerier(qu Querier) CachedQuerier

type Drawer

type Drawer interface {
	Name() string
	New() Drawer
	IsApplicable(DrawerCheckerInput) bool
	Draw(img image.Image, bounds image.Rectangle, rsz Resizer, term *Terminal) error // TODO

}

Drawer ...

func AllDrawers

func AllDrawers() []Drawer

AllDrawers returns all registered drawers

func DrawersFor

func DrawersFor(inp DrawerCheckerInput) ([]Drawer, error)

DrawersFor ...

func EnabledDrawers

func EnabledDrawers() []Drawer

EnabledDrawers returns all enabled registered drawers

func GetRegDrawerByName

func GetRegDrawerByName(name string) Drawer

GetRegDrawerByName returns registered drawers

type DrawerCheckerInput

type DrawerCheckerInput interface {
	Name() string
	environ.Proprietor
	Querier
	TTY
	wm.Window // TODO remove Close()
}

type Image

type Image struct {
	Original image.Image
	Resized  image.Image
	Fitted   image.Image
	InBand   map[string]inBandString
	FileName string // lazily loaded
	Encoded  []byte // lazily loaded

	DrawerSpec map[string]any
	internal.Closer
	// contains filtered or unexported fields
}

Image ...

func NewImage

func NewImage(img image.Image) *Image

NewImage ...

func NewImageBytes

func NewImageBytes(imgBytes []byte) *Image

NewImageBytes - for lazy loading the file

func NewImageFileName

func NewImageFileName(imgFile string) *Image

NewImageFileName - for lazy loading the file

func (*Image) At

func (i *Image) At(x, y int) color.Color

At ...

func (*Image) Bounds

func (i *Image) Bounds() image.Rectangle

Bounds ...

func (*Image) ColorModel

func (i *Image) ColorModel() color.Model

ColorModel ...

func (*Image) Decode

func (i *Image) Decode() error

Decode decodes and stores the image file in the struct. this is not required for some drawers where the file path is passed to the terminal.

Decode requires registration of image decoders.

func (*Image) Fit

func (i *Image) Fit(bounds image.Rectangle, rsz Resizer, sv Surveyor) error

nil Resizer is allowed (default resizer crops instead of resize)

func (*Image) GetInband

func (i *Image) GetInband(placementCells image.Rectangle, d Drawer, t *Terminal) (string, error)

GetInband ...

func (*Image) Image

func (i *Image) Image() (image.Image, error)

Image ...

func (*Image) SaveAsFile

func (i *Image) SaveAsFile(t *Terminal, fileExt string, enc ImageEncoder) (rm func() error, err error)

SaveAsFile writes the image to a temporary file. Defer Image.Close() or call rm() when no longer needed.

func (*Image) SetInband

func (i *Image) SetInband(placementCells image.Rectangle, inband string, d Drawer, t *Terminal) error

SetInband ...

type ImageEncoder

type ImageEncoder = internal.ImageEncoder

type Options added in v0.0.2

type Options struct {
	PTYName                 string
	TTY                     TTY
	TTYFallback             TTY
	TTYProvFallback         TTYProvider // for NewTerminal()
	Querier                 Querier
	QuerierFallback         Querier
	PartialSurveyor         PartialSurveyor
	PartialSurveyorFallback PartialSurveyor
	WindowProvider          wm.WindowProvider
	WindowProviderFallback  wm.WindowProvider
	Resizer                 Resizer
	Proprietor              environ.Proprietor
	TerminalName            string         // for ComposeTerminal()
	Exe                     string         // for ComposeTerminal()
	Arger                   internal.Arger // for ComposeTerminal()
	Drawers                 []Drawer       // for ComposeTerminal()
	Window                  wm.Window      // for ComposeTerminal()

}

func (*Options) CreateTerminal added in v0.0.2

func (c *Options) CreateTerminal(ch TermChecker) (*Terminal, error)

func (*Options) NewTerminal added in v0.0.2

func (c *Options) NewTerminal(ch TermChecker) (*Terminal, error)

type Parser

type Parser interface {
	Parse(rune) bool
}

Parser.Parse returns true when end of terminal reply is reached.

type ParserFunc

type ParserFunc func(rune) bool

ParserFunc returns true when end of terminal reply is reached.

var StopOnAlpha ParserFunc = func(r rune) bool {
	return (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z')
}

StopOnAlpha ...

func (ParserFunc) Parse

func (f ParserFunc) Parse(r rune) bool

Parse returns true when end of terminal reply is reached.

type PartialSurveyor

type PartialSurveyor interface {
	// TODO doc
	// TODO wm.Window func
	IsPartialSurveyor()
}

PartialSurveyor implements some of:

  • CellSize(tty TTY) (width, height float64, err error)
  • CellSizeQuery(qu Querier, tty TTY) (width, height float64, err error)
  • SizeInCells(tty TTY) (widthCells, heightCells uint, err error)
  • SizeInCellsQuery(qu Querier, tty TTY) (widthCells, heightCells uint, err error)
  • SizeInPixels(tty TTY) (widthPixels, heightPixels uint, err error)
  • SizeInPixelsQuery(qu Querier, tty TTY) (widthPixels, heightPixels uint, err error)
  • SizeInPixelsWindow(w wm.Window) (widthPixels, heightPixels uint, err error)
  • SizeInCellsAndPixels(tty TTY) (widthCells, heightCells, widthPixels, heightPixels uint, err error)
  • GetCursor(tty TTY) (xPosCells, yPosCells uint, err error)
  • GetCursorQuery(qu Querier, tty TTY) (widthCells, heightCells uint, err error)
  • SetCursor(xPosCells, yPosCells uint, tty TTY) (err error)
  • SetCursorQuery(xPosCells, yPosCells uint, qu Querier, tty TTY) (err error)

type Querier

type Querier interface {
	Query(string, TTY, Parser) (string, error)
}

Querier sends escapes sequences to the terminal and returns the answer.

type Resizer

type Resizer interface {
	Resize(img image.Image, size image.Point) (image.Image, error)
}

Resizer resizes images

func ResizerDefault

func ResizerDefault() Resizer

type Surveyor

type Surveyor interface {
	// passes stored TTY, Querier, wm.Window, Proprietor to a SurveyorLight
	CellSize() (width, height float64, err error)
	SizeInCells() (width, height uint, err error)
	SizeInPixels() (width, height uint, err error)
	GetCursor() (xPosCells, yPosCells uint, err error)
	SetCursor(xPosCells, yPosCells uint) (err error)
}

Surveyor is implemented by Terminal

type SurveyorDefault

type SurveyorDefault struct {
}

func (*SurveyorDefault) GetCursorQuery

func (s *SurveyorDefault) GetCursorQuery(qu Querier, tty TTY) (widthCells, heightCells uint, err error)

GetCursorQuery

func (*SurveyorDefault) IsPartialSurveyor

func (s *SurveyorDefault) IsPartialSurveyor()

func (*SurveyorDefault) SetCursorQuery

func (s *SurveyorDefault) SetCursorQuery(xPosCells, yPosCells uint, qu Querier, tty TTY) (err error)

SetCursorQuery

func (*SurveyorDefault) SizeInCellsAndPixels

func (s *SurveyorDefault) SizeInCellsAndPixels(tty TTY) (widthCells, heightCells, widthPixels, heightPixels uint, err error)

SizeInCellsAndPixels ...

func (*SurveyorDefault) SizeInCellsQuery

func (s *SurveyorDefault) SizeInCellsQuery(qu Querier, tty TTY) (widthCells, heightCells uint, e error)

SizeInCellsQuery - dtterm window manipulation CSI 18 t

func (*SurveyorDefault) SizeInPixelsQuery

func (s *SurveyorDefault) SizeInPixelsQuery(qu Querier, tty TTY) (widthPixels, heightPixels uint, e error)

SizeInPixelsQuery - dtterm window manipulation CSI 14 t

type SurveyorLight

type SurveyorLight interface {
	CellSize(TTY, Querier, wm.Window, environ.Proprietor) (width, height float64, err error)
	SizeInCells(TTY, Querier, wm.Window, environ.Proprietor) (width, height uint, err error)
	SizeInPixels(TTY, Querier, wm.Window, environ.Proprietor) (width, height uint, err error)
	GetCursor(TTY, Querier, wm.Window, environ.Proprietor) (xPosCells, yPosCells uint, err error)
	SetCursor(xPosCells, yPosCells uint, tty TTY, qu Querier, w wm.Window, pr environ.Proprietor) (err error)
}

type SurveyorNoANSI

type SurveyorNoANSI struct{}

func (*SurveyorNoANSI) IsPartialSurveyor

func (s *SurveyorNoANSI) IsPartialSurveyor()

func (*SurveyorNoANSI) SizeInCellsAndPixels

func (s *SurveyorNoANSI) SizeInCellsAndPixels(tty TTY) (widthCells, heightCells, widthPixels, heightPixels uint, err error)

SizeInCellsAndPixels ...

type SurveyorNoTIOCGWINSZ

type SurveyorNoTIOCGWINSZ struct{}

func (*SurveyorNoTIOCGWINSZ) IsPartialSurveyor

func (s *SurveyorNoTIOCGWINSZ) IsPartialSurveyor()

func (*SurveyorNoTIOCGWINSZ) SizeInCellsQuery

func (s *SurveyorNoTIOCGWINSZ) SizeInCellsQuery(qu Querier, tty TTY) (widthCells, heightCells uint, e error)

SizeInCellsQuery - dtterm window manipulation CSI 18 t

func (*SurveyorNoTIOCGWINSZ) SizeInPixelsQuery

func (s *SurveyorNoTIOCGWINSZ) SizeInPixelsQuery(qu Querier, tty TTY) (widthPixels, heightPixels uint, e error)

SizeInPixelsQuery - dtterm window manipulation CSI 14 t

type TTY

type TTY interface {
	TTYDevName() string
	// TODO -> io.ReadWriteCloser
	io.Writer                                // Write(p []byte) (n int, err error) // io.Writer
	ReadRune() (r rune, size int, err error) // bufio.Reader.ReadRune() // TODO -> io.Reader
	Close() error                            // io.Closer
}

TTY ...

type TTYProvider

type TTYProvider func(ptyName string) (TTY, error)

type TermChecker

type TermChecker interface {
	// TODO: implement all optional methods through the core and check for nil?
	// The following methods are implemented by embedded *termCheckerCore.
	Name() string
	CheckExclude(environ.Proprietor) (mightBe bool, p environ.Proprietor)
	CheckIsQuery(Querier, TTY, environ.Proprietor) (is bool, p environ.Proprietor)
	CheckIsWindow(wm.Window) (is bool, p environ.Proprietor)
	Check(qu Querier, tty TTY, inp environ.Proprietor) (is bool, p environ.Proprietor)
	NewTerminal(*Options) (*Terminal, error)
	CreateTerminal(*Options) (*Terminal, error)
	Init(tc TermChecker) // called during registration
}

TermChecker must implement at least one of CheckExclude, CheckIs, CheckWindow. For passing on properties create a new Proprietor with NewProprietor. CheckExclude is a preliminary check if the to be checked terminal might be the matching terminal of the TermChecker. CheckExclude can set properties for later exclusion of CheckIs checks, etc, no ANSI querying shall be done during this stage. CheckIs is the final check, ANSI querying is allowed, if not prohibited by the TerminalCheckerInput properties. Alternatively a wm.Window can be compared against with CheckWindow.

  • CheckExclude(TerminalCheckerInput) (mightBe bool, p Proprietor)
  • CheckIs(Querier, TTY, TerminalCheckerInput) (is bool, p Proprietor)
  • CheckWindow(wm.Window) (is bool, p Proprietor)

A new TermChecker has to embed NewTermCheckerCore(name string) providing the TermChecker type identity and the Name() method.

RegisterTermChecker(TermChecker) is used for the registration of the new TermChecker.

Optional methods for setting specific implementations:

  • TTY(pytName string, ci environ.Proprietor) (TTY, error)
  • Querier(environ.Proprietor) Querier
  • Surveyor(environ.Proprietor) PartialSurveyor
  • Window(environ.Proprietor) (wm.Window, error)
  • Args(environ.Proprietor) []string
  • Exe(environ.Proprietor) string

func AllTerminalCheckers

func AllTerminalCheckers() []TermChecker

AllTerminals returns all enabled registered dummy terminals

func GetAllRegTermCheckers

func GetAllRegTermCheckers() []TermChecker

func GetRegTermChecker

func GetRegTermChecker(name string) TermChecker

GetRegTermChecker returns registered terminal checker

func NewTermCheckerCore

func NewTermCheckerCore(name string) TermChecker

type Terminal

type Terminal struct {
	// contains filtered or unexported fields
}

func ComposeTerminal

func ComposeTerminal(cr *Options) (*Terminal, error)

ComposeTerminal manually composes a Terminal ignoring any incongruities.

func NewTerminal

func NewTerminal(opts *Options) (*Terminal, error)

NewTerminal tries to recognize the terminal that manages the device ptyName and matches w. It will use non-zero implementations provided by the optional TerminalChecker methods:

  • TTY(ptyName string, ci environ.Proprietor) (TTY, error)
  • Querier(environ.Proprietor) Querier
  • Surveyor(environ.Proprietor) PartialSurveyor
  • Window(environ.Proprietor) (wm.Window, error)
  • Args(environ.Proprietor) []string
  • Exe(environ.Proprietor) string // alternative executable name if it differs from Name()

The optional Options.…Fallback fields are applied in case the enforced Creator fields are nil and the TermChecker also doesn't return a suggestion.

func (*Terminal) CellSize

func (t *Terminal) CellSize() (width, height float64, err error)

func (*Terminal) Close

func (t *Terminal) Close() error

func (*Terminal) CreateTemp

func (t *Terminal) CreateTemp(pattern string) (*os.File, error)

CreateTemp ...

func (*Terminal) Draw

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

func (*Terminal) Drawers

func (t *Terminal) Drawers() []Drawer

func (*Terminal) Exe

func (t *Terminal) Exe() string

func (*Terminal) GetCursor

func (t *Terminal) GetCursor() (xPosCells, yPosCells uint, err error)

func (*Terminal) Name

func (t *Terminal) Name() string

func (*Terminal) Printf

func (t *Terminal) Printf(format string, a ...any) (int, error)

func (*Terminal) Query

func (t *Terminal) Query(qs string, p Parser) (string, error)

func (*Terminal) SetCursor

func (t *Terminal) SetCursor(xPosCells, yPosCells uint) (err error)

func (*Terminal) SizeInCells

func (t *Terminal) SizeInCells() (width, height uint, err error)

func (*Terminal) SizeInPixels

func (t *Terminal) SizeInPixels() (width, height uint, err error)

func (*Terminal) Window

func (t *Terminal) Window() wm.Window

func (*Terminal) Write

func (t *Terminal) Write(p []byte) (n int, err error)

func (*Terminal) WriteString

func (t *Terminal) WriteString(s string) (n int, err error)

Jump to

Keyboard shortcuts

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