Documentation ¶
Overview ¶
Package terminal provides a widget that functions as a unix terminal. Like urwid, it emulates a vt220 (roughly). Mouse support is provided. See the terminal demo for more.
Index ¶
- Constants
- func PtyStart1(c *exec.Cmd) (pty2, tty *os.File, err error)
- func TCellEventToBytes(ev interface{}, mouse IMouseSupport, last gowid.MouseState, paster IPaste, ...) ([]byte, bool)
- func UserInput(w IWidget, ev interface{}, size gowid.IRenderSize, focus gowid.Selector, ...) bool
- type AliasCSICommand
- type Bell
- type CSIFunction
- type CSIMap
- type Canvas
- func (c *Canvas) CSIClearTabstop(mode int)
- func (c *Canvas) CSIEraseDisplay(mode int)
- func (c *Canvas) CSIEraseLine(mode int)
- func (c *Canvas) CSIGetDeviceAttributes(qmark bool)
- func (c *Canvas) CSISetAttr(args []int)
- func (c *Canvas) CSISetKeyboardLEDs(mode int)
- func (c *Canvas) CSISetModes(args []int, qmark bool, reset bool)
- func (c *Canvas) CSISetScroll(top, bottom int)
- func (c *Canvas) CSIStatusReport(mode int)
- func (c *Canvas) CarriageReturn()
- func (c *Canvas) Clear(newcx, newcy gwutil.IntOption)
- func (c *Canvas) ConstrainCoords(x, y int, ignoreScrolling bool) (int, int)
- func (c *Canvas) DECAln()
- func (c *Canvas) Duplicate() gowid.ICanvas
- func (c *Canvas) Erase(startx, starty, endx, endy int)
- func (c *Canvas) InitTabstops(extend bool)
- func (c *Canvas) InsertChars(startx, starty gwutil.IntOption, chars int, charo gwutil.RuneOption)
- func (c *Canvas) InsertLines(atCursor bool, lines int)
- func (c *Canvas) IsScrollRegionSet() bool
- func (c *Canvas) IsTabstop(x int) bool
- func (c *Canvas) LeaveEscapeResetState()
- func (c *Canvas) LineFeed(reverse bool)
- func (c *Canvas) MakeCellFrom(r rune) gowid.Cell
- func (c *Canvas) MoveCursor(x, y int, relative bool, relativeX bool, relativeY bool)
- func (c *Canvas) NewLine()
- func (c *Canvas) ParseCSI(r byte)
- func (c *Canvas) ParseEscape(r byte)
- func (c *Canvas) ParseNonCSI(r byte, mod byte)
- func (c *Canvas) ParseOSC(osc []byte)
- func (c *Canvas) ProcessByte(b byte)
- func (c *Canvas) ProcessByteOrCommand(r rune)
- func (c *Canvas) PushCursor(r rune)
- func (c *Canvas) PushRune(r rune, x, y int)
- func (c *Canvas) RemoveChars(startx, starty gwutil.IntOption, chars int)
- func (c *Canvas) RemoveLines(atCursor bool, lines int)
- func (c *Canvas) Reset()
- func (c *Canvas) ResetScroll()
- func (c *Canvas) Resize(width, height int)
- func (c *Canvas) RestoreCursor(withAttrs bool)
- func (c *Canvas) ReverseVideo(undo bool)
- func (c *Canvas) SGIToAttribs(args []int, fg, bg gwutil.IntOption, styles map[string]bool) (gwutil.IntOption, gwutil.IntOption, map[string]bool)
- func (c *Canvas) SaveCursor(withAttrs bool)
- func (c *Canvas) Scroll(dir ScrollDir)
- func (c *Canvas) ScrollBuffer(dir ScrollDir, reset bool, linesOpt gwutil.IntOption) int
- func (c *Canvas) SetG01(r byte, mod byte)
- func (c *Canvas) SetMode(mode int, flag bool, qmark bool, reset bool)
- func (c *Canvas) SetRune(r rune)
- func (c *Canvas) SetRuneAt(x, y int, r rune)
- func (c *Canvas) SetTabstop(x2 gwutil.IntOption, remove bool, clear bool)
- func (c *Canvas) SetTermCursor(x2, y2 gwutil.IntOption)
- func (c *Canvas) Tab(tabstop int)
- func (c *Canvas) TermCursor() (x, y int)
- func (c *Canvas) UseAlternateScreen()
- func (c *Canvas) UseOriginalScreen()
- func (c *Canvas) Write(p []byte) (n int, err error)
- type Charset
- type EventNotSupported
- type HotKey
- type HotKeyCB
- type HotKeyDuration
- type HotKeyInputFn
- type ICSICommand
- type IHotKeyFunctions
- type IHotKeyPersistence
- type IHotKeyProvider
- type IMouseSupport
- type IPaste
- type IScrollbar
- type ITerminal
- type IWidget
- type LEDSState
- type LEDs
- type Modes
- type Options
- type ProcessExited
- type RegularCSICommand
- type ScrollDir
- type StartCommandError
- type Title
- type ViewPortCanvas
- func (v *ViewPortCanvas) BoxRows() int
- func (v *ViewPortCanvas) CellAt(col, row int) gowid.Cell
- func (c *ViewPortCanvas) Duplicate() gowid.ICanvas
- func (v *ViewPortCanvas) Line(y int, cp gowid.LineCopy) gowid.LineResult
- func (c *ViewPortCanvas) MergeUnder(c2 gowid.IMergeCanvas, leftOffset, topOffset int, bottomGetsCursor bool)
- func (v *ViewPortCanvas) SetCellAt(col, row int, c gowid.Cell)
- func (v *ViewPortCanvas) SetLineAt(row int, line []gowid.Cell)
- func (c *ViewPortCanvas) String() string
- type Widget
- func (w *Widget) Bell(app gowid.IApp)
- func (w *Widget) Canvas() *Canvas
- func (w *Widget) Connected() bool
- func (w *Widget) DisableScrollbar(app gowid.IApp)
- func (w *Widget) EnableScrollbar(app gowid.IApp)
- func (w *Widget) GetLEDs() LEDSState
- func (w *Widget) GetTitle() string
- func (w *Widget) Height() int
- func (w *Widget) HotKeyActive() bool
- func (w *Widget) HotKeyDownTime() time.Time
- func (w *Widget) HotKeyFunctions() []HotKeyInputFn
- func (w *Widget) Modes() *Modes
- func (w *Widget) OnBell(f gowid.IWidgetChangedCallback)
- func (w *Widget) OnHotKey(f gowid.IWidgetChangedCallback)
- func (w *Widget) OnProcessExited(f gowid.IWidgetChangedCallback)
- func (w *Widget) OnSetTitle(f gowid.IWidgetChangedCallback)
- func (w *Widget) PasteState(b ...bool) bool
- func (w *Widget) RemoveOnBell(f gowid.IIdentity)
- func (w *Widget) RemoveOnHotKey(f gowid.IIdentity)
- func (w *Widget) RemoveOnProcessExited(f gowid.IIdentity)
- func (w *Widget) RemoveOnSetTitle(f gowid.IIdentity)
- func (w *Widget) Render(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.ICanvas
- func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
- func (w *Widget) RequestTerminate() error
- func (w *Widget) ResetScroll()
- func (w *Widget) Scroll(dir ScrollDir, page bool, lines int)
- func (w *Widget) ScrollbarEnabled() bool
- func (w *Widget) Scrolling() bool
- func (w *Widget) SetCanvas(app gowid.IApp, c *Canvas)
- func (w *Widget) SetHotKeyActive(app gowid.IApp, down bool)
- func (w *Widget) SetLEDs(app gowid.IApp, mode LEDSState)
- func (w *Widget) SetTerminalSize(width, height int) error
- func (w *Widget) SetTitle(title string, app gowid.IApp)
- func (w *Widget) Signal(sig syscall.Signal) error
- func (w *Widget) StartCommand(app gowid.IApp, width, height int) error
- func (w *Widget) StopCommand()
- func (w *Widget) String() string
- func (w *Widget) Terminfo() *terminfo.Terminfo
- func (w *Widget) TouchTerminal(width, height int, app gowid.IApp)
- func (w *Widget) UserInput(ev interface{}, size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) bool
- func (w *Widget) Width() int
- func (w *Widget) Write(p []byte) (n int, err error)
Constants ¶
const ( CharsetDefault = iota CharsetUTF8 = iota )
const ( DecSpecialChars = "▮◆▒␉␌␍␊°±␋┘┐┌└┼⎺⎻─⎼⎽├┤┴┬│≤≥π≠£·" AltDecSpecialChars = "_`abcdefghijklmnopqrstuvwxyz{|}~" )
const (
EscByte byte = 27
)
Variables ¶
This section is empty.
Functions ¶
func PtyStart1 ¶
PtyStart1 connects the supplied Cmd's stdin/stdout/stderr to a new tty object. The function returns the pty and tty, and also an error which is nil if the operation was successful.
func TCellEventToBytes ¶
func TCellEventToBytes(ev interface{}, mouse IMouseSupport, last gowid.MouseState, paster IPaste, ti *terminfo.Terminfo) ([]byte, bool)
TCellEventToBytes converts TCell's representation of a terminal event to the string of bytes that would be the equivalent event according to the supplied Terminfo object. It returns a tuple of the byte slice representing the terminal event (if successful), and a bool (denoting success or failure). This function is used by the TerminalWidget. Its subprocess is connected to a tty controlled by gowid. Events from the user are parsed by gowid via TCell - they are then translated by this function before being written to the TerminalWidget subprocess's tty.
Types ¶
type AliasCSICommand ¶
type AliasCSICommand struct {
// contains filtered or unexported fields
}
func (AliasCSICommand) Alias ¶
func (c AliasCSICommand) Alias() byte
func (AliasCSICommand) FallbackArg ¶
func (c AliasCSICommand) FallbackArg() int
func (AliasCSICommand) IsAlias ¶
func (c AliasCSICommand) IsAlias() bool
func (AliasCSICommand) MinArgs ¶
func (c AliasCSICommand) MinArgs() int
type CSIFunction ¶
type CSIMap ¶
type CSIMap map[byte]ICSICommand
type Canvas ¶
type Canvas struct { *ViewPortCanvas gowid.ICallbacks // contains filtered or unexported fields }
Canvas implements gowid.ICanvas and stores the state of the terminal drawing area associated with a terminal (and TerminalWidget).
func NewCanvasOfSize ¶
func (*Canvas) CSIClearTabstop ¶
func (*Canvas) CSIEraseDisplay ¶
func (*Canvas) CSIEraseLine ¶
func (*Canvas) CSIGetDeviceAttributes ¶
Report as vt102, like vterm.py
func (*Canvas) CSISetAttr ¶
func (*Canvas) CSISetKeyboardLEDs ¶
func (*Canvas) CSISetScroll ¶
CSISetScroll sets the scrolling region in the current terminal. top is the line number of the first line, bottom the bottom line. If both are 0, the whole screen is used.
func (*Canvas) CSIStatusReport ¶
func (*Canvas) CarriageReturn ¶
func (c *Canvas) CarriageReturn()
func (*Canvas) ConstrainCoords ¶
func (*Canvas) InitTabstops ¶
func (*Canvas) InsertChars ¶
func (*Canvas) InsertLines ¶
InsertLines processes "CSI n L" e.g. "\033[5L". Lines are pushed down and blank lines inserted. Note that the 5 is only processed if a scroll region is defined - otherwise one line is inserted.
func (*Canvas) IsScrollRegionSet ¶
func (*Canvas) LeaveEscapeResetState ¶ added in v1.2.0
func (c *Canvas) LeaveEscapeResetState()
func (*Canvas) MoveCursor ¶
func (*Canvas) ParseEscape ¶
TODO am I always guaranteed to have something in escbuf?
func (*Canvas) ParseNonCSI ¶
func (*Canvas) ProcessByte ¶
func (*Canvas) ProcessByteOrCommand ¶
func (*Canvas) PushCursor ¶
func (*Canvas) RemoveChars ¶
func (*Canvas) RemoveLines ¶
func (*Canvas) ResetScroll ¶
func (c *Canvas) ResetScroll()
func (*Canvas) RestoreCursor ¶
func (*Canvas) ReverseVideo ¶
TODO urwid uses undo - implement it
func (*Canvas) SGIToAttribs ¶
func (*Canvas) SaveCursor ¶
func (*Canvas) ScrollBuffer ¶
ScrollBuffer will return the number of lines actually scrolled.
func (*Canvas) SetTabstop ¶
func (*Canvas) SetTermCursor ¶
func (*Canvas) TermCursor ¶
func (*Canvas) UseAlternateScreen ¶
func (c *Canvas) UseAlternateScreen()
func (*Canvas) UseOriginalScreen ¶
func (c *Canvas) UseOriginalScreen()
type Charset ¶
func NewTerminalCharset ¶
func NewTerminalCharset() *Charset
func (*Charset) ApplyMapping ¶
func (*Charset) ResetSgrIbmpc ¶
func (t *Charset) ResetSgrIbmpc()
func (*Charset) SetSgrIbmpc ¶
func (t *Charset) SetSgrIbmpc()
type EventNotSupported ¶
type EventNotSupported struct {
Event interface{}
}
func (EventNotSupported) Error ¶
func (e EventNotSupported) Error() string
type HotKeyDuration ¶
func (HotKeyDuration) HotKeyDuration ¶
func (t HotKeyDuration) HotKeyDuration() time.Duration
type HotKeyInputFn ¶ added in v1.4.0
type ICSICommand ¶
type IHotKeyFunctions ¶ added in v1.4.0
type IHotKeyFunctions interface { // Customized handling of hotkey sequences HotKeyFunctions() []HotKeyInputFn }
type IHotKeyPersistence ¶
type IHotKeyProvider ¶
type IMouseSupport ¶
type IScrollbar ¶ added in v1.4.0
type ITerminal ¶
type ITerminal interface { io.Writer Width() int Height() int Modes() *Modes Terminfo() *terminfo.Terminfo }
ITerminal is the interface required by terminal.Canvas. For example, when the pty sends a byte sequence, the canvas needs to pass it on to the terminal implementation - hence io.Writer.
type IWidget ¶
type IWidget interface { // All the usual widget requirements gowid.IWidget // Support terminal interfaces needed by terminal.Canvas ITerminal // IHotKeyProvider specifies the keypress that will "unfocus" the widget, that is that will // for a period of time ensure that the widget does not accept keypresses. This allows // the containing gowid application to change focus to another widget e.g. by hitting // the cursor key inside a pile or column widget. IHotKeyProvider // IHotKeyPersistence determines how long a press of the hotkey will be in effect before // keyboard user input is sent back to the underlying terminal. IHotKeyPersistence // IPaste tracks whether the paste start sequence has been seen wthout a matching // paste end sequence IPaste // HotKeyActive returns true if the hotkey is currently in effect. HotKeyActive() bool // SetHotKeyActive sets the state of HotKeyActive. SetHotKeyActive(app gowid.IApp, down bool) // HotKeyDownTime returns the time at which the hotkey was pressed. HotKeyDownTime() time.Time // Scroll the terminal's buffer. Scroll(dir ScrollDir, page bool, lines int) // Reset the the terminal's buffer scroll; display what was current. ResetScroll() // Currently scrolled away from normal view Scrolling() bool }
IWidget encapsulates the requirements of a gowid widget that can represent and interact with a terminal.
type Modes ¶
type Modes struct { DisplayCtrl bool Insert bool LfNl bool KeysAutoWrap bool ReverseVideo bool ConstrainScrolling bool DontAutoWrap bool InvisibleCursor bool Charset int VT200Mouse bool // #define SET_VT200_MOUSE 1000 ReportButton bool // #define SET_BTN_EVENT_MOUSE 1002 ReportAny bool // #define SET_ANY_EVENT_MOUSE 1003 SgrModeMouse bool // #define SET_SGR_EXT_MODE_MOUSE 1006 }
Modes is used to track the state of this terminal - which modes are enabled, etc. It tracks the mouse state in particular so implements IMouseSupport.
func (Modes) MouseEnabled ¶
func (Modes) MouseIsSgr ¶
func (Modes) MouseReportAny ¶
func (Modes) MouseReportButton ¶
type Options ¶
type Options struct { Command []string Env []string HotKey IHotKeyProvider HotKeyPersistence IHotKeyPersistence // the period of time a hotKey sticks after the first post-hotKey keypress Scrollback int Scrollbar bool // disabled regardless of setting if there is no scrollback HotKeyFns []HotKeyInputFn // allow custom behavior after pressing the hotkey EnableBracketedPaste bool KeyPressToEndScrollMode bool // set to true to enable legacy behavior - when the user has scrolled }
type ProcessExited ¶
type ProcessExited struct{}
type RegularCSICommand ¶
type RegularCSICommand struct {
// contains filtered or unexported fields
}
func (RegularCSICommand) Alias ¶
func (c RegularCSICommand) Alias() byte
func (RegularCSICommand) Call ¶
func (c RegularCSICommand) Call(canvas *Canvas, args []int, qmark bool)
func (RegularCSICommand) FallbackArg ¶
func (c RegularCSICommand) FallbackArg() int
func (RegularCSICommand) IsAlias ¶
func (c RegularCSICommand) IsAlias() bool
func (RegularCSICommand) MinArgs ¶
func (c RegularCSICommand) MinArgs() int
type StartCommandError ¶
func (StartCommandError) Cause ¶
func (e StartCommandError) Cause() error
func (StartCommandError) Error ¶
func (e StartCommandError) Error() string
func (StartCommandError) Unwrap ¶ added in v1.2.0
func (e StartCommandError) Unwrap() error
type ViewPortCanvas ¶
ViewPortCanvas implements ICanvas by embedding a Canvas pointer, but reimplementing Line and Cell access APIs relative to an Offset and a Height. The Height specifies the number of visible rows in the ViewPortCanvas; the rows that are not visible are logically "above" the visible rows. If Offset is reduced, the view of the underlying large Canvas is shifted up. This type is used by the terminal widget to hold the terminal's scrollback buffer.
func NewViewPort ¶
func NewViewPort(c *gowid.Canvas, offset, height int) *ViewPortCanvas
func (*ViewPortCanvas) BoxRows ¶
func (v *ViewPortCanvas) BoxRows() int
func (*ViewPortCanvas) Duplicate ¶ added in v1.3.0
func (c *ViewPortCanvas) Duplicate() gowid.ICanvas
func (*ViewPortCanvas) Line ¶
func (v *ViewPortCanvas) Line(y int, cp gowid.LineCopy) gowid.LineResult
func (*ViewPortCanvas) MergeUnder ¶ added in v1.3.0
func (c *ViewPortCanvas) MergeUnder(c2 gowid.IMergeCanvas, leftOffset, topOffset int, bottomGetsCursor bool)
func (*ViewPortCanvas) String ¶
func (c *ViewPortCanvas) String() string
type Widget ¶
type Widget struct { IHotKeyProvider IHotKeyPersistence Cmd *exec.Cmd Callbacks *gowid.Callbacks gowid.IsSelectable // contains filtered or unexported fields }
Widget is a widget that hosts a terminal-based application. The user provides the command to run, an optional environment in which to run it, and an optional hotKey. The hotKey is used to "escape" from the terminal (if using only the keyboard), and serves a similar role to the default ctrl-b in tmux. For example, to move focus to a widget to the right, the user could hit ctrl-b <right>. See examples/gowid-editor for a demo.
func (*Widget) DisableScrollbar ¶ added in v1.4.0
func (*Widget) EnableScrollbar ¶ added in v1.4.0
func (*Widget) HotKeyActive ¶
func (*Widget) HotKeyDownTime ¶
func (*Widget) HotKeyFunctions ¶ added in v1.4.0
func (w *Widget) HotKeyFunctions() []HotKeyInputFn
func (*Widget) OnBell ¶
func (w *Widget) OnBell(f gowid.IWidgetChangedCallback)
func (*Widget) OnHotKey ¶ added in v1.4.0
func (w *Widget) OnHotKey(f gowid.IWidgetChangedCallback)
func (*Widget) OnProcessExited ¶
func (w *Widget) OnProcessExited(f gowid.IWidgetChangedCallback)
func (*Widget) OnSetTitle ¶
func (w *Widget) OnSetTitle(f gowid.IWidgetChangedCallback)
func (*Widget) PasteState ¶ added in v1.4.0
func (*Widget) RemoveOnBell ¶
func (*Widget) RemoveOnHotKey ¶ added in v1.4.0
func (*Widget) RemoveOnProcessExited ¶
func (*Widget) RemoveOnSetTitle ¶
func (*Widget) RenderSize ¶
func (w *Widget) RenderSize(size gowid.IRenderSize, focus gowid.Selector, app gowid.IApp) gowid.IRenderBox
func (*Widget) RequestTerminate ¶
func (*Widget) ResetScroll ¶
func (w *Widget) ResetScroll()
func (*Widget) ScrollbarEnabled ¶ added in v1.4.0
func (*Widget) SetTerminalSize ¶
func (*Widget) StartCommand ¶
func (*Widget) StopCommand ¶
func (w *Widget) StopCommand()