2015-10-16 10:27:43 -07:00
package clui
import (
term "github.com/nsf/termbox-go"
)
const (
2016-10-13 14:16:05 -07:00
// Fixed means 'never change size of the object when its parent resizes'
Fixed int = 0
2015-10-26 17:47:50 -07:00
// AutoSize is used only in constructors. It means that the constructor
// should either calculate the size of an object, e.g. for Label it is its text
// length, or use default intial values
2015-10-16 10:27:43 -07:00
AutoSize int = - 1
2016-10-13 14:16:05 -07:00
// KeepSize is used as a placeholder when you want to change only one
2015-10-26 17:47:50 -07:00
// value and keep other ones untouched. Used in SetSize and SetConstraints
// methods only
2016-10-13 14:16:05 -07:00
// Example: control.SetConstraint(10, KeepValue) changes only minimal width
2015-10-26 17:47:50 -07:00
// of the control and do not change the current minimal control height
2016-10-13 14:16:05 -07:00
KeepValue int = - 1
2015-10-16 10:27:43 -07:00
)
// Predefined types
type (
2015-10-26 17:47:50 -07:00
// BorderStyle is a kind of frame: none, single, and double
BorderStyle int
// ViewButton is a set of buttons displayed in a view title
ViewButton int
// HitResult is a type of a view area that is under mouse cursor.
// Used in mouse click events
HitResult int
// Align is text align: left, right and center
Align int
// EventType is a type of event fired by an object
EventType int
// Direction indicates the direction in which a control must draw its
// content. At that moment it can be applied to Label (text output
// direction and to ProgressBar (direction of bar filling)
Direction int
// PackType sets how to pack controls inside its parent. Can be Vertical or
// Horizontal
PackType int
// SelectDialogType sets the way of choosing an item from a list for
// SelectionDialog control: a list-based selections, or radio group one
2015-10-22 14:44:19 -07:00
SelectDialogType uint
2015-12-22 16:39:32 -08:00
// TableAction is a type of user-generated event for TableView
TableAction int
// SortOrder is a way of sorting rows in TableView
SortOrder int
2016-10-13 14:16:05 -07:00
DragType int
)
const (
DragNone DragType = iota
DragMove
DragResizeLeft
DragResizeRight
DragResizeBottom
DragResizeBottomLeft
DragResizeBottomRight
DragResizeTopLeft
DragResizeTopRight
2015-10-16 10:27:43 -07:00
)
2015-10-26 17:47:50 -07:00
// Event is structure used by Views and controls to communicate with Composer
// and vice versa
2015-10-16 10:27:43 -07:00
type Event struct {
2015-10-27 14:39:16 -07:00
// Event type - the first events are mapped to termbox Event and then a few
// own events added to the end
Type EventType
// Mod - is a key modifier. Only Alt modifier is supported
Mod term . Modifier
// Msg is a text part of the event. Used by few events: e.g, ListBox click
// sends a value of clicked item
Msg string
// X and Y are multi-purpose fields: mouse coordinated for click event,
// X is used to indicate on/off for events like Activate
// Y is used for vertical-based events like ListBox item selection - id of the item
X , Y int
// Err is error got from termbox library
Err error
// Key is a pressed key
Key term . Key
// Ch is a printable representation of pressed key combinaton
Ch rune
2016-10-13 14:16:05 -07:00
// For resize event - new terminal size
Width int
Height int
2015-10-16 10:27:43 -07:00
}
// BorderStyle constants
const (
2015-11-03 10:08:10 -08:00
BorderNone BorderStyle = iota
2016-10-13 14:16:05 -07:00
BorderThin
BorderThick
2015-10-16 10:27:43 -07:00
)
// Color predefined values
const (
ColorDefault = term . ColorDefault
ColorBlack = term . ColorBlack
ColorRed = term . ColorRed
ColorGreen = term . ColorGreen
ColorYellow = term . ColorYellow
ColorBlue = term . ColorBlue
ColorMagenta = term . ColorMagenta
ColorCyan = term . ColorCyan
ColorWhite = term . ColorWhite
ColorBlackBold = term . ColorBlack | term . AttrBold
ColorRedBold = term . ColorRed | term . AttrBold
ColorGreenBold = term . ColorGreen | term . AttrBold
ColorYellowBold = term . ColorYellow | term . AttrBold
ColorBlueBold = term . ColorBlue | term . AttrBold
ColorMagentaBold = term . ColorMagenta | term . AttrBold
ColorCyanBold = term . ColorCyan | term . AttrBold
ColorWhiteBold = term . ColorWhite | term . AttrBold
)
// HitResult constants
const (
2015-11-03 10:08:10 -08:00
HitOutside HitResult = iota
2015-10-16 10:27:43 -07:00
HitInside
HitBorder
2016-10-13 14:16:05 -07:00
HitTop
HitBottom
HitRight
HitLeft
HitTopLeft
HitTopRight
HitBottomRight
HitBottomLeft
2015-10-16 10:27:43 -07:00
HitButtonClose
HitButtonBottom
HitButtonMaximize
)
2015-10-27 14:39:16 -07:00
// VeiwButton values - list of buttons available for using in View title
2015-10-16 10:27:43 -07:00
const (
2015-10-27 14:39:16 -07:00
// ButtonDefault - no button
2015-11-03 10:08:10 -08:00
ButtonDefault ViewButton = 0
2015-10-27 14:39:16 -07:00
// ButtonClose - button to close View
2015-10-16 10:27:43 -07:00
ButtonClose = 1 << 0
2015-10-27 14:39:16 -07:00
// ButtonBottom - move Window to bottom of the View stack
2015-10-16 10:27:43 -07:00
ButtonBottom = 1 << 1
2015-10-27 14:39:16 -07:00
// ButtonMaximaize - maximize and restore View
2015-10-16 10:27:43 -07:00
ButtonMaximize = 1 << 2
)
// Alignment constants
const (
2015-11-03 10:08:10 -08:00
AlignLeft Align = iota
2015-10-16 10:27:43 -07:00
AlignRight
AlignCenter
)
// Output direction
2015-10-26 17:47:50 -07:00
// Used for Label text output direction and for Radio items distribution,
// and for container controls
2015-10-16 10:27:43 -07:00
const (
Horizontal = iota
Vertical
)
2015-10-27 14:39:16 -07:00
// Available object identifiers that can be used in themes
2015-10-16 10:27:43 -07:00
const (
ObjSingleBorder = "SingleBorder"
ObjDoubleBorder = "DoubleBorder"
ObjEdit = "Edit"
ObjScrollBar = "ScrollBar"
ObjViewButtons = "ViewButtons"
ObjCheckBox = "CheckBox"
ObjRadio = "Radio"
ObjProgressBar = "ProgressBar"
2015-12-09 16:13:33 -08:00
ObjBarChart = "BarChart"
2015-12-11 15:33:29 -08:00
ObjSparkChart = "SparkChart"
2015-12-15 17:19:04 -08:00
ObjTableView = "TableView"
2015-10-16 10:27:43 -07:00
)
2015-10-27 14:39:16 -07:00
// Available color identifiers that can be used in themes
2015-10-16 10:27:43 -07:00
const (
// Window back and fore colors (inner area & border)
ColorViewBack = "ViewBack"
ColorViewText = "ViewText"
// general colors
2015-10-19 12:05:43 -07:00
ColorBack = "Back"
ColorText = "Text"
2015-10-20 14:32:16 -07:00
ColorDisabledText = "GrayText"
2015-10-19 12:05:43 -07:00
ColorDisabledBack = "GrayBack"
2015-10-16 10:27:43 -07:00
// editable & listbox-like controls
ColorEditBack = "EditBack"
ColorEditText = "EditText"
ColorEditActiveBack = "EditActiveBack"
ColorEditActiveText = "EditActiveText"
ColorSelectionText = "SelectionText"
ColorSelectionBack = "SelectionBack"
2015-11-02 17:08:36 -08:00
// button control
ColorButtonBack = "ButtonBack"
ColorButtonText = "ButtonText"
ColorButtonActiveBack = "ButtonActiveBack"
ColorButtonActiveText = "ButtonActiveText"
ColorButtonShadow = "ButtonShadowBack"
ColorButtonDisabledBack = "ButtonDisabledBack"
ColorButtonDisabledText = "ButtonDisabledText"
2015-10-16 10:27:43 -07:00
// scroll control
ColorScrollText = "ScrollText"
ColorScrollBack = "ScrollBack"
ColorThumbText = "ThumbText"
ColorThumbBack = "ThumbBack"
// window-like controls (button, radiogroup...)
ColorControlText = "ControlText"
ColorControlBack = "ControlBack"
ColorControlActiveBack = "ControlActiveBack"
ColorControlActiveText = "ControlActiveText"
ColorControlDisabledBack = "ControlDisabledBack"
ColorControlDisabledText = "ControlDisabledText"
2015-10-20 14:32:16 -07:00
ColorControlShadow = "ControlShadowBack"
2015-10-16 10:27:43 -07:00
// progressbar colors
2015-10-19 12:05:43 -07:00
ColorProgressBack = "ProgressBack"
ColorProgressText = "ProgressText"
ColorProgressActiveBack = "ProgressActiveBack"
ColorProgressActiveText = "ProgressActiveText"
2015-11-24 17:28:20 -08:00
ColorProgressTitleText = "ProgressTitle"
2015-12-09 16:13:33 -08:00
// barchart colors
ColorBarChartBack = "BarChartBack"
ColorBarChartText = "BarChartText"
2015-12-11 15:33:29 -08:00
// sparkchart colors
ColorSparkChartBack = "SparkChartBack"
ColorSparkChartText = "SparkChartText"
ColorSparkChartBarBack = "SparkChartBarBack"
ColorSparkChartBarText = "SparkChartBarText"
ColorSparkChartMaxBack = "SparkChartMaxBack"
ColorSparkChartMaxText = "SparkChartMaxText"
2015-12-15 17:19:04 -08:00
// tableview colors
ColorTableText = "TableText"
ColorTableBack = "TableBack"
ColorTableSelectedText = "TableSelectedText"
ColorTableSelectedBack = "TableSelectedBack"
ColorTableActiveCellText = "TableActiveCellText"
ColorTableActiveCellBack = "TableActiveCellBack"
ColorTableLineText = "TableLineText"
ColorTableHeaderText = "TableHeaderText"
ColorTableHeaderBack = "TableHeaderBack"
2015-10-16 10:27:43 -07:00
)
2015-10-26 17:47:50 -07:00
// EventType is event that window or control may process
2015-10-16 10:27:43 -07:00
// Note: Do not change events from EventKey to EventNone - they correspond to the same named events in termbox library
const (
// a key pressed
EventKey EventType = iota
// an object or console size changed. X and Y are new width and height
EventResize
2016-10-13 14:16:05 -07:00
// Mouse button clicked. X and Y are coordinates of mouse click
2015-10-16 10:27:43 -07:00
EventMouse
// Something bad happened
EventError
EventInterrupt
EventRaw
EventNone
// Asks an object to redraw. A library can ask a control to redraw and control can send the event to its parent to ask for total repaint, e.g, button sends redraw event after to its parent it depressed after a while to imitate real button
2015-10-27 14:39:16 -07:00
EventRedraw = iota + 100
2015-10-16 10:27:43 -07:00
// an object that receives the event should close and destroys itself
EventClose
// Notify an object when it is activated or deactivated. X determines whether the object is activated or deactivated(0 - deactivated, 1 - activated)
EventActivate
// An object changes its position. X and Y are new coordinates of the object
EventMove
/ *
control events
* /
// Content of a control changed. E.g, EditField text changed, selected item of ListBox changed etc
// X defines how the content was changed: 0 - by pressing any key, 1 - by clicking mouse. This is used by compound controls, e.g, child ListBox of ComboBox should change its parent EditField text when a user selects a new item an ListBox with arrow keys and the ListBox should be closed if a user clicks on ListBox item
EventChanged
// Button event - button was clicked
2016-10-13 14:16:05 -07:00
EventClick
2015-10-21 09:38:43 -07:00
// dialog closed
EventDialogClose
2015-10-16 10:27:43 -07:00
// Close application
EventQuit
2017-06-30 15:25:29 -07:00
// Close top window - or application is there is only one window
EventCloseWindow
2015-10-16 10:27:43 -07:00
)
2015-10-21 17:04:57 -07:00
2015-10-27 14:39:16 -07:00
// ConfirmationDialog and SelectDialog exit codes
2015-10-21 17:04:57 -07:00
const (
2015-10-27 14:39:16 -07:00
// DialogClosed - a user clicked close button on the dialog title
DialogClosed = - 1
// DialogAlive - a user does not close the dialog yet, exit code is unavailable
DialogAlive = 0
// DialogButton1 - a user clicked the first button in the dialog (by default, it is 'Yes' or 'OK')
2015-10-22 13:37:38 -07:00
DialogButton1 = 1
2015-10-27 14:39:16 -07:00
// DialogButton2 - a user clicked the second button in the dialog
2015-10-22 13:37:38 -07:00
DialogButton2 = 2
2015-10-27 14:39:16 -07:00
// DialogButton3 - a user clicked the third button in the dialog
2015-10-22 13:37:38 -07:00
DialogButton3 = 3
)
2015-10-27 14:39:16 -07:00
// Predefined sets of the buttons for ConfirmationDialog and SelectDialog
2015-10-22 13:37:38 -07:00
var (
ButtonsOK = [ ] string { "OK" }
ButtonsYesNo = [ ] string { "Yes" , "No" }
ButtonsYesNoCancel = [ ] string { "Yes" , "No" , "Cancel" }
2015-10-21 17:04:57 -07:00
)
2015-10-22 14:44:19 -07:00
2015-10-27 14:39:16 -07:00
// SelectDialogType constants
2015-10-22 14:44:19 -07:00
const (
2015-10-27 14:39:16 -07:00
// SelectDialogList - all items are displayed in a ListBox
2015-11-03 10:08:10 -08:00
SelectDialogList SelectDialogType = iota
2015-10-27 14:39:16 -07:00
// SelectDialogList - all items are displayed in a RadioGroup
2015-10-22 14:44:19 -07:00
SelectDialogRadio
)
2015-12-22 16:39:32 -08:00
// TableAction constants
const (
// A user pressed F2 or Enter key in TableView
TableActionEdit TableAction = iota
// A user pressed Insert key in TableView
TableActionNew
// A user pressed Delete key in TableView
TableActionDelete
// A user clicked on a column header in TableView
TableActionSort
)
// SortOrder constants
const (
// Do not sort
SortNone SortOrder = iota
// Sort ascending
SortAsc
// Sort descending
SortDesc
)