ui

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	QRLevelL = qr.L // ~7% redundancy
	QRLevelM = qr.M // ~15% redundancy (default)
	QRLevelH = qr.H // ~30% redundancy
)

Constants re-exported so callers can specify ECC level without importing rsc.io/qr.

View Source
const (
	KB = 1024
	MB = 1024 * 1024
)

Variables

View Source
var DefaultIconSet = IconSet{
	Success:         "✓",
	Warning:         "⚠",
	Error:           "✗",
	Info:            "ℹ",
	Arrow:           "→",
	Bullet:          "•",
	Checkbox:        "☐",
	CheckboxChecked: "☒",
	Folder:          "📁",
	File:            "📄",
	Key:             "🔑",
	Lock:            "🔒",
	Dot:             "●",
	Dash:            "─",
	Pipe:            "│",
}
View Source
var DefaultTheme = Theme{
	Primary:   compat.AdaptiveColor{Dark: lipgloss.Color("#c9d8e8"), Light: lipgloss.Color("#1e293b")},
	Secondary: compat.AdaptiveColor{Dark: lipgloss.Color("#5a7490"), Light: lipgloss.Color("#64748b")},
	Faint:     compat.AdaptiveColor{Dark: lipgloss.Color("#3d5068"), Light: lipgloss.Color("#94a3b8")},
	Accent:    compat.AdaptiveColor{Dark: lipgloss.Color("#3b82f6"), Light: lipgloss.Color("#2563eb")},
	Success:   compat.AdaptiveColor{Dark: lipgloss.Color("#22c55e"), Light: lipgloss.Color("#16a34a")},
	Warn:      compat.AdaptiveColor{Dark: lipgloss.Color("#eab308"), Light: lipgloss.Color("#ca8a04")},
	Danger:    compat.AdaptiveColor{Dark: lipgloss.Color("#ef4444"), Light: lipgloss.Color("#dc2626")},
	Value:     compat.AdaptiveColor{Dark: lipgloss.Color("#e8f2ff"), Light: lipgloss.Color("#0f172a")},
	Border:    compat.AdaptiveColor{Dark: lipgloss.Color("#1a2232"), Light: lipgloss.Color("#dde4ed")},
}

Functions

func DecodePNG added in v0.1.0

func DecodePNG(data []byte) (image.Image, error)

DecodePNG converts raw PNG bytes to image.Image for go-termimg rendering. Usage: img, _ := termimg.New(qr.DecodePNG(result.PNG))

Types

type DialogStyle added in v0.1.0

type DialogStyle int
const (
	DialogDanger DialogStyle = iota
	DialogWarning
	DialogInfo
	DialogSuccess
)

type HelpCmd

type HelpCmd struct {
	Cmd  string
	Desc string
	URL  string
}

type HelpSection

type HelpSection struct {
	Title    string
	Commands []HelpCmd
}

type IconSet

type IconSet struct {
	Success         string
	Warning         string
	Error           string
	Info            string
	Arrow           string
	Bullet          string
	Checkbox        string
	CheckboxChecked string
	Folder          string
	File            string
	Key             string
	Lock            string
	Dot             string
	Dash            string
	Pipe            string
}

type InputConfig added in v0.1.0

type InputConfig struct {
	Title       string
	Placeholder string
	Description string
	Width       int
}

type KV

type KV struct {
	Label string
	Value string
}

type LinkCell

type LinkCell struct {
	Text string
	URL  string
}

type ListItem added in v0.1.0

type ListItem struct {
	Text string
	URL  string
}

type Option

type Option func(*UI)

func WithIcons

func WithIcons(i IconSet) Option

func WithIndent

func WithIndent(n int) Option

func WithReader added in v0.1.0

func WithReader(r io.Reader) Option

func WithTheme

func WithTheme(t Theme) Option

func WithWriter

func WithWriter(w io.Writer) Option

type QR added in v0.1.0

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

QR represents an encoded QR code ready for format generation.

func NewQr added in v0.1.0

func NewQr(content string, level qr.Level) (*QR, error)

NewQr creates a new QR code from content and ECC level.

func (*QR) Result added in v0.1.0

func (q *QR) Result(scale int) *QRResult

Result generates all output formats. Scale controls PNG/SVG resolution. Typical scale values: 4-8 for terminal display, 10+ for print/export.

type QRResult added in v0.1.0

type QRResult struct {
	// Terminal is compact UTF-8 half-block art — fallback if image protocols fail.
	Terminal string
	// SVG is a self-contained <svg> element (no DOCTYPE / namespace).
	SVG string
	// PNG is raw PNG bytes — pass directly to go-termimg for rendering.
	PNG []byte
}

QRResult holds all representations of a generated QR code.

type RegistrationResult added in v0.1.0

type RegistrationResult struct {
	Username     string
	Password     string
	PasswordHash []byte
}

type TreeNode

type TreeNode struct {
	Label    string
	Value    string
	URL      string
	Icon     string
	Children []TreeNode
}

type UI

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

func New

func New(opts ...Option) *UI

func (*UI) BackupDone

func (u *UI) BackupDone(path string, fileCount int) *UI

func (*UI) BackupStart

func (u *UI) BackupStart(encrypted bool) *UI

func (*UI) Blank

func (u *UI) Blank() *UI

func (*UI) Confirm added in v0.1.0

func (u *UI) Confirm(prompt string, helpText ...string) (bool, error)

func (*UI) ConfirmDefault added in v0.1.0

func (u *UI) ConfirmDefault(prompt string, defaultYes bool, helpText ...string) (bool, error)

func (*UI) DialogBox added in v0.1.0

func (u *UI) DialogBox(style DialogStyle, title string, items []string, footer string) *UI

