zterm

package
v0.0.0-...-39ce11f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 16, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrSuspend error cause gocui environment to suspend
	ErrSuspend = errors.New("suspend")
)

Functions

func AttributeAnsi

func AttributeAnsi(col gocui.Attribute) (gocui.Attribute, termenv.Color)

AttributeAnsi converts gocui.Attribute to ANSI color and returns both of them

func ColorProfile

func ColorProfile() termenv.Profile

ColorProfile returns color profile based on configuration

func LoadTheme

func LoadTheme()

LoadTheme loads theme specified in config file.

func Main

func Main(remote bool)

Main function of zterm package

- setup GUI for TUI (terminal user interface)

- set layout

- set keybindings

- run GUI.MainLoop

func StringAttributeAnsi

func StringAttributeAnsi(col string) (gocui.Attribute, termenv.Color, error)

StringAttributeAnsi converts string to gocui.Attribute and returns both of them

Types

type BasicColor

type BasicColor int

BasicColor is for termenv to be able to convert to `\033[3x;1m` or `\033[3x;2m`

func (BasicColor) Sequence

func (c BasicColor) Sequence(bg bool) string

Sequence return string with ANSI code

type Config

type Config struct {
	Server `mapstructure:"server"`
	Theme  `mapstructure:"theme"`
	Views  map[string]View `mapstructure:"views"`
}

Config type defining configuration

type RecvConn

type RecvConn struct {
	// contains filtered or unexported fields
}

RecvConn struct contains channels for output and error string and error

func NewRecvConn

func NewRecvConn() *RecvConn

NewRecvConn create new connection to receive output from command/function

func (*RecvConn) IsEnd

func (conn *RecvConn) IsEnd() <-chan struct{}

IsEnd return ending signal. Check if it's closed to confirm if it is end.

func (*RecvConn) Stop

func (conn *RecvConn) Stop()

Stop command/function origin by sending ending signal.

*it can be called multiple times, it doesn't block*

func (*RecvConn) WaitEnd

func (conn *RecvConn) WaitEnd()

WaitEnd blocks the processing until the connected command/function ends.

type Server

type Server struct {
	Host string
	User string
}

Server configuration

type Theme

type Theme struct {
	ColorSpace string `mapstructure:"color-space"`
	FgColor    string `mapstructure:"fgcolor"`
	BgColor    string `mapstructure:"bgcolor"`
	Frame      string `mapstructure:"frame"`
	FrameSel   string `mapstructure:"frame-select"`
	Console    string `mapstructure:"console"`
	Popup      string `mapstructure:"popup"`
	Error      string `mapstructure:"error"`
	Highlight  string `mapstructure:"highlight"`
}

Theme configuration

type View

type View struct {
	Position int      `mapstructure:"position"`
	Size     int      `mapstructure:"size"`
	Job      string   `mapstructure:"job,omitempty"`
	HiLine   []string `mapstructure:"hiline,omitempty"`
	HiWord   []string `mapstructure:"hiword,omitempty"`
}

View configuration

type Widget

type Widget struct {
	FrameColor gocui.Attribute
	TitleColor gocui.Attribute
	Enabled    bool
	// contains filtered or unexported fields
}

Widget structure for GUI

func NewWidget

func NewWidget(name string, x0 int, y0 int, x1 int, y1 int, body string) *Widget

NewWidget creates a widget for GUI

func (*Widget) Clear

func (w *Widget) Clear()

Clear clears the widget content and reset position

func (*Widget) Connect

func (w *Widget) Connect(conn *RecvConn)

Connect content producing channel

func (*Widget) Disconnect

func (w *Widget) Disconnect()

Disconnect content producing channel

func (*Widget) Error

func (w *Widget) Error(err error)

Error append an error text to the widget content

func (*Widget) GetName

func (w *Widget) GetName() string

GetName returns widget name

func (*Widget) GetView

func (w *Widget) GetView() *gocui.View

GetView returns widget GUI View

func (*Widget) IsHidden

func (w *Widget) IsHidden() bool

IsHidden checks if widget is disabled

func (*Widget) Keybinds

func (w *Widget) Keybinds(g *gocui.Gui)

Keybinds for specific widget

func (*Widget) Layout

func (w *Widget) Layout(g *gocui.Gui) error

Layout setup for widget

func (*Widget) Position

func (w *Widget) Position() int

Position returns position of the widget in the stack. This is used for sorting purposes. For basic widget it's always the biggest, because they should be after WidgetStack.

func (*Widget) Print

func (w *Widget) Print(str string)

Print append a text to the widget content

type WidgetConsole

type WidgetConsole struct {
	Widget
	// contains filtered or unexported fields
}

WidgetConsole structure for GUI

func NewWidgetConsole

func NewWidgetConsole() *WidgetConsole

NewWidgetConsole creates a widget for GUI which doesn't contribute to the layout. This type of widget is displayed on top over the layout.

