ui

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package ui owns everything vrok prints to a terminal. Keeping it in one place means the CLI commands contain decisions, not formatting, and that colour and symbol support is decided once.

Index

Constants

View Source
const HotkeyBar = "c copy · q QR code · p add password · e change expiry · 1 one-time link · x stop"

HotkeyBar is the live command strip shown under a share, in the same compact style as Vite and Expo.

Variables

View Source
var ErrNoClipboard = errors.New("clipboard: no copy command available")

ErrNoClipboard means this machine has no clipboard tool vrok knows.

Functions

func BurstLine added in v0.2.0

func BurstLine(sent int64, took time.Duration) string

BurstLine is the permanent line left behind when a stretch of downloading ends, so the owner can see a large transfer finished after the live line has gone.

func Copy added in v0.2.0

func Copy(text string) error

Copy writes text to the system clipboard. A missing tool is not fatal: the URL is still printed, and the owner can copy it by hand.

func Fit added in v0.2.0

func Fit(text string, width int) string

Fit shortens text to width columns, so a progress line redrawn with a carriage return never wraps onto a second line it cannot erase.

func Plural

func Plural(count int, singular, plural string) string

Plural renders a count with the right noun, so messages read as sentences rather than as "1 process(es)".

func ProgressLine added in v0.2.0

func ProgressLine(transfers []Transfer, rate float64) string

ProgressLine is the live status shown while files are being downloaded:

↓ 1.2 GB / 4.0 GB · 30% · 3.1 MB/s · 18m left
↓ 3 downloads · 9.4 MB/s · 4.5 GB sent

rate is in bytes per second; zero leaves the speed out rather than claiming a stall.

func StatusLine added in v0.2.0

func StatusLine(v ShareView) string

StatusLine is the compact "Expires in 1h 59m · anyone with the link" row.

Types

type Printer

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

Printer writes vrok's terminal output.

func New

func New(out, errOut io.Writer) *Printer

New returns a Printer for the given streams, enabling colour only when the output really is an interactive terminal.

func NewStd

func NewStd() *Printer

NewStd returns a Printer writing to the process's standard streams.

func (*Printer) Blank

func (p *Printer) Blank()

Blank prints an empty line.

func (*Printer) Bold

func (p *Printer) Bold(text string) string

Bold returns text in bold.

func (*Printer) Check added in v0.6.0

func (p *Printer) Check(s Status, label, value string)

Check prints one diagnostic line. Unlike Warn and Error it writes every outcome to the output stream, so a report keeps its order and survives being piped or pasted into an issue whole.

func (*Printer) Detail

func (p *Printer) Detail(label, value string)

Detail prints an indented secondary line.

func (*Printer) Dim

func (p *Printer) Dim(text string) string

Dim returns de-emphasised text.

func (*Printer) Error

func (p *Printer) Error(format string, args ...any)

Error prints a failure to the error stream.

func (*Printer) Hint added in v0.6.0

func (p *Printer) Hint(format string, args ...any)

Hint prints a follow-up line under a Check.

func (*Printer) Info

func (p *Printer) Info(format string, args ...any)

Info prints a plain line.

func (*Printer) Keys added in v0.2.0

func (p *Printer) Keys()

Keys prints the live hotkey bar.

func (p *Printer) Link(text string) string

Link returns a highlighted URL.

func (*Printer) NewTable

func (p *Printer) NewTable(headers ...string) *Table

NewTable starts a table with the given headers.

func (*Printer) Out

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

Out exposes the output stream for callers that write their own formats.

func (*Printer) QR

func (p *Printer) QR(url string)

QR prints a scannable QR code for a URL.

This is the fastest path from a terminal to a phone: no retyping a token, no sending yourself a message. Half-block rendering is used so the code fits in a normal terminal window, since a full-block code is twice as tall.

func (*Printer) SetColor

func (p *Printer) SetColor(enabled bool)

SetColor forces colour on or off, for --no-color and for tests.

func (*Printer) Started

func (p *Printer) Started(v ShareView)

Started prints the share banner: URL first, then who can open it, then the hotkeys (or Ctrl+C when there is no terminal).

func (*Printer) Step

func (p *Printer) Step(format string, args ...any)

Step reports progress on something slow that the user is waiting through, so a one-time download does not look like the tool hanging. It goes to the error stream to keep it out of a piped URL.

func (*Printer) Stopped

func (p *Printer) Stopped(s Stats)

Stopped prints the closing summary.

func (*Printer) Success

func (p *Printer) Success(format string, args ...any)

Success prints a confirmation line.

func (*Printer) Warn

func (p *Printer) Warn(format string, args ...any)

Warn prints a warning to the error stream.

type ShareView

type ShareView struct {
	// Name is the share's display name.
	Name string
	// URL is the address to hand out.
	URL string
	// LocalURL is the direct address, shown alongside URL when a tunnel is in
	// use so the owner can still test locally.
	LocalURL string
	// TTL is the share lifetime; zero means no expiry.
	TTL time.Duration
	// MaxDownloads is the download cap; zero means unlimited.
	MaxDownloads int
	// Downloads is how many have completed so far.
	Downloads int
	// Protected reports whether a password is required.
	Protected bool
	// Tunnel is the provider name.
	Tunnel string
	// Reach says who can open the URL, and Hint says how to widen that.
	//
	// A loopback URL looks exactly as shareable as a public one, and pasting
	// it into a chat sends the recipient to their own machine. Saying so on
	// the banner is the only moment the owner is paying attention.
	Reach string
	Hint  string
	// Copied is true when the URL was written to the clipboard.
	Copied bool
	// Interactive is true when the process is attached to a terminal, so the
	// hotkey bar is worth printing. Scripts and CI see "Press Ctrl+C" instead.
	Interactive bool
}

ShareView is everything the terminal shows when a share starts.

type Stats

type Stats struct {
	Name       string
	Downloads  int
	Bytes      int64
	LastAccess time.Time
	Expired    bool
}

Stats is the local usage summary shown when a share ends. vrok reports no statistics anywhere else: these numbers are counted in this process and printed here, and that is all that happens to them.

type Status added in v0.6.0

type Status int

Status is the outcome of one diagnostic check.

const (
	StatusOK Status = iota
	StatusWarn
	StatusFail
)

type Table

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

Table prints aligned columns for `vrok list`.

It uses text/tabwriter rather than fixed widths so a long filename widens its column instead of breaking the layout.

func (*Table) Flush

func (t *Table) Flush() error

Flush writes the table out.

func (*Table) Row

func (t *Table) Row(cells ...string)

Row adds a row. Missing cells are padded so the table stays aligned even when a caller supplies fewer values than there are headers.

type Transfer added in v0.2.0

type Transfer struct {
	Sent int64
	// Total is the expected size, or -1 when unknown (a streamed zip).
	Total int64
}

Transfer is one download in flight, as the progress line sees it.

Jump to

Keyboard shortcuts

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