func (*UI) Divider

func (u *UI) Divider() *UI

func (*UI) ErrorHint

func (u *UI) ErrorHint(problem, hint string) *UI

func (*UI) ErrorLine added in v0.1.0

func (u *UI) ErrorLine(msg string) *UI
func (u *UI) FileLink(path string, isDir bool) string

func (*UI) Flush

func (u *UI) Flush()

func (*UI) FlushAfter added in v0.1.0

func (u *UI) FlushAfter(fn func())

FlushAfter is an alias for Render kept for backward compatibility.

func (*UI) HelpScreen

func (u *UI) HelpScreen(sections []HelpSection) *UI

func (*UI) Image added in v0.1.0

func (u *UI) Image(pngData []byte) error

func (*UI) InfoLine

func (u *UI) InfoLine(msg string) *UI

func (*UI) InitSuccess

func (u *UI) InitSuccess(configFile, adminUser, adminPassword string, nextSteps []ListItem)

func (*UI) Input added in v0.1.0

func (u *UI) Input(cfg InputConfig) (string, error)

func (*UI) KeyValue

func (u *UI) KeyValue(label, value string) *UI

func (*UI) KeyValueBlock

func (u *UI) KeyValueBlock(title string, pairs []KV) *UI

func (*UI) KeyValueFile

func (u *UI) KeyValueFile(label, path string, isDir bool) *UI
func (u *UI) KeyValueLink(label, text, url string) *UI
func (u *UI) Link(text, url string) string

func (*UI) LinkInline

func (u *UI) LinkInline(text, url string) string
func (u *UI) LinkList(title string, items []ListItem) *UI

func (*UI) Password added in v0.1.0

func (u *UI) Password(prompt string, opts ...prompter.Option) (*prompter.Result, error)

func (*UI) PasswordConfirm added in v0.1.0

func (u *UI) PasswordConfirm(prompt string) (*prompter.Result, error)

func (*UI) PasswordConfirmRequired added in v0.1.0

func (u *UI) PasswordConfirmRequired(prompt string) (*prompter.Result, error)

func (*UI) PasswordConfirmWithHint added in v0.1.0

func (u *UI) PasswordConfirmWithHint(prompt, hint string) (*prompter.Result, error)

func (*UI) PasswordMinLength added in v0.1.0

func (u *UI) PasswordMinLength(prompt string, minLen int, errorMsg string) (*prompter.Result, error)

func (*UI) PasswordRequired added in v0.1.0

func (u *UI) PasswordRequired(prompt string) (*prompter.Result, error)

func (*UI) PasswordRequiredWithHint added in v0.1.0

func (u *UI) PasswordRequiredWithHint(prompt, hint string) (*prompter.Result, error)

func (*UI) PasswordWithHint added in v0.1.0

func (u *UI) PasswordWithHint(prompt, hint string, confirm bool, opts ...prompter.Option) (*prompter.Result, error)

func (*UI) Println

func (u *UI) Println(s string) *UI

func (*UI) Prompt added in v0.1.0

func (u *UI) Prompt(prompt string, description ...string) string

func (*UI) PromptInline added in v0.1.0

func (u *UI) PromptInline(prompt string) string

func (*UI) QR added in v0.1.0

func (u *UI) QR(content string) *QRResult

func (*UI) RegistrationForm added in v0.1.0

func (u *UI) RegistrationForm(title, description string) (*RegistrationResult, error)

func (*UI) Render added in v0.1.0

func (u *UI) Render(fn func())

func (*UI) Reset

func (u *UI) Reset()

func (*UI) RestoreDone

func (u *UI) RestoreDone(count int) *UI

func (*UI) SecretBox

func (u *UI) SecretBox(label, value string) *UI

func (*UI) SectionHeader

func (u *UI) SectionHeader(label string) *UI

func (*UI) ServiceStatus

func (u *UI) ServiceStatus(status, pid, configPath string) *UI

func (*UI) SimpleUserPass added in v0.1.0

func (u *UI) SimpleUserPass() (username, password string, err error)

func (*UI) Sprint

func (u *UI) Sprint(s string) string

func (*UI) StatusBadge

func (u *UI) StatusBadge(status string) *UI

func (*UI) Step

func (u *UI) Step(state, msg string) *UI
func (u *UI) StepWithLink(state, msg, url string) *UI

func (*UI) String

func (u *UI) String() string

func (*UI) SuccessLine

func (u *UI) SuccessLine(msg string) *UI

func (*UI) Table

func (u *UI) Table(headers []string, rows [][]string) *UI
func (u *UI) TableWithLinks(headers []string, rows [][]interface{}) *UI

func (*UI) Theme

func (u *UI) Theme() Theme

func (*UI) Tree

func (u *UI) Tree(root string, nodes []TreeNode) *UI

func (*UI) TreeWithFiles

func (u *UI) TreeWithFiles(rootPath string, nodes []TreeNode) *UI

func (*UI) WarnLine

func (u *UI) WarnLine(msg string) *UI

func (*UI) Welcome

func (u *UI) Welcome(name, description, version, date, banner string)

type Viewer

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

Viewer renders directory contents using the ui theme. Two modes:

horizontal=true  — compact grid (used when dropping into a shell)
horizontal=false — lipgloss/tree with one level of expansion

func NewViewer

func NewViewer() *Viewer

NewViewer creates a Viewer with default UI settings.

func NewViewerWithUI

func NewViewerWithUI(u *UI) *Viewer

NewViewerWithUI creates a Viewer using an existing UI instance.

func (*Viewer) Show

func (v *Viewer) Show(dir string, horizontal bool)

Show renders directory contents.

Jump to

Keyboard shortcuts

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