func (*WidgetConsole) Clear

func (wc *WidgetConsole) Clear()

Clear override to not clear the console output (this is triggered everytime new command is issued in update)

func (*WidgetConsole) Error

func (wc *WidgetConsole) Error(err error)

Error print error message to the console output line (second line below prompt)

func (*WidgetConsole) ExecCmd

func (wc *WidgetConsole) ExecCmd(cmd string)

ExecCmd execute command in the Console Widget

func (*WidgetConsole) Keybinds

func (wc *WidgetConsole) Keybinds(g *gocui.Gui)

Keybinds for specific widget

func (*WidgetConsole) Layout

func (wc *WidgetConsole) Layout(g *gocui.Gui) error

Layout setup for console widget

func (*WidgetConsole) NextHistory

func (wc *WidgetConsole) NextHistory() string

NextHistory go forward in history and return command from it

func (*WidgetConsole) PrevHistory

func (wc *WidgetConsole) PrevHistory() string

PrevHistory go back in history and return command from it

func (*WidgetConsole) Print

func (wc *WidgetConsole) Print(msg string)

Print message to the console output line

func (*WidgetConsole) Printf

func (wc *WidgetConsole) Printf(format string, a ...interface{})

Printf print formatted message to the console output line (second line below prompt)

func (*WidgetConsole) Println

func (wc *WidgetConsole) Println(msg string)

Println prints message to the console output line and add new line at the end

type WidgetFloaty

type WidgetFloaty struct {
	Widget
	Editable bool
}

WidgetFloaty structure for GUI

func NewWidgetFloaty

func NewWidgetFloaty(name string, x, y int, width int, height int, body string) *WidgetFloaty

NewWidgetFloaty creates a widget for GUI which doesn't contribute to the layout. This type of widget is displayed on top over the layout.

func PopupHelpWidget

func PopupHelpWidget() *WidgetFloaty

PopupHelpWidget creates a pop help widget for GUI

func (*WidgetFloaty) Keybinds

func (wf *WidgetFloaty) Keybinds(g *gocui.Gui)

Keybinds for specific widget

func (*WidgetFloaty) Layout

func (wf *WidgetFloaty) Layout(g *gocui.Gui) error

Layout setup for floaty widget

type WidgetPipe

type WidgetPipe struct {
	Widget
	// contains filtered or unexported fields
}

WidgetPipe structure for pipe which can be put between widget and command

func NewWidgetPipe

func NewWidgetPipe(w Widgeter) *WidgetPipe

NewWidgetPipe creates a pipe widget wich is used as a pipe between real widget and output sent to it.

func (*WidgetPipe) Error

func (wp *WidgetPipe) Error(err error)

Error append an error text to the widget content

func (*WidgetPipe) Layout

func (wp *WidgetPipe) Layout(g *gocui.Gui) error

Layout setup for floaty widget

func (*WidgetPipe) Print

func (wp *WidgetPipe) Print(str string)

Print append a text to the widget content

type WidgetStack

type WidgetStack struct {
	Widget

	Fun func() error
	// contains filtered or unexported fields
}

WidgetStack structure for GUI (widgets which are stack on each other)

func NewWidgetStack

func NewWidgetStack(name string, pos int, height int, body string) *WidgetStack

NewWidgetStack creates a widget for stack GUI

func (*WidgetStack) GetFunString

func (ws *WidgetStack) GetFunString() string

GetFunString return command running in this widget

func (*WidgetStack) Keybinds

func (ws *WidgetStack) Keybinds(g *gocui.Gui)

Keybinds for specific widget

func (*WidgetStack) Layout

func (ws *WidgetStack) Layout(g *gocui.Gui) error

Layout setup for widget

func (*WidgetStack) Position

func (ws *WidgetStack) Position() int

Position returns position in the stack of widgets

func (*WidgetStack) Print

func (ws *WidgetStack) Print(str string)

Print append a text to the widget content. Printed line or word will be highlighted if such word exist in `highlight` map in WidgetStack.

func (*WidgetStack) SetupFun

func (ws *WidgetStack) SetupFun(cmd string)

SetupFun set function to run in interval in this widget

func (*WidgetStack) StartFun

func (ws *WidgetStack) StartFun()

StartFun starts a function for the view to update it's content. Function has to return string which is used for update

func (*WidgetStack) StopFun

func (ws *WidgetStack) StopFun()

StopFun stops function running to update widget

type Widgeter

type Widgeter interface {
	// Layout is for gocui.GUI
	Layout(*gocui.Gui) error
	Keybinds(*gocui.Gui)
	GetName() string
	GetView() *gocui.View
	IsHidden() bool
	Position() int
	Connect(conn *RecvConn)
	Disconnect()
	Clear()
	Print(str string)
	Error(err error)
}

Widgeter cover Layout for GUI and some specifics for widgets

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL