Documentation
¶
Overview ¶
Package term provides terminal management for VT220-compatible terminals. It handles character set designation, invocation (shifting), and provides an io.Writer interface for encoding UTF-8 text to the terminal's character set.
Index ¶
- Variables
- type AttrBuilder
- func (a *AttrBuilder) Blink() *AttrBuilder
- func (a *AttrBuilder) Bold() *AttrBuilder
- func (a *AttrBuilder) Bprint(args ...any) []byte
- func (a *AttrBuilder) Bprintf(format string, args ...any) []byte
- func (a *AttrBuilder) Bprintln(args ...any) []byte
- func (a *AttrBuilder) Negative() *AttrBuilder
- func (a *AttrBuilder) Print(args ...any) (int, error)
- func (a *AttrBuilder) Printf(format string, args ...any) (int, error)
- func (a *AttrBuilder) Println(args ...any) (int, error)
- func (a *AttrBuilder) Underline() *AttrBuilder
- type CharSetMode
- type VT220
- func (vt *VT220) Attr() *AttrBuilder
- func (vt *VT220) Bprint(a ...any) []byte
- func (vt *VT220) Bprintf(format string, a ...any) []byte
- func (vt *VT220) Bprintln(a ...any) []byte
- func (vt *VT220) Designate(reg control.RegisterIndex, set *repertoire.GraphicSet) error
- func (vt *VT220) DesignateByName(reg control.RegisterIndex, name string) error
- func (vt *VT220) DynamicGraphicSet() bool
- func (vt *VT220) GLCodepage() *charmap.DynamicCodepage
- func (vt *VT220) GLGraphicSet() *repertoire.GraphicSet
- func (vt *VT220) GLRegister() control.RegisterIndex
- func (vt *VT220) GRCodepage() *charmap.DynamicCodepage
- func (vt *VT220) GRGraphicSet() *repertoire.GraphicSet
- func (vt *VT220) GRRegister() control.RegisterIndex
- func (vt *VT220) Init() error
- func (vt *VT220) LockShiftGL(reg control.RegisterIndex) error
- func (vt *VT220) LockShiftGR(reg control.RegisterIndex) error
- func (vt *VT220) Mode() CharSetMode
- func (vt *VT220) Print(s string) (n int, err error)
- func (vt *VT220) Printf(format string, a ...any) (n int, err error)
- func (vt *VT220) Println(a ...any) (n int, err error)
- func (vt *VT220) Register(reg control.RegisterIndex) *repertoire.GraphicSet
- func (vt *VT220) Reset(clearScreen bool) error
- func (vt *VT220) SendSequence(seq control.Sequence) error
- func (vt *VT220) SetDynamicGraphicSet(enabled bool)
- func (vt *VT220) SetMode(mode CharSetMode)
- func (vt *VT220) SetModeWithSequence(mode CharSetMode) error
- func (vt *VT220) SingleShift(reg control.RegisterIndex, b byte) error
- func (vt *VT220) SingleShiftG2(b byte) error
- func (vt *VT220) SingleShiftG3(b byte) error
- func (vt *VT220) Sprint(a ...any) string
- func (vt *VT220) Sprintf(format string, a ...any) string
- func (vt *VT220) Sprintln(a ...any) string
- func (vt *VT220) UnderlyingWriter() io.Writer
- func (vt *VT220) Write(p []byte) (n int, err error)
- func (vt *VT220) WriteRaw(p []byte) (int, error)
- func (vt *VT220) Writer() io.Writer
- type VTConfig
Constants ¶
This section is empty.
Variables ¶
var ( // ErrInvalidRegister is returned when an invalid register index is specified. ErrInvalidRegister = errors.New("invalid register index") // ErrNilGraphicSet is returned when attempting to designate a nil graphic set. ErrNilGraphicSet = errors.New("graphic set is nil") // ErrUnknownGraphicSet is returned when a graphic set name is not found // in the repertoire. ErrUnknownGraphicSet = errors.New("graphic set not found in repertoire") // ErrNRCInMultinational is returned when attempting to designate an NRC // (National Replacement Character) set while in multinational mode. // NRC sets require 7-bit national mode and cannot be used in 8-bit // multinational mode. ErrNRCInMultinational = errors.New("NRC sets cannot be used in multinational mode") )
Functions ¶
This section is empty.
Types ¶
type AttrBuilder ¶
type AttrBuilder struct {
// contains filtered or unexported fields
}
AttrBuilder provides a fluent interface for building attributed strings. Use VT220.Attr() to create an AttrBuilder, chain attribute methods, then call Print/Printf/Println for direct output or Bprint/Bprintf/Bprintln for composed output.
func (*AttrBuilder) Blink ¶
func (a *AttrBuilder) Blink() *AttrBuilder
Blink enables the blink attribute.
func (*AttrBuilder) Bold ¶
func (a *AttrBuilder) Bold() *AttrBuilder
Bold enables the bold attribute.
func (*AttrBuilder) Bprint ¶
func (a *AttrBuilder) Bprint(args ...any) []byte
Bprint formats using the default formats for its operands and returns the resulting byte slice with SGR attribute sequences. Spaces are added between operands when neither is a string.
func (*AttrBuilder) Bprintf ¶
func (a *AttrBuilder) Bprintf(format string, args ...any) []byte
Bprintf formats according to a format specifier and returns the resulting byte slice with SGR attribute sequences.
func (*AttrBuilder) Bprintln ¶
func (a *AttrBuilder) Bprintln(args ...any) []byte
Bprintln formats using the default formats for its operands and returns the resulting byte slice with SGR attribute sequences. Spaces are always added between operands and a newline is appended.
func (*AttrBuilder) Negative ¶
func (a *AttrBuilder) Negative() *AttrBuilder
Negative enables the negative/reverse video attribute.
func (*AttrBuilder) Print ¶
func (a *AttrBuilder) Print(args ...any) (int, error)
Print formats using the default formats for its operands and writes the attributed string to the terminal.
func (*AttrBuilder) Printf ¶
func (a *AttrBuilder) Printf(format string, args ...any) (int, error)
Printf formats according to a format specifier and writes the attributed string to the terminal.
func (*AttrBuilder) Println ¶
func (a *AttrBuilder) Println(args ...any) (int, error)
Println formats using the default formats for its operands and writes the attributed string to the terminal. Spaces are always added between operands and a newline is appended.
func (*AttrBuilder) Underline ¶
func (a *AttrBuilder) Underline() *AttrBuilder
Underline enables the underline attribute.
type CharSetMode ¶
type CharSetMode int
CharSetMode represents the terminal's character set operating mode.
const ( // Multinational is 8-bit DEC Multinational Character Set mode. // This is the default mode and supports the full 8-bit character range. // NRC (National Replacement Character) sets cannot be used in this mode. Multinational CharSetMode = iota // National is 7-bit National Replacement Character mode. // This mode is required for NRC sets but is incompatible with 8-bit // multinational keyboards and character sets. National )
func (CharSetMode) String ¶
func (m CharSetMode) String() string
String returns a human-readable name for the character set mode.
type VT220 ¶
type VT220 struct {
// contains filtered or unexported fields
}
VT220 represents a VT220 terminal's character set state. It manages four graphic registers (G0-G3) and tracks which registers are currently invoked into GL (left, 7-bit) and GR (right, 8-bit).
func New ¶
New creates a new VT220 terminal manager with the given output writer. It initializes with the standard VT220 defaults:
- G0: ASCII (invoked into GL)
- G1: DEC Supplemental (invoked into GR)
- G2: DEC Special Graphics
- G3: DEC Special Graphics
- Mode: Multinational
- Equivalence encoding: disabled
func NewWithConfig ¶
NewWithConfig creates a new VT220 terminal manager with the given output writer and configuration options. It initializes with the standard VT220 defaults for registers:
- G0: ASCII (invoked into GL)
- G1: DEC Supplemental (invoked into GR)
- G2: DEC Special Graphics
- G3: DEC Special Graphics
func (*VT220) Attr ¶
func (vt *VT220) Attr() *AttrBuilder
Attr returns a new AttrBuilder for constructing attributed strings.
func (*VT220) Bprint ¶
Bprint formats using the default formats for its operands and returns the resulting byte slice. Spaces are added between operands when neither is a string.
func (*VT220) Bprintf ¶
Bprintf formats according to a format specifier and returns the resulting byte slice.
func (*VT220) Bprintln ¶
Bprintln formats using the default formats for its operands and returns the resulting byte slice. Spaces are always added between operands and a newline is appended.
func (*VT220) Designate ¶
func (vt *VT220) Designate(reg control.RegisterIndex, set *repertoire.GraphicSet) error
Designate designates a graphic set to a register and sends the appropriate SCS (Select Character Set) escape sequence to the terminal. The set must be in the terminal's repertoire. Returns ErrNRCInMultinational if attempting to designate an NRC set while in multinational mode.
func (*VT220) DesignateByName ¶
func (vt *VT220) DesignateByName(reg control.RegisterIndex, name string) error
DesignateByName designates a graphic set by name from the repertoire.
func (*VT220) DynamicGraphicSet ¶
DynamicGraphicSet returns whether dynamic graphic set selection is enabled.
func (*VT220) GLCodepage ¶
func (vt *VT220) GLCodepage() *charmap.DynamicCodepage
GLCodepage returns the DynamicCodepage currently active for GL.
func (*VT220) GLGraphicSet ¶
func (vt *VT220) GLGraphicSet() *repertoire.GraphicSet
GLGraphicSet returns the GraphicSet currently invoked into GL, or nil if none.
func (*VT220) GLRegister ¶
func (vt *VT220) GLRegister() control.RegisterIndex
GLRegister returns the index of the register currently invoked into GL.
func (*VT220) GRCodepage ¶
func (vt *VT220) GRCodepage() *charmap.DynamicCodepage
GRCodepage returns the DynamicCodepage currently active for GR.
func (*VT220) GRGraphicSet ¶
func (vt *VT220) GRGraphicSet() *repertoire.GraphicSet
GRGraphicSet returns the GraphicSet currently invoked into GR, or nil if none.
func (*VT220) GRRegister ¶
func (vt *VT220) GRRegister() control.RegisterIndex
GRRegister returns the index of the register currently invoked into GR.
func (*VT220) Init ¶
Init sends the initialization sequences to configure the terminal with the current register designations and shift state.
func (*VT220) LockShiftGL ¶
func (vt *VT220) LockShiftGL(reg control.RegisterIndex) error
LockShiftGL invokes the specified register into GL (left side, 7-bit codes). This sends the appropriate lock shift sequence (LS0, LS1, LS2, or LS3).
func (*VT220) LockShiftGR ¶
func (vt *VT220) LockShiftGR(reg control.RegisterIndex) error
LockShiftGR invokes the specified register into GR (right side, 8-bit codes). This sends the appropriate lock shift sequence (LS1R, LS2R, or LS3R). G0 cannot be invoked into GR.
func (*VT220) Mode ¶
func (vt *VT220) Mode() CharSetMode
Mode returns the current character set operating mode.
func (*VT220) Print ¶
Print writes a string to the terminal, encoding it to the current character set.
func (*VT220) Printf ¶
Printf formats according to a format specifier and writes to the terminal, encoding the result to the current character set.
func (*VT220) Println ¶
Println formats using the default formats for its operands and writes to standard output. Spaces are always added between operands and a newline is appended. It returns the number of bytes written and any write error encountered.
func (*VT220) Register ¶
func (vt *VT220) Register(reg control.RegisterIndex) *repertoire.GraphicSet
Register returns the graphic set currently designated to the given register, or nil if the register is empty.
func (*VT220) Reset ¶
Reset performs a soft terminal reset, reinitializing the VT220 to its default state. This sends DECSTR to the terminal and resets the internal register state to defaults:
- G0: ASCII (invoked into GL)
- G1: DEC Supplemental (invoked into GR)
- G2: DEC Special Graphics
- G3: DEC Special Graphics
If clearScreen is true, the screen is also cleared after the reset.
func (*VT220) SendSequence ¶
SendSequence writes a control sequence to the terminal output.
func (*VT220) SetDynamicGraphicSet ¶
SetDynamicGraphicSet enables or disables dynamic graphic set selection. When enabled, the encoder will check other registers (G2, G3) and use single shifts (SS2, SS3) to output characters that cannot be encoded by the current GL/GR character sets.
func (*VT220) SetMode ¶
func (vt *VT220) SetMode(mode CharSetMode)
SetMode sets the character set operating mode. Note: This only updates the internal state. Use SetModeWithSequence to also send the appropriate DECNRCM control sequence to the terminal.
func (*VT220) SetModeWithSequence ¶
func (vt *VT220) SetModeWithSequence(mode CharSetMode) error
SetModeWithSequence sets the character set operating mode and sends the appropriate DECNRCM control sequence to the terminal.
func (*VT220) SingleShift ¶
func (vt *VT220) SingleShift(reg control.RegisterIndex, b byte) error
SingleShift writes a byte using the character set in the specified register via single shift. Only G2 and G3 support single shifts. Returns ErrInvalidRegister for G0 or G1.
func (*VT220) SingleShiftG2 ¶
SingleShiftG2 writes a byte using the character set in G2 via single shift. The SS2 control is sent followed by the byte, causing the terminal to display the character from G2, then revert to the normal GL mapping.
func (*VT220) SingleShiftG3 ¶
SingleShiftG3 writes a byte using the character set in G3 via single shift. The SS3 control is sent followed by the byte, causing the terminal to display the character from G3, then revert to the normal GL mapping.
func (*VT220) Sprint ¶
Sprint formats using the default formats for its operands and returns the resulting byte slice. Spaces are added between operands when neither is a string.
func (*VT220) Sprintf ¶
Sprintf formats according to a format specifier and returns the resulting string.
func (*VT220) Sprintln ¶
Sprintln formats using the default formats for its operands and returns the resulting string. Spaces are always added between operands and a newline is appended.
func (*VT220) UnderlyingWriter ¶
UnderlyingWriter returns the underlying output writer.
func (*VT220) Write ¶
Write encodes UTF-8 text to the terminal's current character encoding and writes it to the output. This makes VT220 implement io.Writer.
func (*VT220) WriteRaw ¶
WriteRaw writes bytes directly to the terminal without encoding. Use this for pre-encoded content like attributed strings from AttrBuilder.
type VTConfig ¶
type VTConfig struct {
// Mode specifies the character set operating mode.
// Multinational (default) supports 8-bit character sets.
// National mode is required for NRC sets but is 7-bit only.
Mode CharSetMode
// UseEquivalence enables equivalence encoding, which maps visually
// similar characters to their canonical forms during encoding.
UseEquivalence bool
// DynamicGraphicSet enables dynamic character set selection during encoding.
// When a rune cannot be encoded by the current GL/GR character sets,
// the encoder will check other registers (G2, G3) and use single shifts
// (SS2, SS3) to output characters from those sets.
DynamicGraphicSet bool
}
VTConfig holds configuration options for creating a VT220 terminal manager.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package control provides control sequence types and builders for VT220 terminals.
|
Package control provides control sequence types and builders for VT220 terminals. |
|
Package repertoire provides the graphics repertoire for VT220 terminals.
|
Package repertoire provides the graphics repertoire for VT220 terminals. |