component

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2022 License: MIT Imports: 4 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

gocui-component

This is unofficial gocui component.
Form and others can be created easily.

Features

you can easily create the following components.

  • Form
  • InputField
  • Button
  • Dialog
  • Table
  • Radio
  • CheckBox
  • Select

LoadMap

  • InputField
  • Button
  • Form
  • Modal
  • Table
  • Radio
  • CheckBox
  • Select

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attributes

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

Attributes text and hilight color

type Button

type Button struct {
	*gocui.Gui

	*Position
	*Attributes
	// contains filtered or unexported fields
}

Button button struct

func NewButton

func NewButton(gui *gocui.Gui, label string, x, y, width int) *Button

NewButton new button

func (*Button) AddHandler

func (b *Button) AddHandler(key Key, handler Handler) *Button

AddHandler add handler

func (*Button) AddHandlerOnly

func (b *Button) AddHandlerOnly(key Key, handler Handler)

func (*Button) Close

func (b *Button) Close()

Close close button

func (*Button) Draw

func (b *Button) Draw()

Draw draw button

func (*Button) Focus

func (b *Button) Focus()

Focus focus to button

func (*Button) GetLabel

func (b *Button) GetLabel() string

GetLabel get button label

func (*Button) GetPosition

func (b *Button) GetPosition() *Position

GetPosition get button position

func (*Button) GetType

func (b *Button) GetType() ComponentType

GetType get component type

func (*Button) IsFocusable

func (b *Button) IsFocusable() bool

func (*Button) SetHilightColor

func (b *Button) SetHilightColor(fgColor, bgColor gocui.Attribute) *Button

SetHilightColor add button fg and bg color

func (*Button) SetTextColor

func (b *Button) SetTextColor(fgColor, bgColor gocui.Attribute) *Button

SetTextColor add button fg and bg color

func (*Button) UnFocus

func (b *Button) UnFocus()

UnFocus un focus

type CheckBox

type CheckBox struct {
	*gocui.Gui

	*Position
	*Attributes
	// contains filtered or unexported fields
}

CheckBox struct

func NewCheckBox

func NewCheckBox(gui *gocui.Gui, label string, x, y, labelWidth int) *CheckBox

NewCheckBox new checkbox

func (*CheckBox) AddAttribute

func (c *CheckBox) AddAttribute(textColor, textBgColor gocui.Attribute) *CheckBox

AddAttribute add text and bg color

func (*CheckBox) AddHandler

func (c *CheckBox) AddHandler(key Key, handler Handler) *CheckBox

AddHandler add handler

func (*CheckBox) AddHandlerOnly

func (c *CheckBox) AddHandlerOnly(key Key, handler Handler)

AddHandlerOnly add handler not retrun

func (*CheckBox) Check

func (c *CheckBox) Check(g *gocui.Gui, v *gocui.View) error

Check check true or false

func (*CheckBox) Close

func (c *CheckBox) Close()

Close close checkbox

func (*CheckBox) Draw

func (c *CheckBox) Draw()

Draw draw label and checkbox

func (*CheckBox) Focus

func (c *CheckBox) Focus()

Focus focus to checkbox

func (*CheckBox) GetLabel

func (c *CheckBox) GetLabel() string

GetLabel get checkbox label

func (*CheckBox) GetPosition

func (c *CheckBox) GetPosition() *Position

GetPosition get checkbox position

func (*CheckBox) GetType

func (c *CheckBox) GetType() ComponentType

GetType get component type

func (*CheckBox) IsChecked

func (c *CheckBox) IsChecked() bool

IsChecked return check state

func (*CheckBox) IsFocusable

func (c *CheckBox) IsFocusable() bool

func (*CheckBox) UnFocus

func (c *CheckBox) UnFocus()

UnFocus unfocus

type Component

type Component interface {
	GetLabel() string
	GetPosition() *Position
	GetType() ComponentType
	Focus()
	UnFocus()
	Draw()
	Close()
	AddHandlerOnly(Key, Handler)
	IsFocusable() bool
}

Component form component interface

type ComponentType

type ComponentType int

ComponentType component type

const (
	// TypeInputField type is input component
	TypeInputField ComponentType = iota
	// TypeSelect type is select component
	TypeSelect
	// TypeButton type is button component
	TypeButton
	// TypeCheckBox type is checkbox component
	TypeCheckBox
	// TypeRadio type is radio component
	TypeRadio
	// TypeTable type is table component
	TypeTable
	// TypeHeading type is heading component
	TypeHeading
)

type Field

type Field struct {
	*Position
	*Attributes
	*Validator
	// contains filtered or unexported fields
}

Field struct

type Form

