prompt

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CenterRow

func CenterRow(row string, width int) string

CenterRow left-pads a row so it appears centered within the given width.

func ComposeContent

func ComposeContent(m ContentModel) string

ComposeContent builds prompt body content from already-rendered parts.

func FocusLineOffset

func FocusLineOffset(optionFocus bool, optionCursor, optionCount int, hasInput bool) int

FocusLineOffset returns the content line offset of the focused element within prompt content laid out by ComposeContent and RenderChoiceGroups.

When optionFocus is true and optionCount > 0, it returns the line of the option at optionCursor. Otherwise, if hasInput is true, it returns the line where the input field begins. Returns -1 when there is nothing to scroll to.

func FocusOptionsCursor

func FocusOptionsCursor(optionCount int, reverse bool) int

FocusOptionsCursor returns the cursor position to use when entering options.

func RenderChoiceGroups

func RenderChoiceGroups(
	groups []ChoiceGroup,
	selected []int,
	activeGroup int,
	focus bool,
	styles ChoiceGroupStyles,
) string

RenderChoiceGroups renders labeled groups of mutually exclusive choices.

func RenderHintLines

func RenderHintLines(lines [][]Hint, gap string, keyStyle, textStyle lg.Style) string

RenderHintLines renders one or more lines of key/text hints.

func RenderScrollable

func RenderScrollable(m ScrollableModel) string

RenderScrollable renders content inside a styled box, using a viewport and scrollbar when the content exceeds the available height.

func StepChoice

func StepChoice(current, choiceCount, delta int, wrap bool) int

StepChoice moves or cycles the selected value within a choice group.

Types

type Choice

type Choice struct {
	Label string
}

type ChoiceGroup

type ChoiceGroup struct {
	Label   string
	Choices []Choice
}

type ChoiceGroupStyles

type ChoiceGroupStyles struct {
	Label          lg.Style
	SelectedActive lg.Style
	Selected       lg.Style
	Active         lg.Style
	Inactive       lg.Style
	ChoiceGap      string
	GroupGap       string
}

type ContentModel

type ContentModel struct {
	Prompt       string
	Options      string
	FieldLabel   string
	FieldBody    string
	Hints        string
	IncludeHints bool
	HasField     bool
}

type Hint

type Hint struct {
	Key  string
	Text string
}
type NavDirection int
const (
	NavUp NavDirection = iota
	NavDown
	NavTab
	NavShiftTab
)
type NavResult struct {
	Cursor      int
	MoveToInput bool
}
func NavigateOptions(cursor, optionCount int, hasInput bool, dir NavDirection) NavResult

NavigateOptions computes the next options cursor or whether focus should move from the option list into the input field.

type ScrollableModel

type ScrollableModel struct {
	BoxStyle        lg.Style
	BoxWidth        int
	Content         string
	ScrollbarConfig scrollbar.Config
	View            viewport.Model
	ViewportHeight  int
	ViewWidth       int
	Styles          Styles
}

type State

type State struct {
	OptFocus  bool
	OptCursor int
	OptValues []int
	Yes       bool
}

State holds generic interaction state for a prompt with optional choice groups and a yes/no selection. Apps embed this alongside their own app-specific fields (textarea, viewport, action semantics, etc.).

func (*State) EnterOptions

func (s *State) EnterOptions(optionCount int, reverse bool)

EnterOptions sets focus to the option list and positions the cursor at the first or last option depending on reverse.

func (*State) FocusLine

func (s *State) FocusLine(optionCount int, hasInput bool) int

FocusLine returns the content line offset of the currently focused element, for use with viewport scroll-to-visible. Returns -1 when there is nothing to scroll to.

func (*State) Navigate

func (s *State) Navigate(dir NavDirection, optionCount int, hasInput bool) NavResult

Navigate moves the option cursor in the given direction and returns whether focus should move to the input field. The cursor is updated in-place when the result does not move to input.

func (*State) Step

func (s *State) Step(choiceCount, delta int, wrap bool)

Step moves or cycles the selected value for the currently focused option group.

func (*State) ToggleYes

func (s *State) ToggleYes()

ToggleYes flips the yes/no selection.

type Styles

type Styles struct {
	Scrollbar scrollbar.Styles
}

Jump to

Keyboard shortcuts

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