ugform

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 14, 2022 License: MIT Imports: 6 Imported by: 1

README

ugform

Provides primitive forms and textboxes to use with gdadamore/tcell

Documentation

Index

Constants

This section is empty.

Variables

Loggo is the global logger. Set this to a log15 logger from your main to incorporate into main logfile. Otherwise log messages are discarded

Functions

func AddSampleTextBoxes

func AddSampleTextBoxes(nf *Form) (err error)

AddSampleTextBoxes takes an existing form and then adds some basic sample textBoxes

func StyleCursor

func StyleCursor(bgcolor string) (style tcell.Style)

StyleCursor is a helper function that takes a single bgcolor input and returns a tcell Style. Usefull for remembering that setting foreground on a cursor is pointless because no text is ever displayed within a cursor.

func StyleFill

func StyleFill(bgcolor string) (style tcell.Style)

StyleFill is a helper function that takes a single bgcolor input and returns a tcell Style. Usefull for remembering that setting foreground on a textbox fill is pointless because no text is ever displayed using that style

func StyleHelper

func StyleHelper(fgcolor, bgcolor string) (style tcell.Style)

StyleHelper takes a foreground and background color string and converts it to a tcell Style struct

Types

type AddTextBoxInput

type AddTextBoxInput struct {
	// Name of the textbox which will be included
	// when collecting results
	Name string

	// Description of the textbox which can be shown to the user
	// if desired which will be displayed to the left of the
	// actual textBox. This will be drawn relative to the PositionX
	// of the textBox itself so plan ahead in your design.
	Description string

	// The DefaultValue will be pre-populated if desired
	DefaultValue string

	// TabOrder of the textbox for this form. Must be unique
	// within a form or unstable tab behavior could result
	TabOrder int

	// PositionX is the x-axis position of the textbox
	PositionX int

	// PositionY is the y-axis position of the textbox
	PositionY int

	// Width is the width of the textbox. Values typed into
	// the textbox have virtually unlimited length but only
	// width number of chars will be displayed to the
	// user so provide enough room for comfortable usage
	Width int

	// Height is the height of the textbox. Currently only one
	// line is supported but you could display a taller box if
	// you wanted to I guess
	Height int

	// tcell Style to use for cursor color. Setting the foreground
	// of the Cursor is pointless as it never contains text.
	StyleCursor tcell.Style

	// tcell Style to use for textbox fill color. Setting the
	// foreground of Fill is pointless as it never contains text
	StyleFill tcell.Style

	// tcell Style to use for text color within the textbox.
	// You probably want StyleText bgcolor to match
	// StyleFill's bgcolor.
	StyleText tcell.Style

	// tcell Style for the textbox's description.
	// This uses both foreground and background.
	StyleDescription tcell.Style

	// Whether or not to show the description to the user.
	// This gets written out as PositionX minus length of
	// description so design accordingly.
	ShowDescription bool

	// Whether or not this textBox has focus when the form's
	// polling method is activated. The last textbox to be
	// added to the form that has this set to true will be the
	// first one with focus. If no focus is specified then one
	// will be selected at random.
	HasFocus bool

	// Indicates whether or not this textbox is a password
	// field which will mask it's contents while typing.
	Password bool
}

AddTextBoxInput provides all the input parameters for the AddTextBox constructor

type Form

type Form struct {
	// Optional: name for this form. Useful for managing
	// lists of forms for example.
	Name         string
	SubmitAction interface{}
	// contains filtered or unexported fields
}

Form contains properties and methods for interacting with its associated text boxes.

func NewForm

func NewForm(s tcell.Screen) (f *Form)

NewForm instantiates a new form and returns a pointer to which textBoxes can be added and the other various Form methods can be used. Once a Form is created and populated with textboxes using the AddTextBox method then the Start() method should be called followed by the Poll() method.

func (*Form) AddTextBox

func (f *Form) AddTextBox(in *AddTextBoxInput) (err error)

AddTextBox is a constructor for adding a new textBox to the form paying special attention to setting up tabOrder, instantiating contents, and setting focus. The last box to be added that has the hasFocus property set will retain the focus.

func (*Form) ClearShiftXY

func (f *Form) ClearShiftXY(x, y int)

Clears the screen then calls the ShiftXY function then redraws

func (*Form) Collect

func (f *Form) Collect() (results map[string]string)

Collect returns a map of the name and contents of all of the form's textboxes.

func (*Form) Poll

func (f *Form) Poll(ctx context.Context, interrupt chan struct{}, submit chan string)

Poll handles the keyboard events related to the form. Ideally you would cede control over to the Form's polling loop and trust it to return control back to another polling loop. It takes an interrupt channel parameter which you should pass it and then have your main polling loop block waiting for the form's interrupt channel to close.

func (*Form) ShiftXY

func (f *Form) ShiftXY(x, y int)

ShiftXY shifts all coordinates within the form by x and y pixels. This is useful when you're drawing forms relative to other elements on the screen. This method will not clear the screen so if that's desired you should do it manually.

func (*Form) Start

func (f *Form) Start() (err error)

Start activates all of the form's components and renders to the provided screen. If no focus is specified then focus is randomly selected.

Jump to

Keyboard shortcuts

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