common

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const CustomPortsDescription = "e.g. 22,80,443,8000-9000 (valid: 1-65535)"
View Source
const HelpSeparator = " • "

Variables

View Source
var (
	TitleStyle = lipgloss.NewStyle().
				Bold(true).
				Foreground(Color.Info)

	// Help overlay styles
	HelpBoxStyle = lipgloss.NewStyle().
					Border(lipgloss.RoundedBorder()).
					BorderForeground(Color.Selection).
					Padding(0, 1).
					Foreground(Color.Info)

	HelpTitleStyle = lipgloss.NewStyle().
					Foreground(Color.Selection).
					Bold(true)

	HelpIconStyle = lipgloss.NewStyle().
					Foreground(Color.Selection).
					Bold(true)

	// Common text styles
	HelpTextStyle = lipgloss.NewStyle().
					Foreground(Color.Help)

	InfoTextStyle = lipgloss.NewStyle().
					Foreground(Color.Help)

	ErrorStyle = lipgloss.NewStyle().
				Foreground(Color.Error).
				Bold(true)

	HighlightStyle = lipgloss.NewStyle().
					Foreground(Color.Selection).
					Bold(true)

	MutedStyle = lipgloss.NewStyle().
				Foreground(Color.Help).
				Italic(true)

	ItalicHelpStyle = lipgloss.NewStyle().
					Foreground(Color.Help).
					Italic(true)

	ProgressGreenStyle = lipgloss.NewStyle().
						Foreground(Color.Scanned)

	WarningStyle = lipgloss.NewStyle().
					Foreground(Color.Scanning).
					Bold(true)

	// Card styles - shared rounded-border card look used across views
	CardStyle = lipgloss.NewStyle().
				Border(lipgloss.RoundedBorder()).
				BorderForeground(Color.Help)

	SelectedCardStyle = lipgloss.NewStyle().
						Border(lipgloss.RoundedBorder()).
						BorderForeground(Color.Selection)

	FolderStyle = lipgloss.NewStyle().
				Foreground(Color.Folder)
)
View Source
var Color = struct {
	Black     color.Color
	Selection color.Color
	Help      color.Color
	Info      color.Color
	Error     color.Color
	Scanned   color.Color
	Scanning  color.Color
	Folder    color.Color
}{
	Black:     lipgloss.Black,
	Selection: lipgloss.Yellow,
	Help:      lipgloss.BrightBlack,
	Info:      lipgloss.White,
	Error:     lipgloss.Red,
	Scanned:   lipgloss.Green,
	Scanning:  lipgloss.Cyan,
	Folder:    lipgloss.Blue,
}

Color holds the global color palette used throughout the application. Uses lipgloss v2 ANSI 4-bit constants so colors adapt to any terminal theme.

Functions

func Backspace

func Backspace(value string, cursor int) (string, int)

Backspace removes the character before the cursor.

func ClampCursor

func ClampCursor(cursor, valueLen int) int

ClampCursor ensures cursor position is within valid bounds [0, valueLen].

func FormTheme

func FormTheme() *huh.Styles

FormTheme returns a custom huh theme using only ANSI 16 colors so it follows the user's terminal theme.

func GetHelpItemAt

func GetHelpItemAt(layout *HelpLineLayout, x, relY int) int

GetHelpItemAt returns the item index at (x, relY) within the helpline, where relY=0 is the first helpline row. Returns -1 on miss.

func InsertRunes

func InsertRunes(value string, cursor int, runes []rune) (string, int)

InsertRunes inserts runes at cursor position, filtering to valid port characters. Valid characters: digits (0-9), comma (,), dash (-). Enforces validation rules per token (max 5 digits, single dash).

func IsMouseMsg added in v0.7.0

func IsMouseMsg(msg tea.Msg) bool

IsMouseMsg reports whether msg is any type of mouse message.

func MouseXY added in v0.7.0

func MouseXY(msg tea.Msg) (tea.Mouse, bool)

MouseXY extracts Mouse data from any mouse message type.

func MoveCursorLeft

func MoveCursorLeft(cursor int) int

