output

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Default is the process-wide emitter.

Functions

func BenchTotal

func BenchTotal(bytes int64)

BenchTotal writes the pre-transfer total byte count.

func Fatal

func Fatal(err error, kindDefault string)

Fatal reports a fatal error before non-zero process exit.

func Progress

func Progress(role string, bytes int64, bytesPerSec float64)

Progress emits a transfer progress event (throttled per-role).

func Prompt

func Prompt(msg string)

Prompt writes an interactive message to stderr. No-op in JSON mode.

func SDP

func SDP(writer io.Writer, role, sdp string)

SDP writes the local session description.

func Sample

func Sample(role string, sts *stats.Stats)

Sample records a fresh bandwidth sample from sts and emits the resulting byte count + current bandwidth as a progress event for role.

func SetDefault

func SetDefault(emitter *Emitter) (restore func())

SetDefault replaces the process-wide Default emitter and returns a restore function that puts the previous emitter back.

func SetMode

func SetMode(mode Mode)

SetMode is called once from cobra's PersistentPreRun on rootCmd before any subcommand runs.

func Stats

func Stats(role string, sts *stats.Stats)

Stats writes per-side final transfer statistics.

func TransferComplete

func TransferComplete(role, path string, bytes int64)

TransferComplete emits a one-line confirmation that the transfer finished successfully for role, identifying the file and its size.

Types

type Emitter

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

Emitter serialises CLI emissions (text or JSON)

func New

func New(
	mode Mode,
	stdout io.Writer,
	stderr io.Writer,
) *Emitter

New constructs an Emitter with the given mode and writers

func (*Emitter) BenchTotal

func (e *Emitter) BenchTotal(bytes int64)

BenchTotal writes the pre-transfer total byte count.

JSON mode emits a `bench_total` event so consumers can compute a fill ratio (progress events only report current bytes, not the target).

func (*Emitter) CurrentMode

func (e *Emitter) CurrentMode() Mode

CurrentMode returns the active output mode.

func (*Emitter) Fatal

func (e *Emitter) Fatal(
	err error,
	kindDefault string,
)

Fatal reports a fatal error before non-zero process exit.

func (*Emitter) Progress

func (e *Emitter) Progress(
	role string,
	bytes int64,
	bytesPerSec float64,
)

Progress emits a transfer progress event.

Throttled per-role to a minimum interval (progressMinInterval) so neither the terminal nor the JSON stream gets flooded.

func (*Emitter) Prompt

func (e *Emitter) Prompt(msg string)

Prompt writes an interactive message to stderr. No-op in JSON mode.

func (*Emitter) SDP

func (e *Emitter) SDP(
	writer io.Writer,
	role string,
	sdp string,
)

SDP writes the local session description.

func (*Emitter) SetMode

func (e *Emitter) SetMode(mode Mode)

SetMode switches the output mode.

func (*Emitter) Stats

func (e *Emitter) Stats(
	role string,
	sts *stats.Stats,
)

Stats writes per-side final transfer statistics

func (*Emitter) TransferComplete

func (e *Emitter) TransferComplete(
	role string,
	path string,
	bytes int64,
)

TransferComplete emits a one-line confirmation that the transfer finished successfully, identifying the file and its size on disk.

JSON mode emits a `transfer_complete` event so external consumers can detect completion without parsing text.

type Mode

type Mode int

Mode selects the Emitter's output format.

const (
	// ModeText emits human-readable text.
	ModeText Mode = iota

	// ModeJSON emits one JSON event per line for external tools.
	ModeJSON
)

func CurrentMode

func CurrentMode() Mode

CurrentMode returns the active output mode.

Jump to

Keyboard shortcuts

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