Documentation ¶
Index ¶
- Variables
- type Attr
- type Color
- type Colorizer
- type Config
- type Cursor
- type Device
- func (d *Device) Clear(x1, y1, x2, y2 int)
- func (d *Device) ColsRemaining() int
- func (d *Device) HandleCSISequence(seq []rune)
- func (d *Device) HandleEscSequence(seq []rune)
- func (d *Device) HandleOSCSequence(seq []rune)
- func (d *Device) Image() image.Image
- func (d *Device) MoveCursorAbs(x, y int)
- func (d *Device) MoveCursorRel(x, y int)
- func (d *Device) RenderRunes(sym []rune)
- func (d *Device) Scroll(amount int)
- func (d *Device) ScrollToCursor()
- func (d *Device) SetCursorStyle(style cursorRectFunc)
- 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 Property
- type Render
Constants ¶
This section is empty.
Variables ¶
var ( // These Colors are for the 4-bit ANSI colors // Since they're exported, they can be overridden. // It would be convient to have a pallet, but given // TrueColor support, why bother? ColorBlack = NewOpaqueColor(0, 0, 0) ColorBrightBlack = NewOpaqueColor(85, 85, 85) ColorRed = NewOpaqueColor(127, 0, 0) ColorBrightRed = NewOpaqueColor(255, 0, 0) ColorGreen = NewOpaqueColor(0, 170, 0) ColorBrightGreen = NewOpaqueColor(85, 255, 85) ColorYellow = NewOpaqueColor(170, 85, 0) ColorBrightYellow = NewOpaqueColor(255, 255, 85) ColorBlue = NewOpaqueColor(0, 0, 170) ColorBrightBlue = NewOpaqueColor(85, 85, 255) ColorMagenta = NewOpaqueColor(170, 0, 170) ColorBrightMagenta = NewOpaqueColor(255, 85, 255) ColorCyan = NewOpaqueColor(0, 170, 170) ColorBrightCyan = NewOpaqueColor(85, 255, 255) // Okay, I deviated from VGA colors here. VGA "white" is way too gray. ColorWhite = NewOpaqueColor(240, 240, 240) // ColorWhite = NewOpaqueColor(170, 170, 170) ColorBrightWhite = NewOpaqueColor(255, 255, 255) )
var ( // CursorBlock, CursorBeam, and CursorUnderscore are the 3 cursor display options. CursorBlock = blockRect CursorBeam = beamRect CursorUnderscore = underscoreRect )
var AttrDefault = Attr{ Fg: ColorWhite, Bg: ColorBlack, }
var Colors256 = [256]Color{}/* 256 elements not displayed */
Colors256 defines the default set of 256 Colors
var ConfigDefault = Config{
TabSize: 8,
}
Functions ¶
This section is empty.
Types ¶
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color both implements color.Color and image.Image. image.Image needs a color.Model, so for convenience's sake, Color also implements color.Model so it can simply have ColorModel() return itself. The main purpose of Color is so there is no need to instantiate an image.Unform everytime we need to draw something in a particular color.
func NewOpaqueColor ¶
NewOpaqueColor returns a Color that has a fully opaque alpha value.
type Colorizer ¶
the tinygo.org/x/drivers/pixel package has a somewhat incompatible color interface with the color.Color interface. This type definition and it's associated function allows a pixel.Color's RGBA method to be cast so that it implements the color.Color interface. Example: pixelColor := pixel.NewColor[pixel.RGB888](127,127,127) drawImage.Set(xPos,yPos, Colorizer(pixelColor.RGBA))
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is used to track the cursor.
type Device ¶
type Device struct { // BellFunc is called if it is non-null and the terminal would // display a bell character // TODO: Implement affirmative beep (default) and negative acknowledge beep // Negative acknowledge is produced when \a is sent while in SHIFT-OUT mode. // Affirmative: C-G (quarter notes?) // NAK: C♭ (whole note?) BellFunc func() // Config species the runtime configurable features of fansiterm. Config Config // Render collects together all the graphical rendering fields. Render Render // Miscellaneous properties, like "Window Title" Properties map[Property]string // 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 sync.Mutex // contains filtered or unexported fields }
Device implements a virtual terminal. It supports being io.Write()n to. It handles the cursor and processing of sequences.
func New ¶
New returns an initialized *Device. If buf is nil, an internal buffer is used. Otherwise if you specify a hardware backed draw.Image, writes to Device will immediately be written to the backing hardware--whether this is instaneous or buffered is up to the device and the device driver.
func NewAtResolution ¶
NewAtResolution is like New, but rather than specifying the columns and rows, you specify the desired resolution. The maximum rows and cols will be determined automatically and the terminal rendered in the center. Fansiterm will only ever update / work on the rectangle it has claimed. If you want to use an existing backing buffer and position that, use NewWithBuf and use xform.SubImage() to locate 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) 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) ColsRemaining ¶
ColsRemaining returns how many columns are remaining until EOL
func (*Device) HandleCSISequence ¶
func (*Device) HandleEscSequence ¶
HandleEscSequence handles escape sequences. This should be the whole complete sequence. Bounds are not checked so an incomplete sequence will cause a panic.
func (*Device) HandleOSCSequence ¶
func (*Device) MoveCursorAbs ¶
func (*Device) MoveCursorRel ¶
func (*Device) RenderRunes ¶
RenderRunes does not do *any* interpretation of escape codes or control characters like \r or \n. It simply renders a slice of runes (as a string) at the cursor position. It is up to the caller of RenderRunes to ensure there's enough space for the runes on the buffer and to process any control sequences.
func (*Device) ScrollToCursor ¶
func (d *Device) ScrollToCursor()
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) VisualBell ¶
func (d *Device) VisualBell()
VisualBell inverts the screen for a quarter second.
func (*Device) Write ¶
Write implements io.Write and is the main way to interract with with (*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.
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. Negative offset values are set to 0, values larger than d.rows * d.cols are set to d.rows*d.cols.