utils

package
v1.7.2 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 11 Imported by: 1 module, 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.

Documentation

Index

Constants

View Source
const FramedTextDefaultTermWidthPadding = 10

Variables

This section is empty.

Functions

func CenterText

func CenterText(s string, width int) string

func CutTextForWidth added in v1.7.0

func CutTextForWidth(width int, text string) string

func FramedTextList

func FramedTextList(frameColor, header, postfix string, text []string) string

func FramedTextMap

func FramedTextMap(frameColor, header, postfix string, text map[string]string) string

func FramedTextMapWithPadding added in v1.7.0

func FramedTextMapWithPadding(frameColor, header, postfix string, padding int, text map[string]string) string

func GetTermWidth added in v1.7.0

func GetTermWidth() int

returns -1 if has error

Types

type DialogueFormat

type DialogueFormat struct {
	Text string
	Type DialogueType
}

DialogueFormat holds the prompt text and interaction mode for a dialogue.

func NewDialogue

func NewDialogue(dtype DialogueType, prompt string) *DialogueFormat

NewDialogue creates a DialogueFormat with the given type and prompt text.

func (*DialogueFormat) GetVariantByArrows

func (df *DialogueFormat) GetVariantByArrows(variants []string) (string, error)

GetVariantByArrows displays an arrow-navigable menu and returns the chosen item.

func (*DialogueFormat) GetVariantByInput

func (df *DialogueFormat) GetVariantByInput(variants []string) (string, error)

GetVariantByInput reads a line from stdin and validates it against allowed variants.

func (*DialogueFormat) Run

func (df *DialogueFormat) Run(variants []string) (string, error)

Run executes the dialogue and returns the selected variant.

func (*DialogueFormat) RunCheckVariant

func (df *DialogueFormat) RunCheckVariant(variants []string, variant string) (bool, error)

RunCheckVariant runs the dialogue and reports whether the result matches the expected variant.

type DialogueType

type DialogueType int

DialogueType represents the mode of user interaction.

const (
	// ArrowsDialogueType enables keyboard arrow navigation.
	ArrowsDialogueType DialogueType = iota
	// InputDialogueType reads a typed string from stdin.
	InputDialogueType
)

type Rewriter

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

Rewriter provides in-place terminal output rewriting using ANSI escape codes.

func NewRewriter

func NewRewriter() *Rewriter

func (*Rewriter) Write

func (r *Rewriter) Write(text string)

Write replaces the previously written text with new content without scrolling.

Jump to

Keyboard shortcuts

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