termdialog

package module
v0.0.0-...-f038f32 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2018 License: BSD-3-Clause Imports: 3 Imported by: 0

README

PLEASE NOTE: I no longer actively maintain this project. Pull requests are welcome, but development has halted and issues are unlikely to gain a response.

Package: github.com/kierdavis/termdialog

doc

Package termdialog provides a dialog-based GUI system based on Termbox.

Install

$ go get github.com/kierdavis/termdialog

Package Dependencies

(documentation provided by GoPkgDoc)

Documentation

Overview

Package termdialog provides a dialog-based GUI system based on Termbox.

Index

Constants

View Source
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

View Source
var (
	HelpDialog     *SelectionDialog
	HelpExitDialog *SelectionDialog

	HelpGeneralDialog   *MessageDialog
	HelpMessageDialog   *MessageDialog
	HelpSelectionDialog *MessageDialog
	HelpInputDialog     *MessageDialog
)
View Source
var DefaultTheme = PlainTheme
View Source
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

View Source
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 BaseDialogHandleEvent(dialog Dialog, event termbox.Event) (handled bool, shouldClose bool)

func BaseDialogOpen

func BaseDialogOpen(dialog Dialog)

func Debug

func Debug(y int, s string, args ...interface{})

func DrawBox

func DrawBox(x int, y int, width int, height int, style Style)

Function DrawBox draws a box on the screen.

func DrawString

func DrawString(x int, y int, str string, style Style)

Function DrawString draws the specified text onto the screen.

func ExitCallback

func ExitCallback(option *Option) (shouldClose bool)

func Fill

func Fill(x int, y int, width int, height int, ch rune, style Style)

Function Fill fills a region of the screen with the specified character and attribute.

func OpenDialogCallback

func OpenDialogCallback(option *Option) (shouldClose bool)

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 NewInputDialog(title string, prompt string, valueWidth int, valueInit string, callback func(string, interface{}) bool, arg interface{}) (dialog *InputDialog)

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.

func (Style) Reverse

func (style Style) Reverse() (newStyle Style)

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.

Jump to

Keyboard shortcuts

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