util

package
v2.16.5 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MeetURL        = "https://meet.livekit.io/custom"
	ConsoleURLPath = "/projects/%s/agents/console/?"
)

Variables

View Source
var (

	// Theme is the huh form theme for the active color theme.
	Theme *huh.Theme

	Fg              lipgloss.AdaptiveColor
	FormBaseStyle   lipgloss.Style
	FormHeaderStyle lipgloss.Style
)

Active theme state. Populated by applyTheme; switched once at startup via SetTheme. These are package-level so existing call sites (util.Theme, util.Accented, util.Fg, …) keep working; they are read at render time, which always happens after the theme is selected.

View Source
var (
	OpenFlag = &cli.StringFlag{
		Name:  "open",
		Usage: fmt.Sprintf("Open relevant `APP` in browser, supported options: %v", options),
		Validator: func(input string) error {
			if !slices.Contains(options, input) {
				return fmt.Errorf("invalid open target: %s, supported options: %v", input, options)
			}
			return nil
		},
	}
)

ValidThemes lists the selectable theme names, for validation and help text.

Functions

func Accent added in v2.16.5

func Accent() lipgloss.TerminalColor

func Accented added in v2.4.5

func Accented(text string) string

Accented renders text in the active theme's title style (brand color under livekit).

func Brand added in v2.16.5

func Brand() lipgloss.TerminalColor

Semantic color accessors. They read the active palette at call time, so they reflect the selected theme even when used to build styles lazily.

func Confirm added in v2.16.5

func Confirm() *huh.Select[bool]

Confirm is a yes/no select styled by the active theme.

func CopyFile

func CopyFile(src, dest string) error

Safely copy a file across filesystems, preserving permissions

func CreateTable

func CreateTable() *table.Table

func Dimmed added in v2.4.5

func Dimmed(text string) string

Dimmed renders text in the active theme's muted/description style.

func EllipsizeTo

func EllipsizeTo(str string, maxLength int) string

func Error added in v2.16.5

func Error() lipgloss.TerminalColor

func ExpandTemplate added in v2.4.13

func ExpandTemplate(template string) string

func ExtractSubdomain added in v2.4.6

func ExtractSubdomain(url string) string

func FileExists added in v2.5.0

func FileExists(dir fs.FS, filename string) bool

func HashString

func HashString(str string) (string, error)

func MapStrings

func MapStrings(strs []string, fn func(string) string) []string

func MoveDir

func MoveDir(src, dest string) error

Safely move a directory across filesystems, preserving permissions

func OpenInConsole added in v2.16.1

func OpenInConsole(dashboardURL, projectId string, params *ConsoleURLParams) error

func OpenInMeet added in v2.4.13

func OpenInMeet(livekitURL, token string) error

func PrintJSON

func PrintJSON(obj any)

func PrintJSONTo added in v2.15.1

func PrintJSONTo(w io.Writer, obj any) error

func SetTheme added in v2.16.5

func SetTheme(name string) error

SetTheme selects the active theme by name. An empty name resolves to the default. It returns an error for any other unrecognized name (used to validate `lk set-theme`).

func Success added in v2.16.5

func Success() lipgloss.TerminalColor

func ToUnixPath added in v2.5.2

func ToUnixPath(p string) string

Converts a path (possibly Windows-style) to a Unix-style path.

func URLSafeName

func URLSafeName(projectURL string) (string, error)

func UseTempPath

func UseTempPath(permanentPath string) (string, func() error, func() error)

Provides a temporary path, a function to relocate it to a permanent path, and a function to clean up the temporary path that should always be deferred in the case of a failure to relocate.

func Warning added in v2.16.5

func Warning() lipgloss.TerminalColor

func WrapToLines

func WrapToLines(input string, maxLineLength int) []string

func WrapWith

func WrapWith(wrap string) func(string) string

Types

type ConsoleURLParams added in v2.16.1

