cons

package
v0.0.0-...-f82ba6c Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyControlC is Control+C
	KeyControlC = 3
	// KeyEnter is the Enter key
	KeyEnter = 13
	// KeyControlEnter is the Control+Enter keys
	KeyControlEnter = 10
	// KeyTab is the Tab key
	KeyTab = 9
	// KeyBackspace is the backspace key
	KeyBackspace = 8
	// KeyEscape is the escape key
	KeyEscape = 27
	// KeyPageUp is the page up key
	KeyPageUp = 129
	// KeyPageDown is the page down key
	KeyPageDown = 130
	// KeyEnd is the end key
	KeyEnd = 131
	// KeyHome is the home key
	KeyHome = 132
	// KeyLeft is the left key
	KeyLeft = 133
	// KeyUp is the up key
	KeyUp = 134
	// KeyRight is the right key
	KeyRight = 135
	// KeyDown is the down key
	KeyDown = 136
	// KeyIns is the insert key
	KeyIns = 141
	// KeyDel is the delete key
	KeyDel = 142
	// KeyF1 is the F1 key
	KeyF1 = 143
	// KeyF2 is the F2 key
	KeyF2 = 144
	// KeyF3 is the F3 key
	KeyF3 = 145
	// KeyF4 is the F4 key
	KeyF4 = 146
	// KeyF5 is the F5 key
	KeyF5 = 147
	// KeyF6 is the F6 key
	KeyF6 = 148
	// KeyF7 is the F7 key
	KeyF7 = 149
	// KeyF8 is the F8 key
	KeyF8 = 150
	// KeyF9 is the F9 key
	KeyF9 = 151
	// KeyF10 is the F10 key
	KeyF10 = 152
	// KeyF11 is the F11 key
	KeyF11 = 153
	// KeyF12 is the F12 key
	KeyF12 = 154
	// KeyF13 is the F13 key
	KeyF13 = 155
	// KeyF14 is the F14 key
	KeyF14 = 156
	// KeyF15 is the F15 key
	KeyF15 = 157
	// KeyF16 is the F16 key
	KeyF16 = 158
	// KeyF17 is the F17 key
	KeyF17 = 159
	// KeyF18 is the F18 key
	KeyF18 = 160
	// KeyF19 is the F19 key
	KeyF19 = 161
	// KeyF20 is the F20 key
	KeyF20 = 162
	// KeyF21 is the F21 key
	KeyF21 = 163
	// KeyF22 is the F22 key
	KeyF22 = 164
	// KeyF23 is the F23 key
	KeyF23 = 165
	// KeyF24 is the F24 key
	KeyF24 = 166
)
View Source
const (
	// LineStyleNone draws no line
	LineStyleNone = 0
	// LineStyleSingle draws a single line
	LineStyleSingle = 1
	// LineStyleDouble draws a double line3
	LineStyleDouble = 2
)
View Source
const (
	// KeyCapsLock is the caps lock modifier
	KeyCapsLock = 1
	// KeyAlt is the alt modifier
	KeyAlt = 2
	// KeyControl is the control modifier
	KeyControl = 4
	// KeyShift is the shift modifier
	KeyShift = 8
)
View Source
const (
	// ColorBlack is the black color
	ColorBlack = 0
	// ColorBlue is the blue color
	ColorBlue = 1
	// ColorGreen is the green color
	ColorGreen = 2
	// ColorCyan is the cyan color
	ColorCyan = 3
	// ColorRed is the red color
	ColorRed = 4
	// ColorMagenta is the magenta color
	ColorMagenta = 5
	// ColorYellow is the yellow color
	ColorYellow = 6
	// ColorWhite is the white color
	ColorWhite = 7
	// ColorBright is a modifier for bright colors
	ColorBright = 8
	// ColorGray is the gray color
	ColorGray = ColorBlack | ColorBright
	// ColorBrightBlue is the bright blue color
	ColorBrightBlue = ColorBlue | ColorBright
	// ColorBrightGreen is the bright green color
	ColorBrightGreen = ColorGreen | ColorBright
	// ColorBrightCyan is the bright cyan color
	ColorBrightCyan = ColorCyan | ColorBright
	// ColorBrightRed is the bright red color
	ColorBrightRed = ColorRed | ColorBright
	// ColorBrightMagenta is the bright magenta color
	ColorBrightMagenta = ColorMagenta | ColorBright
	// ColorBrightYellow is the bright yellow color
	ColorBrightYellow = ColorYellow | ColorBright
	// ColorBrightWhite is the bright white color
	ColorBrightWhite = ColorWhite | ColorBright
)

Variables

This section is empty.

Functions

func Beep

func Beep()

Beep plays a sound if SetBeep was passed true

func BufferCols

func BufferCols() int

BufferCols returns the number of buffer columns on the console screen

func BufferRows

func BufferRows() int

BufferRows returns the number of buffer rows on the console window

func Center

func Center(value string)

Center writes a string centered in the console and advances to the next line.

