Documentation ¶
Overview ¶
Package termdialog provides a dialog-based GUI system based on Termbox.
Index ¶
- Constants
- Variables
- func BaseDialogHandleEvent(dialog Dialog, event termbox.Event) (handled bool, shouldClose bool)
- func BaseDialogOpen(dialog Dialog)
- func Debug(y int, s string, args ...interface{})
- func DrawBox(x int, y int, width int, height int, style Style)
- func DrawString(x int, y int, str string, style Style)
- func ExitCallback(option *Option) (shouldClose bool)
- func Fill(x int, y int, width int, height int, ch rune, style Style)
- func OpenDialogCallback(option *Option) (shouldClose bool)
- type BaseDialog
- func (dialog *BaseDialog) CalcMetrics()
- func (dialog *BaseDialog) Close()
- func (dialog *BaseDialog) GetHeight() (height int)
- func (dialog *BaseDialog) GetLastDialogStack() (lastDialogStack *DialogStack)
- func (dialog *BaseDialog) GetMetricsDirty() (dirty bool)
- func (dialog *BaseDialog) GetTheme() (theme *Theme)
- func (dialog *BaseDialog) GetTitle() (title string)
- func (dialog *BaseDialog) GetWidth() (width int)
- func (dialog *BaseDialog) GetX() (x int)
- func (dialog *BaseDialog) GetY() (y int)
- func (dialog *BaseDialog) HandleGlobalEvent(event termbox.Event) (handled bool, shouldClose bool)
- func (dialog *BaseDialog) SetHeight(height int)
- func (dialog *BaseDialog) SetLastDialogStack(lastDialogStack *DialogStack)
- func (dialog *BaseDialog) SetMetricsDirty(dirty bool)
- func (dialog *BaseDialog) SetTheme(theme *Theme)
- func (dialog *BaseDialog) SetTitle(title string)
- func (dialog *BaseDialog) SetWidth(width int)
- func (dialog *BaseDialog) SetX(x int)
- func (dialog *BaseDialog) SetY(y int)
- type Dialog
- type DialogStack
- type InputDialog
- func (dialog *InputDialog) CalcMetrics()
- func (dialog *InputDialog) GetCallback() (callback func(string, interface{}) bool)
- func (dialog *InputDialog) GetCallbackArg() (arg interface{})
- func (dialog *InputDialog) GetPrompt() (prompt string)
- func (dialog *InputDialog) GetValue() (value string)
- func (dialog *InputDialog) GetValueWidth() (valueWidth int)
- func (dialog *InputDialog) HandleEvent(event termbox.Event) (handled bool, shouldClose bool)
- func (dialog *InputDialog) Open()
- func (dialog *InputDialog) SetCallback(callback func(string, interface{}) bool)
- func (dialog *InputDialog) SetCallbackArg(arg interface{})
- func (dialog *InputDialog) SetPrompt(prompt string)
- func (dialog *InputDialog) SetValue(value string)
- func (dialog *InputDialog) SetValueWidth(valueWidth int)
- type MessageDialog
- type Option
- type SelectionDialog
- func (dialog *SelectionDialog) AddOption(option *Option) (theSameOption *Option)
- func (dialog *SelectionDialog) CalcMetrics()
- func (dialog *SelectionDialog) ClearOptions()
- func (dialog *SelectionDialog) FindOption(option *Option) (n int)
- func (dialog *SelectionDialog) GetOption(n int) (option *Option)
- func (dialog *SelectionDialog) GetSelectedIndex() (selectedIndex int)
- func (dialog *SelectionDialog) GetSelectedOption() (option *Option)
- func (dialog *SelectionDialog) HandleEvent(event termbox.Event) (handled bool, shouldClose bool)
- func (dialog *SelectionDialog) NOptions() (num int)
- func (dialog *SelectionDialog) Open()
- func (dialog *SelectionDialog) RemoveOption(n int)
- func (dialog *SelectionDialog) SetOption(n int, option *Option)
- func (dialog *SelectionDialog) SetSelectedIndex(selectedIndex int)
- func (dialog *SelectionDialog) SetSelectionOption(option *Option)
- type Style
- type Theme
Constants ¶
const ( BOX_HOZ rune = 0x2500 // Horizontal line BOX_VERT rune = 0x2502 // Vertical line BOX_CORNER_TL rune = 0x250C // Top-left corner BOX_CORNER_TR rune = 0x2510 // Top-right corner BOX_CORNER_BL rune = 0x2514 // Bottom-left corner BOX_CORNER_BR rune = 0x2518 // Bottom-right corner BOX_TEE_L rune = 0x251C // Left tee (i.e. on the left side of a box) BOX_TEE_R rune = 0x2524 // Right tee BOX_TEE_T rune = 0x252C // Top tee BOX_TEE_B rune = 0x2534 // Bottom tee BOX_CROSS rune = 0x253C // Cross )
Variables ¶
var ( HelpDialog *SelectionDialog HelpExitDialog *SelectionDialog HelpGeneralDialog *MessageDialog HelpMessageDialog *MessageDialog HelpSelectionDialog *MessageDialog HelpInputDialog *MessageDialog )
var DefaultTheme = PlainTheme
var PlainTheme = &Theme{ Screen: Style{termbox.ColorBlack, termbox.ColorBlack}, Shadow: Style{termbox.ColorBlack, termbox.ColorBlack}, Border: Style{termbox.ColorWhite, termbox.ColorBlack}, Dialog: Style{termbox.ColorWhite, termbox.ColorWhite}, Title: Style{termbox.ColorBlack | termbox.AttrUnderline, termbox.ColorWhite}, InactiveItem: Style{termbox.ColorBlack, termbox.ColorWhite}, ActiveItem: Style{termbox.ColorWhite, termbox.ColorRed}, HasShadow: false, ShadowOffsetX: 2, ShadowOffsetY: 1, }
Variable PlainTheme theme is the standard black/white theme
var WhiptailTheme = &Theme{ Screen: Style{termbox.ColorBlack, termbox.ColorBlue}, Shadow: Style{termbox.ColorBlack, termbox.ColorBlack}, Border: Style{termbox.ColorBlack, termbox.ColorWhite}, Dialog: Style{termbox.ColorBlack, termbox.ColorWhite}, Title: Style{termbox.ColorBlack | termbox.AttrUnderline, termbox.ColorWhite}, InactiveItem: Style{termbox.ColorBlack, termbox.ColorWhite}, ActiveItem: Style{termbox.ColorWhite, termbox.ColorRed}, HasShadow: true, ShadowOffsetX: 1, ShadowOffsetY: 1, }
Variable WhiptailTheme is a theme that mimics whiptail dialogs
Functions ¶
func BaseDialogHandleEvent ¶
func BaseDialogOpen ¶
func BaseDialogOpen(dialog Dialog)
func DrawString ¶
Function DrawString draws the specified text onto the screen.
func ExitCallback ¶
func OpenDialogCallback ¶
Types ¶
type BaseDialog ¶
type BaseDialog struct {
// contains filtered or unexported fields
}
func (*BaseDialog) CalcMetrics ¶
func (dialog *BaseDialog) CalcMetrics()
func (*BaseDialog) Close ¶
func (dialog *BaseDialog) Close()
func (*BaseDialog) GetHeight ¶
func (dialog *BaseDialog) GetHeight() (height int)
func (*BaseDialog) GetLastDialogStack ¶
func (dialog *BaseDialog) GetLastDialogStack() (lastDialogStack *DialogStack)
func (*BaseDialog) GetMetricsDirty ¶
func (dialog *BaseDialog) GetMetricsDirty() (dirty bool)
func (*BaseDialog) GetTheme ¶
func (dialog *BaseDialog) GetTheme() (theme *Theme)
func (*BaseDialog) GetTitle ¶
func (dialog *BaseDialog) GetTitle() (title string)
func (*BaseDialog) GetWidth ¶
func (dialog *BaseDialog) GetWidth() (width int)
func (*BaseDialog) GetX ¶
func (dialog *BaseDialog) GetX() (x int)
func (*BaseDialog) GetY ¶
func (dialog *BaseDialog) GetY() (y int)
func (*BaseDialog) HandleGlobalEvent ¶
func (dialog *BaseDialog) HandleGlobalEvent(event termbox.Event) (handled bool, shouldClose bool)
func (*BaseDialog) SetHeight ¶
func (dialog *BaseDialog) SetHeight(height int)
func (*BaseDialog) SetLastDialogStack ¶
func (dialog *BaseDialog) SetLastDialogStack(lastDialogStack *DialogStack)
func (*BaseDialog) SetMetricsDirty ¶
func (dialog *BaseDialog) SetMetricsDirty(dirty bool)
func (*BaseDialog) SetTheme ¶
func (dialog *BaseDialog) SetTheme(theme *Theme)
func (*BaseDialog) SetTitle ¶
func (dialog *BaseDialog) SetTitle(title string)
func (*BaseDialog) SetWidth ¶
func (dialog *BaseDialog) SetWidth(width int)
func (*BaseDialog) SetX ¶
func (dialog *BaseDialog) SetX(x int)
func (*BaseDialog) SetY ¶
func (dialog *BaseDialog) SetY(y int)
type Dialog ¶
type Dialog interface { // Stuff implemented by BaseDialog GetTitle() string SetTitle(string) GetMetricsDirty() bool SetMetricsDirty(bool) GetWidth() int SetWidth(int) GetHeight() int SetHeight(int) GetX() int SetX(int) GetY() int SetY(int) GetTheme() *Theme SetTheme(*Theme) GetLastDialogStack() *DialogStack SetLastDialogStack(*DialogStack) Close() // Stuff implemented by subtypes CalcMetrics() Open() HandleEvent(termbox.Event) (bool, bool) HandleGlobalEvent(termbox.Event) (bool, bool) }
type DialogStack ¶
type DialogStack struct {
// contains filtered or unexported fields
}
func NewDialogStack ¶
func NewDialogStack() (dialogStack *DialogStack)
func (*DialogStack) Close ¶
func (dialogStack *DialogStack) Close(dialog Dialog)
func (*DialogStack) CloseTop ¶
func (dialogStack *DialogStack) CloseTop()
func (*DialogStack) Open ¶
func (dialogStack *DialogStack) Open(dialog Dialog)
func (*DialogStack) Run ¶
func (dialogStack *DialogStack) Run()
func (*DialogStack) Stop ¶
func (dialogStack *DialogStack) Stop()
type InputDialog ¶
type InputDialog struct { BaseDialog // contains filtered or unexported fields }
func NewInputDialog ¶
func (*InputDialog) CalcMetrics ¶
func (dialog *InputDialog) CalcMetrics()
func (*InputDialog) GetCallback ¶
func (dialog *InputDialog) GetCallback() (callback func(string, interface{}) bool)
func (*InputDialog) GetCallbackArg ¶
func (dialog *InputDialog) GetCallbackArg() (arg interface{})
func (*InputDialog) GetPrompt ¶
func (dialog *InputDialog) GetPrompt() (prompt string)
func (*InputDialog) GetValue ¶
func (dialog *InputDialog) GetValue() (value string)
func (*InputDialog) GetValueWidth ¶
func (dialog *InputDialog) GetValueWidth() (valueWidth int)
func (*InputDialog) HandleEvent ¶
func (dialog *InputDialog) HandleEvent(event termbox.Event) (handled bool, shouldClose bool)
func (*InputDialog) Open ¶
func (dialog *InputDialog) Open()
func (*InputDialog) SetCallback ¶
func (dialog *InputDialog) SetCallback(callback func(string, interface{}) bool)
func (*InputDialog) SetCallbackArg ¶
func (dialog *InputDialog) SetCallbackArg(arg interface{})
func (*InputDialog) SetPrompt ¶
func (dialog *InputDialog) SetPrompt(prompt string)
func (*InputDialog) SetValue ¶
func (dialog *InputDialog) SetValue(value string)
func (*InputDialog) SetValueWidth ¶
func (dialog *InputDialog) SetValueWidth(valueWidth int)
type MessageDialog ¶
type MessageDialog struct { BaseDialog // contains filtered or unexported fields }
func NewMessageDialog ¶
func NewMessageDialog(title string, message string) (dialog *MessageDialog)
func (*MessageDialog) CalcMetrics ¶
func (dialog *MessageDialog) CalcMetrics()
func (*MessageDialog) GetMessage ¶
func (dialog *MessageDialog) GetMessage() (message string)
func (*MessageDialog) HandleEvent ¶
func (dialog *MessageDialog) HandleEvent(event termbox.Event) (handled bool, shouldClose bool)
func (*MessageDialog) Open ¶
func (dialog *MessageDialog) Open()
func (*MessageDialog) SetMessage ¶
func (dialog *MessageDialog) SetMessage(message string)
type Option ¶
type Option struct { Text string // The text of the option. Callback func(*Option) bool // The callback. Data interface{} // Arbitary associated data that can be accessed by the callback. }
Type Option represents an option in a selection dialog.
type SelectionDialog ¶
type SelectionDialog struct { BaseDialog // contains filtered or unexported fields }
Type SelectionDialog represents a dialog with a number of selectable options.
func NewSelectionDialog ¶
func NewSelectionDialog(title string, options []*Option, maxVisibleOptions ...int) (dialog *SelectionDialog)
Function NewSelectionDialog creates and returns a new selection dialog. The options argument can be nil, and an empty slice will be created (options can be added later with AddOption). Set maxVisibleOptions to get scrolling feature. Designed for compatibility.
func (*SelectionDialog) AddOption ¶
func (dialog *SelectionDialog) AddOption(option *Option) (theSameOption *Option)
func (*SelectionDialog) CalcMetrics ¶
func (dialog *SelectionDialog) CalcMetrics()
func (*SelectionDialog) ClearOptions ¶
func (dialog *SelectionDialog) ClearOptions()
func (*SelectionDialog) FindOption ¶
func (dialog *SelectionDialog) FindOption(option *Option) (n int)
func (*SelectionDialog) GetOption ¶
func (dialog *SelectionDialog) GetOption(n int) (option *Option)
func (*SelectionDialog) GetSelectedIndex ¶
func (dialog *SelectionDialog) GetSelectedIndex() (selectedIndex int)
func (*SelectionDialog) GetSelectedOption ¶
func (dialog *SelectionDialog) GetSelectedOption() (option *Option)
func (*SelectionDialog) HandleEvent ¶
func (dialog *SelectionDialog) HandleEvent(event termbox.Event) (handled bool, shouldClose bool)
func (*SelectionDialog) NOptions ¶
func (dialog *SelectionDialog) NOptions() (num int)
Function NOptions returns the number of options attached to this dialog.
func (*SelectionDialog) Open ¶
func (dialog *SelectionDialog) Open()
func (*SelectionDialog) RemoveOption ¶
func (dialog *SelectionDialog) RemoveOption(n int)
func (*SelectionDialog) SetOption ¶
func (dialog *SelectionDialog) SetOption(n int, option *Option)
func (*SelectionDialog) SetSelectedIndex ¶
func (dialog *SelectionDialog) SetSelectedIndex(selectedIndex int)
func (*SelectionDialog) SetSelectionOption ¶
func (dialog *SelectionDialog) SetSelectionOption(option *Option)
type Style ¶
type Style struct { FG termbox.Attribute BG termbox.Attribute }
Type Style represents a pair of foreground and background attributes.
type Theme ¶
type Theme struct { Screen Style // The style for the empty background region. Shadow Style // The style for the shadow of dialogs (if enabled). Border Style // The style for the border of dialogs. Dialog Style // The style for the empty background of dialogs. Title Style // The style for the title text of dialogs. InactiveItem Style // The style for inactive items and static text on dialogs. ActiveItem Style // The style for active items and widgets that can be interacted with. HasShadow bool // Whether to display a shadow behind dialogs. (keep this false, shadow rendering looks horrible at the moment) ShadowOffsetX int // The X offset of the shadow, relative to the dialog's coordinates. ShadowOffsetY int // The Y offset of the shadow, relative to the dialog's coordinates. }
Type Theme represents a GUI theme.