Documentation ¶
Overview ¶
Package ui manages the terminal and logs output for zedpm.
Index ¶
- func StringWidth(str string) int
- func TruncateString(line string, width int, ellipsis string) string
- type Characters
- type Progress
- func (p *Progress) Close()
- func (p *Progress) HasPhases() bool
- func (p *Progress) Log(name, level, message string, args ...any)
- func (p *Progress) RegisterTask(name, title string)
- func (p *Progress) SetPhases(phases []string)
- func (p *Progress) StartPhase(phase int, taskCount int)
- func (p *Progress) TaskWidgetSize() int
- func (p *Progress) UpdateProgress()
- type ProgressAdapter
- type ProgressWriter
- type State
- func (s *State) AddFlags(id WidgetID, action string, flags []string)
- func (s *State) AddWidget(n int) WidgetID
- func (s *State) Close()
- func (s *State) DeleteWidget(id WidgetID)
- func (s *State) IncTick(id WidgetID, action string)
- func (s *State) Log(line string)
- func (s *State) LogWidget(id WidgetID, line string)
- func (s *State) MovementsToBoundary() int
- func (s *State) Redraw()
- func (s *State) Set(id WidgetID, n int, line string, flags ...string)
- func (s *State) SetActionKey(id WidgetID, n int, action string)
- func (s *State) SetOutcome(id WidgetID, action string, outcome log.Outcome)
- func (s *State) SetStatus(id WidgetID, n int, name string, icon statusIcon, op string)
- func (s *State) SetTitle(id WidgetID, title string)
- func (s *State) Title(id WidgetID) string
- type Terminal
- func (t *Terminal) AddLines(n int)
- func (t *Terminal) ClearLine()
- func (t *Terminal) ClearLines(n int)
- func (t *Terminal) Height() int
- func (t *Terminal) IsTTY() bool
- func (t *Terminal) MoveUp(n int)
- func (t *Terminal) Println(line string)
- func (t *Terminal) SetEllipsis(ellipsis string)
- func (t *Terminal) Width() int
- func (t *Terminal) WriteLine(line string)
- type WidgetID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StringWidth ¶
StringWidth will calculate the width of the string, taking control sequences into account as well as graphemes and their sizes.
func TruncateString ¶
TruncateString will take a string and shorten it so that it's visible length matches the given value. It will also make the last visible part of the string the value given as the ellipsis (which may be empty).
Types ¶
type Characters ¶
type Characters struct {
// contains filtered or unexported fields
}
Characters is a scanner that returns character groups for a terminal widgetLogLine one at a time. Each group represents either some visible element (a grapheme or space or 0-width component of a unicode string) or a complete terminal escape sequence. Only a subset of CSI escapes are supported (i.e., only including those that may be used by the code of zedpm or plugins).
func NewCharacters ¶
func NewCharacters(str string) *Characters
NewCharacters creates a new Characters iterator.
func (*Characters) Bytes ¶
func (c *Characters) Bytes() []byte
Bytes returns a byte slice which corresponds to the current grapheme cluster or escape sequence.
func (*Characters) IsEscape ¶
func (c *Characters) IsEscape() bool
IsEscape returns true if the current cluster of bytes is an escape sequence.
func (*Characters) Next ¶
func (c *Characters) Next() bool
Next moves to the next grapheme or terminal escape sequence. This returns false if no more graphemes or escape sequence remain.
func (*Characters) Positions ¶
func (c *Characters) Positions() (int, int)
Positions returns the start and end locations of the current escape seqeuence or grapheme cluster in the string.
func (*Characters) Runes ¶
func (c *Characters) Runes() []rune
Runes returns a rune slice which corresponds to the current grapheme cluster or escape sequence.
func (*Characters) String ¶
func (c *Characters) String() string
String returns a string which corresponse to the current grapheme cluster or terminal escape sequence.
func (*Characters) Width ¶
func (c *Characters) Width() int
Width returns the visible width of the current grapheme or terminal sequence (terminal sequences are always treated as zero-width).
type Progress ¶
type Progress struct {
// contains filtered or unexported fields
}
func NewProgress ¶
func (*Progress) Close ¶
func (p *Progress) Close()
Close should always be called when finished with the progress widgetLogLine. When state is used, this will close all widgets and move the cursor to the final widgetLogLine.
func (*Progress) Log ¶
Log will process a log widgetLogLine, typically by writing it to the screen. If widgets are present, it will add the widgetLogLine to the appropriate widget. It will also handle a number of special @<name> fields:
@task - name of the task to log this with @operation - the operation the task is performing @action - an action key to identify some persistent state @actionFlags - flags to modify how the log is displayed (e.g., "spin" and "autospin") @outcome - outcome is the final outcome of an action @tick - tick will cause a widgetLogLine with an associated "spin" flag to move
func (*Progress) RegisterTask ¶
func (*Progress) StartPhase ¶
func (*Progress) TaskWidgetSize ¶
func (*Progress) UpdateProgress ¶
func (p *Progress) UpdateProgress()
type ProgressAdapter ¶
type ProgressAdapter struct {
// contains filtered or unexported fields
}
ProgressAdapter sends logs to the progress.
func NewSinkAdapter ¶
func NewSinkAdapter(progress *Progress, minLevel hclog.Level) *ProgressAdapter
type ProgressWriter ¶
type ProgressWriter struct {
// contains filtered or unexported fields
}
func NewWriter ¶
func NewWriter(name, level string, progress *Progress) *ProgressWriter
type State ¶
type State struct {
// contains filtered or unexported fields
}
State tracks the low-level state of output and writes that state to the terminal.
func NewState ¶
NewState creates a new State object attached to the given terminal with room for capacity widgets, initially. Capacity will expand as needed.
State manages the terminal in two basic sections separated by a boundary widgetLogLine. Above the boundary widgetLogLine is a log. Below is zero or more widgets which are drawn and redrawn with every change.
func (*State) AddWidget ¶
AddWidget creates a new widget with the given row height and then resizes and redraws the State on the terminal. The returned WidgetID should be used to make any changes to this widget going forward.
func (*State) Close ¶
func (s *State) Close()
Close should always be called before program termination or when the State object is about to give up control of the terminal. This will erase all the widgets and move the cursor to where the boundary widgetLogLine was, just below the end of the log.
func (*State) DeleteWidget ¶
DeleteWidget removes the widget with the given WidgetID. Then it resizes and redraws the State on the terminal.
func (*State) LogWidget ¶
LogWidget will write a log to the widget identified by the given WidgetID. If no such widget exists or the NoWidget constant is passed, the log is recorded above the boundary without writing anything to the state below.
func (*State) MovementsToBoundary ¶
MovementsToBoundary states how many cursor movements are required to move the cursor from the bottom of the on-screen State to the boundary widgetLogLine.
func (*State) Redraw ¶
func (s *State) Redraw()
Redraw triggers a redraw. This should never be necessary to call directly.
func (*State) Set ¶
Set will set the value of a specific widget widgetLogLine to the given value. If the widget given by the WidgetID does not exist, this method does nothing. If flags are given, the flags are immediately added to the line.
func (*State) SetActionKey ¶
SetActionKey assigns an action key to a line in a widget.
func (*State) SetOutcome ¶
SetOutcome assigns an outcome to a line in a widget.
func (*State) SetStatus ¶
SetStatus will set the status of a specific widget widgetLine. This does nothing if the widget with the given ID does not exist. This will then redraw the widget.
type Terminal ¶
type Terminal struct {
// contains filtered or unexported fields
}
Terminal is a very simple tool for writing to and manipulating the terminal.
func NewTerminal ¶
NewTerminal creates a Terminal object for the given terminal and returns a pointer to that object.
func (*Terminal) ClearLine ¶
func (t *Terminal) ClearLine()
ClearLine will clear the row the cursor is currently on.
func (*Terminal) ClearLines ¶
ClearLines will clear n lines below the row the cursor is currently on.
func (*Terminal) Height ¶
Height returns the number of rows on the current TTY. Returns 0 if this is not a TTY.
func (*Terminal) IsTTY ¶
IsTTY returns true if the screen is a TTY. If IsTTY is false, the only feature that will do anything is WriteLine. All other methods become no-ops. In fact, even WriteLine does less: it will no longer clear lines.
func (*Terminal) Println ¶
Println will write a single widgetLogLine to the screen. This will blank any existing data on the current widgetLogLine before writing and will move the cursor down one widgetLogLine afterward.
func (*Terminal) SetEllipsis ¶
SetEllipsis sets a string to add at the end of a truncated widgetLogLine. The default is to have no such string and just terminate the widgetLogLine at the end of the on-screen widgetLogLine.
func (*Terminal) Width ¶
Width returns the number of coumns in the current TTY. Returns 0 if this is not a TTY.
func (*Terminal) WriteLine ¶
WriteLine will write a single widgetLogLine to the screen. If the given widgetLogLine contains a newline, it will be replaced by U+2424 (SYMBOL FOR NEWLINE) on screen. This will also truncate the widgetLogLine so it is not longer than the terminal width. This will blank any existing data on the current widgetLogLine before writing and will move the cursor down one widgetLogLine afterward.