forms

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 7 Imported by: 4 modules, 3 packages

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.

Documentation

Overview

Package forms provides keys.Action-driven forms and confirm dialogs for viewkit terminal UIs.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Confirm

type Confirm struct {
	Title    string
	Message  string
	YesLabel string
	NoLabel  string
	Yes      bool
}

func (*Confirm) Handle

func (c *Confirm) Handle(a keys.Action) Result

func (Confirm) Overlay

func (c Confirm) Overlay(bg string, f layout.Frame, pos ...layout.OverlayPos) string

func (Confirm) Render

func (c Confirm) Render(f layout.Frame) string

type Field

type Field struct {
	Key   string
	Label string
	Kind  FieldKind

	Options []string

	Text     string
	On       bool
	Selected int
	Checked  map[int]bool

	Secret bool
}

func (*Field) Value

func (fd *Field) Value() any

type FieldKind

type FieldKind int
const (
	FieldText FieldKind = iota

	FieldMultiline

	FieldSelect

	FieldMultiselect

	FieldRadio

	FieldToggle
)

type Form

type Form struct {
	Fields []Field
	// contains filtered or unexported fields
}
Example
package main

import (
	"github.com/codyconfer/viewkit/forms"
	"github.com/codyconfer/viewkit/keys"
	"github.com/codyconfer/viewkit/layout"
)

func main() {
	fm := forms.NewForm(
		forms.Field{Key: "name", Label: "Name", Kind: forms.FieldText},
		forms.Field{
			Key:     "risk",
			Label:   "Risk",
			Kind:    forms.FieldSelect,
			Options: []string{"low", "med", "high"},
		},
		forms.Field{Key: "auto", Label: "Auto", Kind: forms.FieldToggle},
	)

	fm.Insert("example")
	fm.Handle(keys.Down)
	fm.Handle(keys.Right)
	fm.Handle(keys.Down)
	fm.Handle(keys.Confirm)

	_ = fm.Values()
	_ = fm.Render(layout.NewFrame(60), "SETTINGS")
}

func NewForm

func NewForm(fields ...Field) *Form

func (*Form) Focused

func (fm *Form) Focused() *Field

func (*Form) Handle

func (fm *Form) Handle(a keys.Action) bool

func (*Form) Insert

func (fm *Form) Insert(s string)

func (*Form) Overlay

func (fm *Form) Overlay(bg string, f layout.Frame, title string, pos ...layout.OverlayPos) string

func (*Form) Render

func (fm *Form) Render(f layout.Frame, title string) string

func (*Form) Values

func (fm *Form) Values() map[string]any

type Result

type Result int
const (
	Pending Result = iota

	Submitted

	Cancelled
)

Jump to

Keyboard shortcuts

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