ui

package
v0.0.0-...-68d9d71 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Stdout    = colorable.NewColorableStdout()
	Stderr    = colorable.NewColorableStderr()
	DefaultUI = Console{Stdout: Stdout, Stderr: Stderr}

	// Log is the global structured console logger used when the TUI is inactive.
	// It uses charmbracelet/log with custom lipgloss styles matching the TUI palette.
	Log *charmlog.Logger
)
View Source
var DisplayProgress = true

DisplayProgress controls whether the TUI progress bar is shown. Set to false in tests to disable TUI output.

View Source
var Program *tea.Program

Program is the global tea.Program; goroutines call Program.Send() to deliver messages.

Functions

func ConfirmRedownload

func ConfirmRedownload(filename string) bool

ConfirmRedownload shows a styled huh confirmation prompt asking whether to overwrite an existing file. Returns true when the user says yes (or when stdout is not a terminal, in which case the download proceeds silently).

func DisplayProgressBar

func DisplayProgressBar() bool

DisplayProgressBar returns true when running in interactive TTY mode.

func Errorf

func Errorf(format string, a ...any) (n int, err error)

Errorf outputs error-level logs, routing to TUI when available.

func Errorln

func Errorln(a ...any) (n int, err error)

Errorln is the non-formatted error printer.

func IsTerminal

func IsTerminal(f *os.File) bool

IsTerminal checks if f is connected to a real TTY.

func NewProgram

func NewProgram(numConns int) *tea.Program

NewProgram creates and starts a new Bubble Tea program for the TUI.

func NewTUIModel

func NewTUIModel(numConns int, willVerify bool, batchCurrent, batchTotal int, onSkip, onQuit func()) tuiModel

NewTUIModel creates a new TUI model for the given number of connections. batchCurrent and batchTotal are 1-based; pass 0,0 when not in batch mode. onSkip is non-nil only in batch mode and is invoked when the user presses 's'. onQuit is invoked on 'q' / 'ctrl+c'; both default to no-ops if nil.

func PrintHelp

func PrintHelp()

PrintHelp renders a styled --help screen to stdout.

func PrintVerifySummary

func PrintVerifySummary(ok bool, detail string)

PrintVerifySummary writes a styled one-line verify result to the terminal using charmbracelet/log (works after the TUI alt-screen has closed).

func Printf

func Printf(format string, a ...any) (n int, err error)

Printf outputs information-level logs, routing to TUI when available.

func ResumePrompt

func ResumePrompt(taskName string, downloaded, total int64) (bool, error)

ResumePrompt shows an animated TUI prompt asking whether to resume a partial download. Returns true if user wants to resume, false to start fresh.

func RunWithTUI

func RunWithTUI(opts RunOptions, fn func() error) error

RunWithTUI starts a Bubble Tea program for interactive TTY sessions and runs fn in a background goroutine. Falls back to plain execution when not in a TTY. Returns the error returned by fn (or recovered from a panic inside it), so callers can distinguish skip vs abort vs failure.

func ShowMessage

func ShowMessage(msgType MessageType, title, message string)

ShowMessage displays a styled message box and returns immediately.

func Warnf

func Warnf(format string, a ...any) (n int, err error)

Warnf outputs warning-level logs, routing to TUI when available.

Types

type Console

type Console struct {
	Stdout io.Writer
	Stderr io.Writer
}

Console is the non-TUI implementation of UI.

func (Console) Errorf

func (c Console) Errorf(format string, a ...any) (n int, err error)

func (Console) Errorln

func (c Console) Errorln(a ...any) (n int, err error)

func (Console) Printf

func (c Console) Printf(format string, a ...any) (n int, err error)

func (Console) Println

func (c Console) Println(a ...any) (n int, err error)

type DownloadDoneMsg

type DownloadDoneMsg struct{}

DownloadDoneMsg signals the entire pipeline (download + join + optional verify) finished.

type DownloadErrorMsg

type DownloadErrorMsg struct{ Err error }

DownloadErrorMsg signals a fatal download error.

type DownloadStartMsg

type DownloadStartMsg struct {
	URL      string
	FileName string
	Size     int64
	NumParts int
	IPs      []string
}

DownloadStartMsg is sent once download metadata is known.

type JoinDoneMsg

type JoinDoneMsg struct{}

JoinDoneMsg signals joining finished.

type JoinProgressMsg

type JoinProgressMsg struct{ Current int }

JoinProgressMsg carries joining progress.

type JoinStartMsg

type JoinStartMsg struct{ Total int }

JoinStartMsg signals the file-joining phase started.

type LogMsg

type LogMsg struct {
	Level string // "info" | "warn" | "error"
	Text  string
}

LogMsg adds an entry to the on-screen log panel.

type MessageType

type MessageType int

MessageBox renders a styled message box that fits the modem theme.

const (
	MessageInfo MessageType = iota
	MessageWarning
	MessageError
	MessageSuccess
)

type PartDoneMsg

type PartDoneMsg struct{ Index int }

PartDoneMsg signals a chunk finished downloading successfully.

type PartProgressMsg

type PartProgressMsg struct {
	Index      int
	Downloaded int64
	Total      int64
}

PartProgressMsg carries incremental progress for one chunk.

type RunOptions

type RunOptions struct {
	// Ctx is observed for external cancellation (e.g. SIGINT routed through
	// signal.NotifyContext at main).  When Ctx is cancelled, RunWithTUI
	// surfaces a "stopping…" overlay and waits for fn to drain.
	Ctx context.Context
	// OnSkip is called when the user presses 's' (batch mode only).
	OnSkip func()
	// OnQuit is called when the user presses 'q' / 'ctrl+c'.
	OnQuit       func()
	NumConns     int
	WillVerify   bool
	BatchCurrent int
	BatchTotal   int
}

RunOptions configures a TUI session.

type SkippingMsg

type SkippingMsg struct{}

SkippingMsg overlays a "skipping" panel for the current batch item.

type StoppingMsg

type StoppingMsg struct {
	// Reason renders inside the stopping panel; e.g. "Aborted by user".
	Reason string
}

StoppingMsg is sent when an external cancellation (e.g. SIGINT routed through signal.NotifyContext) has been requested. The TUI overlays a "stopping" panel until the worker goroutine reports completion.

type UI

type UI interface {
	Printf(format string, a ...any) (n int, err error)
	Println(a ...any) (n int, err error)
	Errorf(format string, a ...any) (n int, err error)
	Errorln(a ...any) (n int, err error)
}

UI represents simple IO output.

type VerifyDoneMsg

type VerifyDoneMsg struct {
	OK     bool
	Detail string // gpg output excerpt
}

VerifyDoneMsg signals GPG verification has completed.

type VerifyStartMsg

type VerifyStartMsg struct{}

VerifyStartMsg signals GPG signature verification has begun.

Jump to

Keyboard shortcuts

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