type Form struct {
	*gocui.Gui

	*Position
	// contains filtered or unexported fields
}

Form form struct

func NewForm

func NewForm(gui *gocui.Gui, name string, x, y, w, h int) *Form

NewForm new form

func (*Form) AddButton

func (f *Form) AddButton(label string, handler Handler) *Button

AddButton add button to form

func (*Form) AddCheckBox

func (f *Form) AddCheckBox(label string, width int, checked bool) *CheckBox

AddCheckBox add checkbox

func (*Form) AddCloseFunc

func (f *Form) AddCloseFunc(function func(g *gocui.Gui, v *gocui.View) error)

AddCloseFunc add close function

func (*Form) AddHeading

func (f *Form) AddHeading(label string) *HeadingField

AddHeading add heading field to form

func (*Form) AddInputField

func (f *Form) AddInputField(label string, labelWidth, fieldWidth int, initialValue string) *InputField

AddInputField add input field to form

func (*Form) AddRadio

func (f *Form) AddRadio(label string, width int) *Radio

AddRadio add radio

func (*Form) AddSelect

func (f *Form) AddSelect(label string, labelWidth, listWidth int) *Select

AddSelect add select

func (*Form) Close

func (f *Form) Close(g *gocui.Gui, v *gocui.View) error

Close close form

func (*Form) Draw

func (f *Form) Draw()

Draw form

func (*Form) GetButtons

func (f *Form) GetButtons() []*Button

GetButtons get buttons

func (*Form) GetCheckBoxState

func (f *Form) GetCheckBoxState(target string) bool

GetCheckBoxState get checkbox states

func (*Form) GetCheckBoxStates

func (f *Form) GetCheckBoxStates() map[string]bool

GetCheckBoxStates get checkbox states

func (*Form) GetCheckBoxs

func (f *Form) GetCheckBoxs() []*CheckBox

GetCheckBoxs get checkboxs

func (*Form) GetCurrentItem

func (f *Form) GetCurrentItem() int

GetCurrentItem get current item index

func (*Form) GetFieldText

func (f *Form) GetFieldText(target string) string

GetFieldText get form data with field name

func (*Form) GetFieldTexts

func (f *Form) GetFieldTexts() map[string]string

GetFieldTexts form data

func (*Form) GetFormData

func (f *Form) GetFormData() *FormData

GetFormData get form data

func (*Form) GetInputs

func (f *Form) GetInputs() []*InputField

GetInputs get inputs

func (*Form) GetItems

func (f *Form) GetItems() []Component

GetItems get items

func (*Form) GetRadioText

func (f *Form) GetRadioText() string

GetRadioText get radio text

func (*Form) GetRadios

func (f *Form) GetRadios() []*Radio

GetRadios get radios

func (*Form) GetSelectedOpt

func (f *Form) GetSelectedOpt(target string) string

GetSelectedOpt get selected options

func (*Form) GetSelectedOpts

func (f *Form) GetSelectedOpts() map[string]string

GetSelectedOpts get selected options

func (*Form) GetSelectedRadio

func (f *Form) GetSelectedRadio(target string) string

GetSelectedRadio get selected radio

func (*Form) GetSelectedRadios

func (f *Form) GetSelectedRadios() map[string]string

GetSelectedRadios get selected radio

func (*Form) GetSelects

func (f *Form) GetSelects() []*Select

GetSelects get selects

func (*Form) NextItem

func (f *Form) NextItem(g *gocui.Gui, v *gocui.View) error

NextItem to next item

func (*Form) PreItem

func (f *Form) PreItem(g *gocui.Gui, v *gocui.View) error

PreItem to pre item

func (*Form) SetCurrentItem

func (f *Form) SetCurrentItem(index int) *Form

SetCurrentItem set current item index

func (*Form) Validate

func (f *Form) Validate() bool

Validate validate form items

type FormData

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

FormData form data struct

type Handler

type Handler func(g *gocui.Gui, v *gocui.View) error

Handler define handler type

type Handlers

type Handlers map[Key]Handler

Handlers handlers

type HeadingField

type HeadingField struct {
	*gocui.Gui

	*Position
	*Attributes
	// contains filtered or unexported fields
}

HeadingField struct

func NewHeading

func NewHeading(gui *gocui.Gui, label string, x, y int) *HeadingField

NewHeading new heading

func (*HeadingField) AddHandlerOnly

func (c *HeadingField) AddHandlerOnly(key Key, handler Handler)

func (*HeadingField) Close

func (c *HeadingField) Close()

Close closes the heading

func (*HeadingField) Draw

func (c *HeadingField) Draw()

Draw draw label and heading

func (*HeadingField) Focus