MoveCursorLeft moves cursor one position left, clamped to 0.

func MoveCursorRight

func MoveCursorRight(cursor, valueLen int) int

MoveCursorRight moves cursor one position right, clamped to valueLen.

func NewCustomPortsInput

func NewCustomPortsInput() textinput.Model

func RenderHelpLine

func RenderHelpLine(layout *HelpLineLayout, navPrefix string, maxWidth int, hoveredIndex int) string

RenderHelpLine renders the helpline with hover highlighting on hoveredIndex (-1 = none).

func RenderHelpOverlay

func RenderHelpOverlay(view string, config HelpConfig) string

RenderHelpOverlay renders a centered help overlay with consistent styling

func WrapWords

func WrapWords(s string, maxWidth int) string

Types

type CustomPortInput

type CustomPortInput struct {
	Input  textinput.Model
	Ready  bool
	Value  string
	Cursor int
}

CustomPortInput manages custom port text entry state.

func (CustomPortInput) HandleKey

func (c CustomPortInput) HandleKey(action PortInputAction, keyMsg tea.KeyPressMsg) (CustomPortInput, tea.Cmd)

HandleKey dispatches key actions (move, delete, insert) or falls through to textinput.

func (CustomPortInput) Prepare

func (c CustomPortInput) Prepare(focused bool) (CustomPortInput, tea.Cmd)

Prepare initializes or re-syncs the textinput, optionally focusing it.

func (CustomPortInput) SetValue

func (c CustomPortInput) SetValue(v string) CustomPortInput

SetValue replaces value and moves cursor to end.

func (CustomPortInput) UpdateNonKey

func (c CustomPortInput) UpdateNonKey(msg tea.Msg) (CustomPortInput, tea.Cmd)

UpdateNonKey forwards non-keyboard messages to the textinput.

type HelpConfig

type HelpConfig struct {
	Title      string
	Content    []string
	Width      int // Width of help box (default 56)
	ViewWidth  int // Width of the view/terminal for centering
	ViewHeight int // Height of the view/terminal for placement
}

HelpConfig defines the content and appearance of a help overlay

type HelpItem

type HelpItem struct {
	Text   string
	Action int // view-specific action value
	StartX int // starting X position in the rendered line
	EndX   int // ending X position in the rendered line
	Line   int // line index in wrapped helpline (0-based)
}

HelpItem represents a clickable help item with its rendered position. Action is an opaque int — each view casts it to its own action type.

type HelpLineLayout

type HelpLineLayout struct {
	Items     []HelpItem
	LineCount int
}

HelpLineLayout stores the computed layout for a helpline.

func BuildHelpLineLayout

func BuildHelpLineLayout(items []HelpItem, navPrefix string, maxWidth int) *HelpLineLayout

BuildHelpLineLayout computes item positions for the given items and navPrefix, wrapping at maxWidth. navPrefix is the non-clickable leading text (e.g. "←/→/↑/↓").

type HelpMouseResult added in v0.7.0

type HelpMouseResult struct {
	NewHoveredItem int  // updated hover index (-1 = none)
	ClickedAction  int  // action value of clicked item, or -1 if no click
	Consumed       bool // true if the click was in the help-line area
}

HelpMouseResult describes what happened when a mouse event hit the help line.

func HandleHelpLineMouse added in v0.7.0

func HandleHelpLineMouse(mouse tea.Mouse, msg tea.Msg, items []HelpItem, prefix string, helpLineY, maxWidth int) HelpMouseResult

HandleHelpLineMouse processes a mouse event against the help line area. It updates hover state on any mouse event and detects left-clicks on items.

type PortInputAction

type PortInputAction struct {
	MoveLeft    bool
	MoveRight   bool
	MoveHome    bool
	MoveEnd     bool
	Backspace   bool
	DeleteAll   bool
	InsertRunes bool
}

PortInputAction describes which editing operation a key maps to.

func PortInputActionFromKey

func PortInputActionFromKey(key string, isRunes bool) PortInputAction

PortInputActionFromKey maps a key string to an action.

Jump to

Keyboard shortcuts

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