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
- Variables
- func BurstLine(sent int64, took time.Duration) string
- func Copy(text string) error
- func Fit(text string, width int) string
- func Plural(count int, singular, plural string) string
- func ProgressLine(transfers []Transfer, rate float64) string
- func StatusLine(v ShareView) string
- type Printer
- func (p *Printer) Blank()
- func (p *Printer) Bold(text string) string
- func (p *Printer) Check(s Status, label, value string)
- func (p *Printer) Detail(label, value string)
- func (p *Printer) Dim(text string) string
- func (p *Printer) Error(format string, args ...any)
- func (p *Printer) Hint(format string, args ...any)
- func (p *Printer) Info(format string, args ...any)
- func (p *Printer) Keys()
- func (p *Printer) Link(text string) string
- func (p *Printer) NewTable(headers ...string) *Table
- func (p *Printer) Out() io.Writer
- func (p *Printer) QR(url string)
- func (p *Printer) SetColor(enabled bool)
- func (p *Printer) Started(v ShareView)
- func (p *Printer) Step(format string, args ...any)
- func (p *Printer) Stopped(s Stats)
- func (p *Printer) Success(format string, args ...any)
- func (p *Printer) Warn(format string, args ...any)
- type ShareView
- type Stats
- type Status
- type Table
- type Transfer
Constants ¶
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 ¶
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
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
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
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 ¶
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
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
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 ¶
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) Check ¶ added in v0.6.0
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) QR ¶
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) Started ¶
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 ¶
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.
type ShareView ¶
type ShareView struct {
Name string
URL string
// use so the owner can still test locally.
LocalURL string
TTL time.Duration
MaxDownloads int
Downloads int
Protected bool
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.
Copied bool
// 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 ¶
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.