func (c *HeadingField) Focus()

func (*HeadingField) GetLabel

func (c *HeadingField) GetLabel() string

GetLabel get heading label

func (*HeadingField) GetPosition

func (c *HeadingField) GetPosition() *Position

GetPosition get heading position

func (*HeadingField) GetType

func (c *HeadingField) GetType() ComponentType

GetType get component type

func (*HeadingField) IsFocusable

func (c *HeadingField) IsFocusable() bool

func (*HeadingField) UnFocus

func (c *HeadingField) UnFocus()

type InputField

type InputField struct {
	*gocui.Gui
	// contains filtered or unexported fields
}

InputField struct

func NewInputField

func NewInputField(gui *gocui.Gui, labelText string, x, y, labelWidth, fieldWidth int) *InputField

NewInputField new input label and field

func (*InputField) AddFieldAttribute

func (i *InputField) AddFieldAttribute(textColor, textBgColor, fgColor, bgColor gocui.Attribute) *InputField

AddFieldAttribute add field colors

func (*InputField) AddHandler

func (i *InputField) AddHandler(key Key, handler Handler) *InputField

AddHandler add keybinding

func (*InputField) AddHandlerOnly

func (i *InputField) AddHandlerOnly(key Key, handler Handler)

AddHandlerOnly add handler not return

func (*InputField) AddLabelAttribute

func (i *InputField) AddLabelAttribute(textColor, textBgColor gocui.Attribute) *InputField

AddLabelAttribute add label colors

func (*InputField) AddMarginLeft

func (i *InputField) AddMarginLeft(left int) *InputField

AddMarginLeft add margin left

func (*InputField) AddMarginTop

func (i *InputField) AddMarginTop(top int) *InputField

AddMarginTop add margin top

func (*InputField) AddValidate

func (i *InputField) AddValidate(errMsg string, validate func(value string) bool) *InputField

AddValidate add input validator

func (*InputField) Close

func (i *InputField) Close()

Close close input field

func (*InputField) Draw

func (i *InputField) Draw()

Draw draw label and field

func (*InputField) Edit

func (i *InputField) Edit(v *gocui.View, key gocui.Key, ch rune, mod gocui.Modifier)

Edit input field editor

func (*InputField) Focus

func (i *InputField) Focus()

Focus focus to input field

func (*InputField) GetFieldText

func (i *InputField) GetFieldText() string

GetFieldText get input field text

func (*InputField) GetLabel

func (i *InputField) GetLabel() string

GetLabel get label text

func (*InputField) GetPosition

func (i *InputField) GetPosition() *Position

GetPosition get input field position

func (*InputField) GetType

func (i *InputField) GetType() ComponentType

GetType get component type

func (*InputField) IsFocusable

func (i *InputField) IsFocusable() bool

func (*InputField) IsValid

func (i *InputField) IsValid() bool

IsValid valid field data will be return true

func (*InputField) SetCursor

func (i *InputField) SetCursor(b bool) *InputField

SetCursor set input field cursor

func (*InputField) SetEditable

func (i *InputField) SetEditable(b bool) *InputField

SetEditable if editmode is true can input

func (*InputField) SetFieldBorder

func (i *InputField) SetFieldBorder() *InputField

SetFieldBorder draw field border

func (*InputField) SetLabelBorder

func (i *InputField) SetLabelBorder() *InputField

SetLabelBorder draw label border

func (*InputField) SetMask

func (i *InputField) SetMask() *InputField

SetMask set input field to mask '*'

func (*InputField) SetMaskKeybinding

func (i *InputField) SetMaskKeybinding(key Key) *InputField

SetMaskKeybinding set or unset input field to mask '*' with key

func (*InputField) SetText

func (i *InputField) SetText(text string) *InputField

SetText set text

func (*InputField) UnFocus

func (i *InputField) UnFocus()

UnFocus un focus

func (*InputField) Validate

func (i *InputField) Validate() bool

Validate validate field

type Key

type Key interface{}

Key define kye type

type Label

type Label struct {
	*Position
	*Attributes
	// contains filtered or unexported fields
}

Label struct

type Margin

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

Margin struct

type Modal struct {
	*gocui.Gui

	*Attributes
	*Position
	// contains filtered or unexported fields
}

Modal struct

func NewModal

func NewModal(gui *gocui.Gui, x, y, w int) *Modal

NewModal new modal

func (*Modal) AddButton

func (m *Modal) AddButton(label string, key Key, handler Handler) *Button

AddButton add button

func (*Modal) Close

func (m *Modal) Close()

Close close modal

func (*Modal) Draw

func (m *Modal) Draw()

Draw draw modal

