Documentation
¶
Overview ¶
Package fansiterm provides a fully featured, graphics-capable virtual terminal implementation designed for environments with minimal or no operating support. Originally implemented to run on microcontrollers and works well with TinyGo.
Index ¶
- Variables
- func DecodeImageData(data []rune) (image.Image, error)
- type Attr
- type Color
- type Colorizer
- type Config
- type Cursor
- type Device
- func (d *Device) BlinkCursor()
- func (d *Device) Clear(x1, y1, x2, y2 int)
- func (d *Device) GetReader() (rd io.Reader)
- func (d *Device) Image() image.Image
- func (d *Device) RenderRune(sym rune) (width int)
- func (d *Device) Reset()
- func (d *Device) Scroll(rowAmount int)
- func (d *Device) SetAttrDefault(attr Attr)
- func (d *Device) SetCursorStyle(style cursorRectFunc)
- func (d *Device) Size() (int, int)
- func (d *Device) Stop()
- func (d *Device) UpdateAttr()
- func (d *Device) UseBuf(buf draw.Image)
- func (d *Device) VectorScrollCells(c1, r1, c2, r2, cn, rn int)
- func (d *Device) VisualBell()
- func (d *Device) Write(data []byte) (n int, err error)
- func (d *Device) WriteAt(p []byte, off int64) (n int, err error)
- type Logger
- type Property
- type RGBColor
- type RGBImage
- type Render
- func (r Render) Bounds() image.Rectangle
- func (r *Render) Fill(region image.Rectangle, c color.Color)
- func (r *Render) RegionScroll(region image.Rectangle, pixAmt int)
- func (r *Render) Scroll(pixAmt int)
- func (r Render) Set(x, y int, c color.Color)
- func (r *Render) VectorScroll(region image.Rectangle, vector image.Point)
Constants ¶
This section is empty.
Variables ¶
var ( // ShowEsc if set to true (default false) prints to stdout escape sequences as received by fansiterm ShowEsc bool // ShowUnhandled if set to true (default false) prints to stdout escape sequencies that fansiterm does not actually handle. ShowUnhandled bool )
var ( PaletteANSI []Color Palette256 []Color )
Ensure at build-time the Color implementation has implemented both color.Color and image.Image.
var ( BlockCursor = cursorRectFunc(blockRect) BeamCursor = cursorRectFunc(beamRect) UnderscoreCursor = cursorRectFunc(underscoreRect) )
var ConfigDefault = Config{ TabSize: 8, StrikethroughHeight: 7, BoldColors: true, }
ConfigDefault provides the default configuration values for a Device.
var (
LogOutput io.Writer
)
Functions ¶
Types ¶
type Attr ¶
type Attr struct {
Bold bool
Underline bool
DoubleUnderline bool
Strike bool
Blink bool
Reversed bool
Italic bool
Conceal bool
Fg Color
Bg Color
}
Attr defines the attributes applied to rendered text.
type Color ¶
func NewColorFromRGBA ¶
func NewOpaqueColor ¶
NewOpaqueColor returns a Color with full opacity (alpha = 255).
func (Color) Bounds ¶
Bounds implements image.Image. It returns an extremely large bounding rectangle to satisfy the image.Image interface when Color is used as an image.
func (Color) ColorModel ¶
ColorModel implements image.Image and color.Model.
type Colorizer ¶
Colorizer is an adapter that allows a pixel.Color's RGBA method to satisfy the color.Color interface used by the Go image packages.
Example usage:
pixelColor := pixel.NewColor[pixel.RGB888](127,127,127) drawImage.Set(x, y, Colorizer(pixelColor.RGBA))
type Config ¶
type Config struct {
LocalEcho bool
TabSize int // Number of spaces per tab.
StrikethroughHeight int // Pixel height offset for strike-through.
CursorStyle int // Default cursor style.
BoldColors bool // Whether bold colors are enabled.
AltScreen bool // Enable alternate screen buffer (expensive on MCUs).
Wraparound bool // Whether text wraps at the screen edge.
CursorKeyApplicationMode bool // Enable application mode for cursor keys.
MouseEvents int // 0, 1000, 10002, or 1003
MouseSGR bool // if false, use \e[Mcbxbyb reporting; else use \e[<
// Miscellaneous properties, like "Window Title"
Properties map[Property]string
}
Config defines runtime settings for a Device.
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is used to track the cursor.
func (*Cursor) ColsRemaining ¶
ColsRemaining returns how many columns are remaining until EO
func (*Cursor) RestorePos ¶
func (c *Cursor) RestorePos()
func (*Cursor) ToggleAltPos ¶
func (c *Cursor) ToggleAltPos()
ToggleAltPos toggles between the main screen's position and the alt screen's position.
type Device ¶
type Device struct {
// BellFunc is called if it is non-null and the terminal would
// display a bell character
BellFunc func(id string)
// Config specifies the runtime configurable features of fansiterm.
Config Config
// ConfigUpdate, if non-nil, is called when the config changes.
ConfigUpdate func(conf Config)
// Render collects together all the graphical rendering fields.
Render Render
// Output specifies the program attached to the terminal. This should be the
// same interface that the input mechanism (whatever that may be) uses to write
// to the program. On POSIX systems, this would be equivalent to Stdin.
// Default is io.Discard. Setting to nil will cause Escape Sequences that
// write a response to panic.
Output io.Writer
// UserResetFunc is called when fansiterm's Reset() method is called. This
// is the same Reset triggered by an \x1bc escape sequence. This can be used
// to reset a hardware display.
UserResetFunc func()
sync.Mutex
// contains filtered or unexported fields
}
Device implements a virtual terminal. It satisfies the io.Writer interface and supports ANSI escape sequences, custom fonts, raster graphics, and more. It is thread-safe and optimized for embedded or minimal environments.
func New ¶
New initializes a new terminal device with the specified dimensions and optional draw.Image buffer. If buf is nil, a default in-memory RGBA buffer is allocated. The terminal's character size is fixed.
func NewAtResolution ¶
NewAtResolution returns a new Device sized to fit a resolution (x,y), centering the terminal.
func NewWithBuf ¶
NewWithBuf uses buf as its target. NewWithBuf() will panic if called against a nil buf. If using fansiterm with backing hardware, NewWithBuf is likely the way you want to instantiate fansiterm. If you have buf providing an interface to a 240x135 screen, using the default 8x16 tiles, you can have an 40x8 cell terminal, with 7 rows of pixels leftover. If you want to have those extra 7 rows above the rendered terminal, you can do so like this:
term := NewWithBuf(xform.SubImage(buf,image.Rect(0,0,240,128).Add(0,7)))
Note: you can skip the Add() and just define your rectangle as image.Rect(0,7,240,135), but I find supplying the actual dimensions and then adding an offset to be clearer.
func (*Device) BlinkCursor ¶
func (d *Device) BlinkCursor()
func (*Device) Clear ¶
Clear writes a block of current background color in a rectangular shape, specified in units of cells (rows and columns). So (*Device).Clear(0,0, (*Device).cols, (*Device).rows) would clear the whole screen.
func (*Device) GetReader ¶
GetReader returns an io.Reader that fansiterm will use for output. This uses an io.Pipe under the hood. The write portion of the pipe displaces (*Device).Output. A new pipe is instantiated every time this is called and will displace the old pipe.
func (*Device) RenderRune ¶
RenderRune does not do *any* interpretation of escape codes or control characters like \r or \n. It simply renders a single rune at the cursor position. It is up to the caller of RenderRune to process any control sequences / handle non-printing characters.
func (*Device) SetAttrDefault ¶
func (*Device) SetCursorStyle ¶
func (d *Device) SetCursorStyle(style cursorRectFunc)
SetCursorStyle changes the shape of the cursor. Valid options are CursorBlock, CursorBeam, and CursorUnderscore. CursorBlock is the default.
func (*Device) UpdateAttr ¶
func (d *Device) UpdateAttr()
func (*Device) VectorScrollCells ¶
func (*Device) VisualBell ¶
func (d *Device) VisualBell()
VisualBell inverts the screen for a tenth of a second.
func (*Device) Write ¶
Write implements io.Write and is the main way to interract with a (*fansiterm).Device. This is essentially writing to the "terminal." Writes are more or less unbuffered with the exception of escape sequences. If a partial escape sequence is written to Device, the beginning will be bufferred and prepended to the next write. Certain broken escape sequence can potentially block forever.
func (*Device) WriteAt ¶
WriteAt works like calling the save cursor position escape sequence, then the absolute set cursor position escape sequence, writing to the terminal, and then finally restoring cursor position. The offset is just the i'th character on screen. Offset values are clamped: Negative offset values are set to 0, values larger than d.rows * d.cols are set to d.rows*d.cols-1.
type Render ¶
type Render struct {
draw.Image
CharSet tiles.Tiler
AltCharSet tiles.Tiler
BoldCharSet tiles.Tiler
ItalicCharSet tiles.Tiler
User tiles.FullColorTileSet
// DisplayFunc is called after a write to the terminal. This is for some displays that require a flush / blit / sync call.
DisplayFunc func()
// contains filtered or unexported fields
}