func Choose

func Choose(title string, subTitle string, items []string, borderStyle int, foreground int8, background int8, inputForeground int8, inputBackground int8, errorForeground int8) int

Choose draws the menu and prompts for input. Title and subTitle are not drawn if empty.

func Cls

func Cls()

Cls clears the screen using the current foreground/background

func Col

func Col() int

Col returns the current screen column the cursor is on from 0 to Cols-1

func Cols

func Cols() int

Cols returns the number of columns on the console screen

func Entry

func Entry(title string, subTitle string, fields []InputField, foreground int8,
	background int8, fieldForeground int8, fieldBackground int8, borderStyle int) bool

Entry simplifies full screen data entry. Calculates row,col positions, draws screen, does input

func FieldValue

func FieldValue(field *InputField) string

FieldValue returns the entered field value

func GetBeep

func GetBeep() bool

GetBeep returns true if a beep will make a sound or false if it will be silent.

func GetStdIn

func GetStdIn() uintptr

GetStdIn gets the stdin windows handle

func GetStdOut

func GetStdOut() uintptr

GetStdOut gets the stdout windows handle

func GetTitle

func GetTitle() string

GetTitle gets the console window title

func IsFullScreen

func IsFullScreen() bool

IsFullScreen returns true if full screen or false if windowed

func IsNumeric

func IsNumeric(s string) bool

IsNumeric tests if string is an integer

func LineInput

func LineInput() string

LineInput allows entry of a line

func LineInputLen

func LineInputLen(max int) string

LineInputLen allows entry of up to max characters

func Locate

func Locate(row int, col int)

Locate positions the cursor to a row and column. valid values are 0 to Rows-1 and 0 to Cols-1

func PaintFields

func PaintFields(fields []InputField, foreground int8, background int8)

PaintFields draws all field contents using foreground/background colors

func PositionInputField

func PositionInputField(field *InputField, row int, col int)

PositionInputField sets the row/col for the input field

func Row

func Row() int

Row returns the current screen row the cursor is on from 0 to Rows-1

func Rows

func Rows() int

Rows returns the number of rows on the console window

func SetBeep

func SetBeep(value bool)

SetBeep will allow beep to sound if value is true or be silent if value is false.

func SetColor

func SetColor(foreground int8, background int8)

SetColor sets the foreground and background colors for subsequent output

func SetFullScreen

func SetFullScreen()

SetFullScreen changes to full screen for 32-bit applications. Does not work for 64bit applications

func SetTitle

func SetTitle(title string)

SetTitle sets the console window title

func SetWindowAndBufferSize

func SetWindowAndBufferSize(rows int, cols int, bufRows int, bufCols int)

SetWindowAndBufferSize sets the window rows/cols and buffer rows/cols. buffer must be >= window size

func SetWindowSize

func SetWindowSize(rows int, cols int)

SetWindowSize sets the console window rows and columns and matches the buffer to it.

func SetWindowed

func SetWindowed()

SetWindowed changes to windowed mode for 32-bit applications. Does not work for 64bit applications

func StartEntry

func StartEntry(fields []InputField) bool

StartEntry performs full screen entry. It is assumed you have already updated the screen in preparation. Params:

fields = The field locations, sizes, and values to capture input for.

Enter, down arrow, and tab moves to the next field. On the last field, Enter will exit while down arrow and tab will move to the first field. up arrow and shift tab will move to the prior field. When on the first field, they will move to the last field. home moves to the begining of the line. end moves to the end of the entered line. left arrow moves left a character right arrow moves right a character up to the end of line control+left arrow moves left a word control+right arrow moves right a word. insert inserts a space delete deletes the current character control+delete deletes to the end of line backspace delets the character to the left of the cursor and moves left one character. f10 or control+Enter will exit entry with success. escape will exit entry with failure. typing a character will change the current character and advance the cursor.

func ValidatedInputField

func ValidatedInputField(field *InputField, validateKey func(field *InputField, key KeyEvent) bool, validateField func(field *InputField) bool)

ValidatedInputField adds key and field validation

Types

type InputField

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

InputField describes a field used for full screen data entry

func CreateInputField

func CreateInputField(row int, col int, prompt string, value string, size int, field *InputField, validateKey func(field *InputField, key KeyEvent) bool, validateField func(field *InputField) bool) InputField

CreateInputField creates a fully populated input field

func NewInputField

func NewInputField(prompt string, value string, size int) InputField

NewInputField creates an input field with prompt, initialial value, and max size

type KeyEvent

type KeyEvent struct {
	// Key is the key that was pressed
	Key uint8
	// Modifier is the bit mask of modifiers that were down when the key was pressed
	Modifier int8
}

KeyEvent represents a key press event

func GetKey

func GetKey() KeyEvent

GetKey returns a keypress event

func Inkey

func Inkey() KeyEvent

Inkey returns 0 key if no input available or a keypress if available. Does not block or wait.

Jump to

Keyboard shortcuts

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