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 ¶
- Constants
- Variables
- func DebugLogsTo(w io.Writer)
- type Canvas
- func (canvas *Canvas) Delete(row, col, n int)
- func (canvas *Canvas) Height() int
- func (canvas *Canvas) Insert(row, col int, f Format, n int)
- func (canvas *Canvas) Paint(row, col int, format Format)
- func (canvas *Canvas) Regions(row int) iter.Seq[*Region]
- func (canvas *Canvas) Resize(h, w int)
- func (canvas *Canvas) ResizeX(w int)
- func (canvas *Canvas) ResizeY(h int)
- type Cursor
- type Format
- func (f *Format) IsBlink() bool
- func (f *Format) IsBold() bool
- func (f *Format) IsConceal() bool
- func (f *Format) IsFaint() bool
- func (f *Format) IsItalic() bool
- func (f *Format) IsReset() bool
- func (f *Format) IsReverse() bool
- func (f *Format) IsUnderline() bool
- func (f Format) MarshalBinary() (data []byte, err error)
- func (f Format) Render() string
- func (f Format) RenderFgBg(fg, bg termenv.Color) string
- func (f *Format) SetBlink(value bool)
- func (f *Format) SetBold(value bool)
- func (f *Format) SetConceal(value bool)
- func (f *Format) SetFaint(value bool)
- func (f *Format) SetItalic(value bool)
- func (f *Format) SetReset(value bool)
- func (f *Format) SetReverse(value bool)
- func (f *Format) SetUnderline(value bool)
- type Line
- type OnResizeFunc
- type OnScrollbackFunc
- type Region
- type Screen
- type ScrollRegion
- type Terminal
- func (v *Terminal) Backspace()
- func (v *Terminal) Bell()
- func (v *Terminal) CarriageReturn()
- func (v *Terminal) ClearLine(mode ansicode.LineClearMode)
- func (v *Terminal) ClearScreen(mode ansicode.ClearMode)
- func (v *Terminal) ClearTabs(mode ansicode.TabulationClearMode)
- func (v *Terminal) ClipboardLoad(clipboard byte, terminator string)
- func (v *Terminal) ClipboardStore(clipboard byte, data []byte)
- func (v *Terminal) ConfigureCharset(index ansicode.CharsetIndex, charset ansicode.Charset)
- func (v *Terminal) Decaln()
- func (v *Terminal) DeleteChars(n int)
- func (v *Terminal) DeleteLines(n int)
- func (v *Terminal) DeviceStatus(n int)
- func (v *Terminal) EraseChars(n int)
- func (v *Terminal) Goto(y int, x int)
- func (v *Terminal) GotoCol(n int)
- func (v *Terminal) GotoLine(n int)
- func (v *Terminal) HTML() string
- func (v *Terminal) HorizontalTabSet()
- func (v *Terminal) IdentifyTerminal(b byte)
- func (v *Terminal) Input(r rune)
- func (v *Terminal) InsertBlank(n int)
- func (v *Terminal) InsertBlankLines(n int)
- func (v *Terminal) LineFeed()
- func (vt *Terminal) MarshalBinary() (data []byte, err error)
- func (v *Terminal) MoveBackward(n int)
- func (v *Terminal) MoveBackwardTabs(n int)
- func (v *Terminal) MoveDown(n int)
- func (v *Terminal) MoveDownCr(n int)
- func (v *Terminal) MoveForward(n int)
- func (v *Terminal) MoveForwardTabs(n int)
- func (v *Terminal) MoveUp(n int)
- func (v *Terminal) MoveUpCr(n int)
- func (v *Terminal) OnResize(f OnResizeFunc)
- func (v *Terminal) OnScrollback(f OnScrollbackFunc)
- func (v *Terminal) PopKeyboardMode(n int)
- func (v *Terminal) PopTitle()
- func (v *Terminal) PushKeyboardMode(mode ansicode.KeyboardMode)
- func (v *Terminal) PushTitle()
- func (vt *Terminal) Render(w io.Writer) error
- func (vt *Terminal) RenderFgBg(w io.Writer, fg, bg termenv.Color) error
- func (vt *Terminal) RenderLine(w io.Writer, row int) error
- func (vt *Terminal) RenderLineFgBg(w io.Writer, row int, fg, bg termenv.Color) error
- func (v *Terminal) ReportKeyboardMode()
- func (v *Terminal) ReportModifyOtherKeys()
- func (v *Terminal) Reset()
- func (v *Terminal) ResetColor(i int)
- func (v *Terminal) ResetState()
- func (v *Terminal) Resize(rows, cols int)
- func (v *Terminal) ResizeX(cols int)
- func (v *Terminal) ResizeY(rows int)
- func (v *Terminal) RestoreCursorPosition()
- func (v *Terminal) ReverseIndex()
- func (v *Terminal) SaveCursorPosition()
- func (v *Terminal) ScrollDown(n int)
- func (v *Terminal) ScrollUp(n int)
- func (v *Terminal) SetActiveCharset(n int)
- func (v *Terminal) SetColor(index int, color color.Color)
- func (v *Terminal) SetCursorStyle(style ansicode.CursorStyle)
- func (v *Terminal) SetDynamicColor(prefix string, index int, terminator string)
- func (v *Terminal) SetHyperlink(hyperlink *ansicode.Hyperlink)
- func (v *Terminal) SetKeyboardMode(mode ansicode.KeyboardMode, behavior ansicode.KeyboardModeBehavior)
- func (v *Terminal) SetKeypadApplicationMode()
- func (v *Terminal) SetMode(mode ansicode.TerminalMode)
- func (v *Terminal) SetModifyOtherKeys(modify ansicode.ModifyOtherKeys)
- func (v *Terminal) SetScrollingRegion(top int, bottom int)
- func (v *Terminal) SetTerminalCharAttribute(attr ansicode.TerminalCharAttribute)
- func (v *Terminal) SetTitle(title string)
- func (v *Terminal) Substitute()
- func (v *Terminal) Tab(n int)
- func (v *Terminal) TextAreaSizeChars()
- func (v *Terminal) TextAreaSizePixels()
- func (v *Terminal) UnsetKeypadApplicationMode()
- func (v *Terminal) UnsetMode(mode ansicode.TerminalMode)
- func (v *Terminal) UsedHeight() int
- func (v *Terminal) UsedWidth() int
- func (v *Terminal) Write(p []byte) (int, error)
Constants ¶
const ( ResetBit uint8 = 1 << iota BoldBit FaintBit ItalicBit UnderlineBit BlinkBit ReverseBit ConcealBit )
Constants for property bit positions
Variables ¶
var EmptyFormat = Format{}
var Reset = Format{Properties: ResetBit}
var ReverseFormat = Format{Properties: ReverseBit}
Functions ¶
func DebugLogsTo ¶ added in v0.2.1
Types ¶
type Cursor ¶
type Cursor struct {
// Y and X are the coordinates.
Y, X int
// F is the format that will be displayed.
F Format
// S is the cursor style.
S ansicode.CursorStyle
}
Cursor represents both the position and text type of the cursor.
func (Cursor) MarshalBinary ¶ added in v0.2.1
type Format ¶
type Format struct {
// Fg and Bg are the foreground and background colors.
Fg, Bg termenv.Color
// Properties packed into a single byte.
Properties uint8
}
Format represents the text formatting options.
func (*Format) IsUnderline ¶ added in v0.2.0
func (Format) MarshalBinary ¶ added in v0.2.1
func (*Format) SetConceal ¶ added in v0.2.0
func (*Format) SetReverse ¶ added in v0.2.0
func (*Format) SetUnderline ¶ added in v0.2.0
type OnResizeFunc ¶
type OnResizeFunc func(rows, cols int)
type OnScrollbackFunc ¶ added in v0.2.0
type OnScrollbackFunc func(line Line)
type Region ¶ added in v0.2.1
type Region struct { // Format that applies to this region. F Format // Size is the number of characters to which the format applies. Size int // Next is the next region in the row. Next *Region }
Region represents a segment of a row with a specific format.
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 contains the display properties of each cell.
Format *Canvas
// Changes counts the number of times each row has been modified so that the
// UI can know which content needs to be redrawn.
//
// Note that this includes changes to the cursor position, in case the cursor
// is visible: if the cursor moves from row 0 to row 3, both rows will be
// incremented.
Changes []uint64
// 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
// MaxX is the maximum horizontal offset that a character has been printed.
MaxX 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 // The title of the terminal Title string // 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 that the terminal has no defined width - instead, // columns are dynamically allocated as text is printed, and not all rows // will be the same 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 // Enable "raw" mode. Line endings do not imply a carriage return. Raw bool // AppendOnly instructs the terminal to not respect sequences that might // cause output to be lost - for example, setting a scrolling region. AppendOnly bool *ansicode.Decoder // 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) Backspace ¶ added in v0.2.1
func (v *Terminal) Backspace()
Backspace moves the cursor one position to the left.
func (*Terminal) CarriageReturn ¶ added in v0.2.1
func (v *Terminal) CarriageReturn()
CarriageReturn moves the cursor to the beginning of the line.
func (*Terminal) ClearLine ¶ added in v0.2.1
func (v *Terminal) ClearLine(mode ansicode.LineClearMode)
ClearLine clears the line.
func (*Terminal) ClearScreen ¶ added in v0.2.1
func (v *Terminal) ClearScreen(mode ansicode.ClearMode)
ClearScreen clears the screen.
func (*Terminal) ClearTabs ¶ added in v0.2.1
func (v *Terminal) ClearTabs(mode ansicode.TabulationClearMode)
ClearTabs clears the tab stops.
func (*Terminal) ClipboardLoad ¶ added in v0.2.1
ClipboardLoad loads data from the clipboard.
func (*Terminal) ClipboardStore ¶ added in v0.2.1
ClipboardStore stores data in the clipboard.
func (*Terminal) ConfigureCharset ¶ added in v0.2.1
func (v *Terminal) ConfigureCharset(index ansicode.CharsetIndex, charset ansicode.Charset)
ConfigureCharset configures the charset.
func (*Terminal) Decaln ¶ added in v0.2.1
func (v *Terminal) Decaln()
Decaln runs the DECALN command.
func (*Terminal) DeleteChars ¶ added in v0.2.1
DeleteChars deletes n characters.
func (*Terminal) DeleteLines ¶ added in v0.2.1
DeleteLines deletes n lines.
func (*Terminal) DeviceStatus ¶ added in v0.2.1
DeviceStatus reports the device status.
func (*Terminal) EraseChars ¶ added in v0.2.1
EraseChars erases n characters.
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) HorizontalTabSet ¶ added in v0.2.1
func (v *Terminal) HorizontalTabSet()
HorizontalTab sets the current position as a tab stop.
func (*Terminal) IdentifyTerminal ¶ added in v0.2.1
IdentifyTerminal identifies the terminal.
func (*Terminal) InsertBlank ¶ added in v0.2.1
InsertBlank inserts n blank characters.
func (*Terminal) InsertBlankLines ¶ added in v0.2.1
InsertBlankLines inserts n blank lines.
func (*Terminal) LineFeed ¶ added in v0.2.1
func (v *Terminal) LineFeed()
LineFeed moves the cursor to the next line.
func (*Terminal) MarshalBinary ¶ added in v0.2.1
func (*Terminal) MoveBackward ¶ added in v0.2.1
MoveBackward moves the cursor backward n columns.
func (*Terminal) MoveBackwardTabs ¶ added in v0.2.1
MoveBackwardTabs moves the cursor backward n tab stops.
func (*Terminal) MoveDownCr ¶ added in v0.2.1
MoveDownCr moves the cursor down n lines and to the beginning of the line.
func (*Terminal) MoveForward ¶ added in v0.2.1
MoveForward moves the cursor forward n columns.
func (*Terminal) MoveForwardTabs ¶ added in v0.2.1
MoveForwardTabs moves the cursor forward n tab stops.
func (*Terminal) MoveUpCr ¶ added in v0.2.1
MoveUpCr moves the cursor up n lines and to the beginning of the line.
func (*Terminal) OnResize ¶
func (v *Terminal) OnResize(f OnResizeFunc)
OnResize sets a hook that is called every time the terminal resizes.
func (*Terminal) OnScrollback ¶ added in v0.2.0
func (v *Terminal) OnScrollback(f OnScrollbackFunc)
OnScrollback sets a hook that is called every time a line is about to be pushed out of the visible screen region.
func (*Terminal) PopKeyboardMode ¶ added in v0.2.1
PopKeyboardMode pops the given amount n of keyboard modes from the stack.
func (*Terminal) PopTitle ¶ added in v0.2.1
func (v *Terminal) PopTitle()
PopTitle pops the title from the stack.
func (*Terminal) PushKeyboardMode ¶ added in v0.2.1
func (v *Terminal) PushKeyboardMode(mode ansicode.KeyboardMode)
PushKeyboardMode pushes the given keyboard mode to the stack.
func (*Terminal) PushTitle ¶ added in v0.2.1
func (v *Terminal) PushTitle()
PushTitle pushes the given title to the stack.
func (*Terminal) RenderFgBg ¶ added in v0.2.1
func (*Terminal) RenderLineFgBg ¶ added in v0.2.1
func (*Terminal) ReportKeyboardMode ¶ added in v0.2.1
func (v *Terminal) ReportKeyboardMode()
ReportKeyboardMode reports the keyboard mode.
func (*Terminal) ReportModifyOtherKeys ¶ added in v0.2.1
func (v *Terminal) ReportModifyOtherKeys()
ReportModifyOtherKeys reports the modify other keys mode. (XTERM)
func (*Terminal) ResetColor ¶ added in v0.2.1
ResetColor resets the color at the given index.
func (*Terminal) ResetState ¶ added in v0.2.1
func (v *Terminal) ResetState()
ResetState resets the terminal state.
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) RestoreCursorPosition ¶ added in v0.2.1
func (v *Terminal) RestoreCursorPosition()
RestoreCursorPosition restores the cursor position.
func (*Terminal) ReverseIndex ¶ added in v0.2.1
func (v *Terminal) ReverseIndex()
ReverseIndex moves the active position to the same horizontal position on the preceding line.
func (*Terminal) SaveCursorPosition ¶ added in v0.2.1
func (v *Terminal) SaveCursorPosition()
SaveCursorPosition saves the cursor position.
func (*Terminal) ScrollDown ¶ added in v0.2.1
ScrollDown scrolls the screen down n lines.
func (*Terminal) SetActiveCharset ¶ added in v0.2.1
SetActiveCharset sets the active charset.
func (*Terminal) SetCursorStyle ¶ added in v0.2.1
func (v *Terminal) SetCursorStyle(style ansicode.CursorStyle)
SetCursorStyle sets the cursor style.
func (*Terminal) SetDynamicColor ¶ added in v0.2.1
SetDynamicColor sets the dynamic color at the given index.
func (*Terminal) SetHyperlink ¶ added in v0.2.1
func (v *Terminal) SetHyperlink(hyperlink *ansicode.Hyperlink)
SetHyperlink sets the hyperlink.
func (*Terminal) SetKeyboardMode ¶ added in v0.2.1
func (v *Terminal) SetKeyboardMode(mode ansicode.KeyboardMode, behavior ansicode.KeyboardModeBehavior)
SetKeyboardMode sets the keyboard mode.
func (*Terminal) SetKeypadApplicationMode ¶ added in v0.2.1
func (v *Terminal) SetKeypadApplicationMode()
SetKeypadApplicationMode sets keypad to applications mode.
func (*Terminal) SetMode ¶ added in v0.2.1
func (v *Terminal) SetMode(mode ansicode.TerminalMode)
SetMode sets the given mode.
func (*Terminal) SetModifyOtherKeys ¶ added in v0.2.1
func (v *Terminal) SetModifyOtherKeys(modify ansicode.ModifyOtherKeys)
SetModifyOtherKeys sets the modify other keys mode. (XTERM)
func (*Terminal) SetScrollingRegion ¶ added in v0.2.1
SetScrollingRegion sets the scrolling region.
func (*Terminal) SetTerminalCharAttribute ¶ added in v0.2.1
func (v *Terminal) SetTerminalCharAttribute(attr ansicode.TerminalCharAttribute)
SetTerminalCharAttribute sets the terminal char attribute.
func (*Terminal) Substitute ¶ added in v0.2.1
func (v *Terminal) Substitute()
Substitute replaces the character under the cursor.
func (*Terminal) TextAreaSizeChars ¶ added in v0.2.1
func (v *Terminal) TextAreaSizeChars()
TextAreaSizeChars reports the text area size in characters.
func (*Terminal) TextAreaSizePixels ¶ added in v0.2.1
func (v *Terminal) TextAreaSizePixels()
TextAreaSizePixels reports the text area size in pixels.
func (*Terminal) UnsetKeypadApplicationMode ¶ added in v0.2.1
func (v *Terminal) UnsetKeypadApplicationMode()
UnsetKeypadApplicationMode sets the keypad to numeric mode.
func (*Terminal) UnsetMode ¶ added in v0.2.1
func (v *Terminal) UnsetMode(mode ansicode.TerminalMode)
UnsetMode unsets the given mode.