type ConsoleURLParams struct {
	AgentName    string            `url:"agentName,omitempty"`
	JobMetadata  string            `url:"jobMetadata,omitempty"`
	RoomName     string            `url:"roomName,omitempty"`
	RoomMetadata string            `url:"roomMetadata,omitempty"`
	Identity     string            `url:"identity,omitempty"`
	Metadata     string            `url:"metadata,omitempty"`
	Attributes   map[string]string `url:"attributes,omitempty"`
	Hidden       bool              `url:"hidden,omitempty"`
	AutoStart    bool              `url:"autoStart,omitempty"`
}

type OpenTarget added in v2.4.13

type OpenTarget string
const (
	OpenTargetMeet    OpenTarget = "meet"
	OpenTargetConsole OpenTarget = "console"
)

type Printer added in v2.16.5

type Printer struct {
	Out   io.Writer // primary output: data the user might pipe or redirect
	Err   io.Writer // status, warnings, diagnostics
	Quiet bool      // suppresses Status (warnings and errors still print)
	// contains filtered or unexported fields
}

Printer is a single sink for human-facing CLI output. One instance per process is initialized from the root command and reused everywhere, so all status, warning, and result lines share consistent streams and gating.

func NewPrinter added in v2.16.5

func NewPrinter(out, err io.Writer, quiet bool) *Printer

NewPrinter builds a Printer targeting the given writers. Pass nil to default to os.Stdout / os.Stderr; this is the path tests use with bytes.Buffer.

func (*Printer) Await added in v2.16.5

func (p *Printer) Await(title string, ctx context.Context, action func(ctx context.Context) error) error

Await runs action while showing a spinner, then returns the action's error.

The spinner is decoration: it only animates when the Printer targets an interactive terminal and is not in quiet mode. Otherwise Await emits the title once as a plain status line (itself suppressed by --quiet) and runs the action without animation, so redirected/piped/CI output stays free of escape sequences and --quiet stays silent.

func (*Printer) Result added in v2.16.5

func (p *Printer) Result(a ...any)

Result writes the command's primary output to stdout. Always printed.

func (*Printer) ResultWriter added in v2.16.5

func (p *Printer) ResultWriter() io.Writer

ResultWriter is the streaming counterpart of Result: always printed.

func (*Printer) Resultf added in v2.16.5

func (p *Printer) Resultf(format string, a ...any)

Resultf is Printf-style Result.

func (*Printer) Status added in v2.16.5

func (p *Printer) Status(a ...any)

Status writes an informational breadcrumb to stderr ("Using project [X]", "Cloning template…"). Suppressed by --quiet. A trailing newline is appended.

func (*Printer) StatusWriter added in v2.16.5

func (p *Printer) StatusWriter() io.Writer

StatusWriter is the streaming counterpart of Status: io.Discard under --quiet.

func (*Printer) Statusf added in v2.16.5

func (p *Printer) Statusf(format string, a ...any)

Statusf is Printf-style Status.

func (*Printer) WarnWriter added in v2.16.5

func (p *Printer) WarnWriter() io.Writer

WarnWriter is the streaming counterpart of Warnf: never silenced.

func (*Printer) Warnf added in v2.16.5

func (p *Printer) Warnf(format string, a ...any)

Warnf writes a warning to stderr. NOT suppressed by --quiet — warnings are always worth surfacing.

type ThemeName added in v2.16.5

type ThemeName string

ThemeName identifies a color theme. The active theme is selected once at startup (see SetTheme) from the value persisted in the CLI config.

const (
	// ThemeDefault uses only ANSI palette colors, so it adapts to the user's terminal
	// color scheme. This is the original look.
	ThemeDefault ThemeName = "default"
	// ThemeLiveKit uses the LiveKit brand palette (truecolor hex with light/dark variants).
	ThemeLiveKit ThemeName = "livekit"
)

Jump to

Keyboard shortcuts

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