Documentation ¶
Overview ¶
package midterm implements an in-memory terminal emulator, designed to be used as a component within a larger application for displaying logs, running interactive shells, or rendering terminal output.
Index ¶
- type Command
- type Cursor
- type Format
- type Intensity
- type OnResizeFunc
- type Screen
- type ScrollRegion
- type Terminal
- func (v *Terminal) HTML() string
- func (v *Terminal) OnResize(f OnResizeFunc)
- func (v *Terminal) Process(c Command) error
- func (vt *Terminal) Render(w io.Writer) error
- func (vt *Terminal) RenderLine(w io.Writer, row int) error
- func (v *Terminal) Reset()
- func (v *Terminal) Resize(rows, cols int)
- func (v *Terminal) ResizeX(cols int)
- func (v *Terminal) ResizeY(rows int)
- func (v *Terminal) UsedHeight() int
- func (v *Terminal) Write(dt []byte) (n int, rerr error)
- type UnsupportedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Command ¶
type Command interface {
// contains filtered or unexported methods
}
Command is a type of object that the terminal can process to perform an update.
func Decode ¶
func Decode(s io.RuneScanner) (Command, []rune, error)
Decode decodes one ANSI terminal command from s.
s should be connected to a client program that expects an ANSI terminal on the other end. It will push bytes to us that we are meant to intepret as terminal control codes, or text to place onto the terminal.
This Command alone does not actually update the terminal. You need to pass it to VT100.Process().
You should not share s with any other reader, because it could leave the stream in an invalid state.
type Cursor ¶
type Cursor struct {
// Y and X are the coordinates.
Y, X int
// F is the format that will be displayed.
F Format
}
Cursor represents both the position and text type of the cursor.
type Format ¶
type Format struct { // Reset inidcates that the format should be reset prior to applying any of // the other fields. Reset bool // Fg is the foreground color. Fg termenv.Color // Bg is the background color. Bg termenv.Color // Intensity is the text intensity (bright, normal, dim). Intensity Intensity // Various text properties. Italic, Underline, Blink, Reverse, Conceal, CrossOut, Overline bool }
Format represents the display format of text on a terminal.
type OnResizeFunc ¶
type OnResizeFunc func(rows, cols int)
type Screen ¶ added in v0.1.4
type Screen struct {
// Height and Width are the dimensions of the terminal.
Height, Width int
// Content is the text in the terminal.
Content [][]rune
// Format is the display properties of each cell.
Format [][]Format
// Cursor is the current state of the cursor.
Cursor Cursor
// ScrollRegion is the region of the terminal that is scrollable. If it is
// nil, the entire terminal is scrollable.
//
// This value is set by the CSI ; Ps ; Ps r command.
ScrollRegion *ScrollRegion
// CursorVisible indicates whether the cursor is visible.
//
// This value is set by CSI ? 25 h and unset by CSI ? 25 l.
CursorVisible bool
// CursorBlinking indicates whether the cursor is blinking, and the start of
// the blinking interval.
CursorBlinkEpoch *time.Time
// SavedCursor is the state of the cursor last time save() was called.
SavedCursor Cursor
// MaxY is the maximum vertical offset that a character has been printed.
MaxY int
}
type ScrollRegion ¶
type ScrollRegion struct {
Start, End int
}
ScrollRegion represents a region of the terminal that is scrollable.
type Terminal ¶
type Terminal struct { // Screen is the current screen, embedded so that Terminal is a pass-through. *Screen // Alt is either the alternate screen (if !IsAlt) or the main screen (if // IsAlt). Alt *Screen // IsAlt indicates whether the alt screen is active. IsAlt bool // AutoResizeY indicates whether the terminal should automatically resize // when the content exceeds its maximum height. AutoResizeY bool // AutoResizeX indicates whether the terminal should automatically resize // when the content exceeds its maximum width. AutoResizeX bool // ForwardRequests is the writer to which we send requests to forward // to the terminal. ForwardRequests io.Writer // ForwardResponses is the writer to which we send responses to CSI/OSC queries. ForwardResponses io.Writer // contains filtered or unexported fields }
Terminal represents a raw terminal capable of handling VT100 and VT102 ANSI escape sequences, some of which are handled by forwarding them to a local or remote session (e.g. OSC52 copy/paste).
func NewAutoResizingTerminal ¶ added in v0.1.1
func NewAutoResizingTerminal() *Terminal
NewAutoResizingTerminal creates a new Terminal object with small initial dimensions, configured to automatically resize width and height as needed.
This may be useful for applications that want to display dynamically sized content.
func NewTerminal ¶
NewTerminal creates a new Terminal object with the specified dimensions. y and x must both be greater than zero.
Each cell is set to contain a ' ' rune, and all formats are left as the default.
func (*Terminal) HTML ¶
HTML renders v as an HTML fragment. One idea for how to use this is to debug the current state of the screen reader.
func (*Terminal) OnResize ¶
func (v *Terminal) OnResize(f OnResizeFunc)
func (*Terminal) Process ¶
Process handles a single ANSI terminal command, updating the terminal appropriately.
One special kind of error that this can return is an UnsupportedError. It's probably best to check for these and skip, because they are likely recoverable.
func (*Terminal) Resize ¶
Resize sets the terminal height and width to rows and cols and disables auto-resizing on both axes.
func (*Terminal) ResizeX ¶ added in v0.1.3
Resize sets the terminal width to cols and disables auto-resizing width.
func (*Terminal) ResizeY ¶ added in v0.1.3
Resize sets the terminal height to rows rows and disables auto-resizing height.
func (*Terminal) UsedHeight ¶
type UnsupportedError ¶
type UnsupportedError struct {
// contains filtered or unexported fields
}
UnsupportedError indicates that we parsed an operation that this terminal does not implement. Such errors indicate that the client program asked us to perform an action that we don't know how to. It MAY be safe to continue trying to do additional operations. This is a distinct category of errors from things we do know how to do, but are badly encoded, or errors from the underlying io.RuneScanner that we're reading commands from.