Documentation ¶
Index ¶
- func CachedQuery(qu Querier, qs string, tty TTY, p Parser, prIn, prOut environ.Properties) (string, error)
- func DisableDrawer(name string)
- func DisableTerminal(name string)
- func Draw(img image.Image, bounds image.Rectangle, term *Terminal, dr Drawer) error
- func QueryDeviceAttributes(qu Querier, tty TTY, prIn, prOut environ.Properties) error
- func RegisterDrawer(d Drawer)
- func RegisterTermChecker(t TermChecker)
- func ResetDrawerList()
- func ResetTerminalCheckerList()
- type CachedQuerier
- type Canvas
- func (c *Canvas) At(x, y int) color.Color
- func (c *Canvas) Bounds() image.Rectangle
- func (c *Canvas) CellArea() image.Rectangle
- func (c *Canvas) Close() error
- func (c *Canvas) ColorModel() color.Model
- func (c *Canvas) Draw(img image.Image) error
- func (c *Canvas) Offset() image.Point
- func (c *Canvas) Screenshot() (image.Image, error)
- func (c *Canvas) Set(x, y int, col color.Color)
- func (c *Canvas) SetCellArea(bounds image.Rectangle) error
- func (c *Canvas) SetImage(img image.Image) error
- func (c *Canvas) Video(ctx context.Context, vid <-chan image.Image, frameDur time.Duration) error
- type Drawer
- type DrawerCheckerInput
- type Image
- func (i *Image) At(x, y int) color.Color
- func (i *Image) Bounds() image.Rectangle
- func (i *Image) ColorModel() color.Model
- func (i *Image) Decode() error
- func (i *Image) DrawerObject(d Drawer) (any, error)
- func (i *Image) Fit(bounds image.Rectangle, rsz Resizer, sv Surveyor) error
- func (i *Image) Image() (image.Image, error)
- func (i *Image) Inband(placementCells image.Rectangle, d Drawer, t *Terminal) (string, error)
- func (i *Image) PosObject(placementCells image.Rectangle, d Drawer, t *Terminal) (any, error)
- func (i *Image) SaveAsFile(t *Terminal, fileExt string, enc ImageEncoder) (rm func() error, err error)
- func (i *Image) SetDrawerObject(obj any, d Drawer) error
- func (i *Image) SetInband(placementCells image.Rectangle, inband string, d Drawer, t *Terminal) error
- func (i *Image) SetPosObject(placementCells image.Rectangle, obj any, d Drawer, t *Terminal) error
- type ImageEncoder
- type OptFunc
- type Option
- func AfterSetup(f func(*Terminal)) Option
- func SetArgs(args []string) Option
- func SetDrawers(drs []Drawer) Option
- func SetExe(exe string) Option
- func SetLogFile(filename string, enable bool) Option
- func SetPTYName(ptyName string) Option
- func SetProprietor(pr environ.Properties, merge bool) Option
- func SetQuerier(qu Querier, enforce bool) Option
- func SetResizer(rsz Resizer) Option
- func SetSLogHandler(h slog.Handler, enable bool) Option
- func SetSurveyor(ps PartialSurveyor, enforce bool) Option
- func SetTTY(tty TTY, enforce bool) Option
- func SetTTYProvider[T TTY, F func(ptyName string) (T, error)](ttyProv F, enforce bool) Option
- func SetTerminalName(termName string) Option
- func SetWindow(w wm.Window) Option
- func SetWindowProvider(wProv wm.WindowProvider, enforce bool) Option
- type Options
- type Parser
- type ParserFunc
- type PartialSurveyor
- type Querier
- type Resizer
- type Resolution
- type Surveyor
- type SurveyorDefault
- func (s *SurveyorDefault) CursorQuery(qu Querier, tty TTY) (widthCells, heightCells uint, err error)
- func (s *SurveyorDefault) IsPartialSurveyor()
- func (s *SurveyorDefault) ResizeEvents(tty TTY) (_ <-chan Resolution, closeFunc func() error, _ error)
- func (s *SurveyorDefault) SetCursorQuery(xPosCells, yPosCells uint, qu Querier, tty TTY) (err error)
- func (s *SurveyorDefault) SizeInCellsAndPixels(tty TTY) (widthCells, heightCells, widthPixels, heightPixels uint, err error)
- func (s *SurveyorDefault) SizeInCellsQuery(qu Querier, tty TTY) (widthCells, heightCells uint, e error)
- func (s *SurveyorDefault) SizeInPixelsQuery(qu Querier, tty TTY) (widthPixels, heightPixels uint, e error)
- func (s *SurveyorDefault) SizeInPixelsWindow(w wm.Window) (widthPixels, heightPixels uint, err error)
- type SurveyorLight
- type SurveyorNoANSI
- type SurveyorNoTIOCGWINSZ
- func (s *SurveyorNoTIOCGWINSZ) IsPartialSurveyor()
- func (s *SurveyorNoTIOCGWINSZ) ResizeEvents(tty TTY) (_ <-chan Resolution, closeFunc func() error, _ error)
- func (s *SurveyorNoTIOCGWINSZ) SizeInCellsQuery(qu Querier, tty TTY) (widthCells, heightCells uint, e error)
- func (s *SurveyorNoTIOCGWINSZ) SizeInPixelsQuery(qu Querier, tty TTY) (widthPixels, heightPixels uint, e error)
- type TTY
- type TermChecker
- type Terminal
- func (t *Terminal) CellScale(ptSrcPx, ptDstCl image.Point) (ptSrcCl image.Point, _ error)
- func (t *Terminal) CellSize() (width, height float64, _ error)
- func (t *Terminal) Close() error
- func (t *Terminal) CreateTemp(pattern string) (*os.File, error)
- func (t *Terminal) Cursor() (xPosCells, yPosCells uint, err error)
- func (t *Terminal) Draw(img image.Image, bounds image.Rectangle) error
- func (t *Terminal) Drawers() []Drawer
- func (t *Terminal) Env() environ.Enver
- func (t *Terminal) Logger() *slog.Logger
- func (t *Terminal) Name() string
- func (t *Terminal) NewCanvas(bounds image.Rectangle) (*Canvas, error)
- func (t *Terminal) Printf(format string, a ...any) (int, error)
- func (t *Terminal) Query(qs string, p Parser) (string, error)
- func (t *Terminal) Resizer() Resizer
- func (t *Terminal) Scroll(lineCnt int) error
- func (t *Terminal) SetCursor(xPosCells, yPosCells uint) (err error)
- func (t *Terminal) SetOptions(opts ...Option) error
- func (t *Terminal) SizeInCells() (width, height uint, err error)
- func (t *Terminal) SizeInPixels() (width, height uint, err error)
- func (t *Terminal) TTY() TTY
- func (t *Terminal) Window() wm.Window
- func (t *Terminal) Write(p []byte) (n int, err error)
- func (t *Terminal) WriteString(s string) (n int, err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CachedQuery ¶
func DisableDrawer ¶
func DisableDrawer(name string)
func DisableTerminal ¶
func DisableTerminal(name string)
func Draw ¶
Draw draws an image on the terminal. bounds is the drawing area in cells. if the passed drawer is nil, the Terminals drawer is used.
func QueryDeviceAttributes ¶
func QueryDeviceAttributes(qu Querier, tty TTY, prIn, prOut environ.Properties) error
QueryDeviceAttributes should only be used for external TermCheckers
func ResetDrawerList ¶
func ResetDrawerList()
Types ¶
type CachedQuerier ¶
type CachedQuerier interface {
CachedQuery(string, TTY, Parser, environ.Properties) (string, error)
}
CachedQuerier ...
func NewCachedQuerier ¶
func NewCachedQuerier(qu Querier) CachedQuerier
type Canvas ¶ added in v0.0.3
type Canvas struct {
// contains filtered or unexported fields
}
Canvas has to be created with (*term.Terminal).NewCanvas()
func (*Canvas) ColorModel ¶ added in v0.0.3
func (*Canvas) SetCellArea ¶ added in v0.0.5
type Drawer ¶
type Drawer interface { Name() string New() Drawer IsApplicable(DrawerCheckerInput) (bool, environ.Properties) Draw(img image.Image, bounds image.Rectangle, term *Terminal) error Prepare(ctx context.Context, img image.Image, bounds image.Rectangle, term *Terminal) (drawFn func() error, _ error) }
Drawer ...
func EnabledDrawers ¶
func EnabledDrawers() []Drawer
EnabledDrawers returns all enabled registered drawers
func GetRegDrawerByName ¶
GetRegDrawerByName returns registered drawers
type DrawerCheckerInput ¶
type Image ¶
type Image struct { Original image.Image Resized image.Image Cropped image.Image FileName string // lazily loaded Encoded []byte // lazily loaded internal.Closer // contains filtered or unexported fields }
Image ...
func NewImageBytes ¶
NewImageBytes - for lazy loading the file
func NewImageFilename ¶ added in v0.0.3
NewImageFilename - for lazy loading the file
func (*Image) Decode ¶
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) DrawerObject ¶ added in v0.0.4
DrawerObject ...
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) SetDrawerObject ¶ added in v0.0.3
SetDrawerObject ...
type ImageEncoder ¶
type ImageEncoder = internal.ImageEncoder
type OptFunc ¶ added in v0.0.3
func (OptFunc) ApplyOption ¶ added in v0.0.3
type Option ¶ added in v0.0.3
func AfterSetup ¶ added in v0.0.5
func SetDrawers ¶ added in v0.0.3
func SetLogFile ¶ added in v0.0.4
func SetPTYName ¶ added in v0.0.3
func SetProprietor ¶ added in v0.0.3
func SetProprietor(pr environ.Properties, merge bool) Option
func SetQuerier ¶ added in v0.0.3
func SetResizer ¶ added in v0.0.3
func SetSurveyor ¶ added in v0.0.3
func SetSurveyor(ps PartialSurveyor, enforce bool) Option
func SetTTYProvider ¶ added in v0.0.3
ttyProv is implemented by the New constructors in the subpackages of the tty package
func SetTerminalName ¶ added in v0.0.3
func SetWindowProvider ¶ added in v0.0.3
func SetWindowProvider(wProv wm.WindowProvider, enforce bool) Option
type ParserFunc ¶
ParserFunc returns true when end of terminal reply is reached.
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)
- Cursor(tty TTY) (xPosCells, yPosCells uint, err error)
- CursorQuery(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)
- ResizeEvents(tty TTY) (<-chan Resolution, error)
- ResizeEventsWindow(w wm.Window) (<-chan Resolution, error)
func DefaultSurveyor ¶ added in v0.0.3
func DefaultSurveyor() PartialSurveyor
type Resolution ¶ added in v0.0.4
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) Cursor() (xPosCells, yPosCells uint, err error) SetCursor(xPosCells, yPosCells uint) (err error) CellScale(ptSrcPx, ptDstCl image.Point) (ptSrcCl image.Point, _ error) }
Surveyor is implemented by Terminal
type SurveyorDefault ¶
type SurveyorDefault struct { }
func (*SurveyorDefault) CursorQuery ¶ added in v0.0.4
func (s *SurveyorDefault) CursorQuery(qu Querier, tty TTY) (widthCells, heightCells uint, err error)
CursorQuery
func (*SurveyorDefault) IsPartialSurveyor ¶
func (s *SurveyorDefault) IsPartialSurveyor()
func (*SurveyorDefault) ResizeEvents ¶ added in v0.0.4
func (s *SurveyorDefault) ResizeEvents(tty TTY) (_ <-chan Resolution, closeFunc func() error, _ error)
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
func (*SurveyorDefault) SizeInPixelsWindow ¶ added in v0.0.3
func (s *SurveyorDefault) SizeInPixelsWindow(w wm.Window) (widthPixels, heightPixels uint, err error)
SizeInPixelsWindow
type SurveyorLight ¶
type SurveyorLight interface { CellSize(TTY, Querier, wm.Window, environ.Properties) (width, height float64, err error) SizeInCells(TTY, Querier, wm.Window, environ.Properties) (width, height uint, err error) SizeInPixels(TTY, Querier, wm.Window, environ.Properties) (width, height uint, err error) Cursor(TTY, Querier, wm.Window, environ.Properties) (xPosCells, yPosCells uint, err error) SetCursor(xPosCells, yPosCells uint, tty TTY, qu Querier, w wm.Window, pr environ.Properties) (err error) WatchResizeEventsStart(TTY, Querier, wm.Window, environ.Properties) (_ <-chan Resolution, closeFunc func() error, _ error) WatchResizeEventsStop() error }
type SurveyorNoANSI ¶
type SurveyorNoANSI struct{}
func (*SurveyorNoANSI) IsPartialSurveyor ¶
func (s *SurveyorNoANSI) IsPartialSurveyor()
func (*SurveyorNoANSI) ResizeEvents ¶ added in v0.0.4
func (s *SurveyorNoANSI) ResizeEvents(tty TTY) (_ <-chan Resolution, closeFunc func() error, _ error)
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) ResizeEvents ¶ added in v0.0.4
func (s *SurveyorNoTIOCGWINSZ) ResizeEvents(tty TTY) (_ <-chan Resolution, closeFunc func() error, _ error)
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 { io.ReadWriteCloser TTYDevName() string }
TTY ... optional methods:
- ResizeEvents() (_ <-chan Resolution, closeFunc func() error, _ error)
- SizePixel() (cw int, ch int, pw int, ph int, e error)
- ReadRune() (r rune, size int, err error) // io.RuneReader
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.Properties) (mightBe bool, p environ.Properties) CheckIsQuery(Querier, TTY, environ.Properties) (is bool, p environ.Properties) CheckIsWindow(wm.Window) (is bool, p environ.Properties) Check(qu Querier, tty TTY, inp environ.Properties) (is bool, p environ.Properties) NewTerminal(...Option) (*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 AllRegisteredTermCheckers ¶ added in v0.0.3
func AllRegisteredTermCheckers() []TermChecker
func AllTerminalCheckers ¶
func AllTerminalCheckers() []TermChecker
AllTerminals returns all enabled registered dummy terminals
func NewTermCheckerCore ¶
func NewTermCheckerCore(name string) TermChecker
func RegisteredTermChecker ¶ added in v0.0.3
func RegisteredTermChecker(name string) TermChecker
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
func NewTerminal ¶
NewTerminal tries to recognize the terminal that manages the device ptyName. It will use suggestions 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()
"Enforced" Options have precedence over the TermCheckers suggestion.
func (*Terminal) CellScale ¶ added in v0.0.3
CellScale returns a cell size for pixel size <ptSrcPx> to the cell size <ptDstCl> while maintaining the scale. With no passed 0 side length values, the largest subarea is returned. With one passed 0 side length value, the other side length will be fixed. With two passed 0 side length values, pixels in source and destination area at the same position correspond to each other.
func (*Terminal) CreateTemp ¶
CreateTemp ...