func (*Modal) GetPosition

func (m *Modal) GetPosition() *Position

GetPosition get modal position

func (*Modal) SetText

func (m *Modal) SetText(text string) *Modal

SetText set text

func (*Modal) SetTextColor

func (m *Modal) SetTextColor(textColor gocui.Attribute) *Modal

SetTextColor set text color

type Mode

type Mode int

Mode radio mode

const (
	// VerticalMode display radio button vertical
	VerticalMode Mode = iota
	// SplitMode display radio button split
	SplitMode
)

type Position

type Position struct {
	X, Y int
	W, H int
}

Position component position

type Radio

type Radio struct {
	*gocui.Gui

	*Position
	*Attributes
	// contains filtered or unexported fields
}

Radio struct

func NewRadio

func NewRadio(gui *gocui.Gui, label string, x, y, w int) *Radio

NewRadio new radio

func (*Radio) AddHandler

func (r *Radio) AddHandler(key Key, handler Handler) *Radio

AddHandler add handler

func (*Radio) AddHandlerOnly

func (r *Radio) AddHandlerOnly(key Key, handler Handler)

AddHandlerOnly add handler only

func (*Radio) AddOption

func (r *Radio) AddOption(name string) *Radio

AddOption add option

func (*Radio) AddOptions

func (r *Radio) AddOptions(names ...string) *Radio

AddOptions add options

func (*Radio) Check

func (r *Radio) Check(g *gocui.Gui, v *gocui.View) error

Check check radio button

func (*Radio) Close

func (r *Radio) Close()

Close close radio

func (*Radio) Draw

func (r *Radio) Draw()

Draw draw radio

func (*Radio) Focus

func (r *Radio) Focus()

Focus focus to radio

func (*Radio) GetLabel

func (r *Radio) GetLabel() string

GetLabel get radio label

func (*Radio) GetPosition

func (r *Radio) GetPosition() *Position

GetPosition get radio position

func (*Radio) GetSelected

func (r *Radio) GetSelected() string

GetSelected get selected radio

func (*Radio) GetType

func (r *Radio) GetType() ComponentType

GetType get component type

func (*Radio) IsChecked

func (r *Radio) IsChecked() bool

IsChecked return check state

func (*Radio) IsFocusable

func (r *Radio) IsFocusable() bool

func (*Radio) SetMode

func (r *Radio) SetMode(mode Mode) *Radio

SetMode set mode SplitMode or VerticalMode

func (*Radio) UnFocus

func (r *Radio) UnFocus()

UnFocus un focus radio

type Select

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

Select struct

func NewSelect

func NewSelect(gui *gocui.Gui, label string, x, y, labelWidth, fieldWidth int) *Select

NewSelect new select

func (*Select) AddAttribute

func (s *Select) AddAttribute(textColor, textBgColor, fgColor, bgColor gocui.Attribute) *Select

AddAttribute add select attribute

func (*Select) AddListHandler

func (s *Select) AddListHandler(key Key, handler Handler) *Select

AddListHandler add list handler

func (*Select) AddOption

func (s *Select) AddOption(opt string) *Select

AddOption add select option

func (*Select) AddOptions

func (s *Select) AddOptions(opts ...string) *Select

AddOptions add select options

func (*Select) Close

func (s *Select) Close()

Close close select

func (*Select) Draw

func (s *Select) Draw()

Draw draw select

func (*Select) Focus

func (s *Select) Focus()

Focus set focus to select

func (*Select) GetSelected

func (s *Select) GetSelected() string

GetSelected get selected option

func (*Select) GetType

func (s *Select) GetType() ComponentType

GetType get component type

func (*Select) UnFocus

func (s *Select) UnFocus()

UnFocus un focus

type Validate

type Validate struct {
	ErrMsg string
	Do     func(value string) bool
}

Validate validate struct

type Validator

type Validator struct {
	*gocui.Gui

	*Position
	// contains filtered or unexported fields
}

Validator validate struct

func NewValidator

func NewValidator(gui *gocui.Gui, name string, x, y, w, h int) *Validator

NewValidator new validator

func (*Validator) AddValidate

func (v *Validator) AddValidate(errMsg string, validate func(value string) bool)

AddValidate add validate

func (*Validator) CloseValidateMsg

func (v *Validator) CloseValidateMsg()

CloseValidateMsg close validate error message

func (*Validator) DispValidateMsg

func (v *Validator) DispValidateMsg()

DispValidateMsg display validate error message

func (*Validator) IsValid

func (v *Validator) IsValid() bool

IsValid if valid return true

func (*Validator) Validate

func (v *Validator) Validate(value string)

Validate validate value

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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