progress

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

README

Progress

Анимированный спиннер задач и прогресс-баров для терминала. Своя перерисовка на ANSI-кодах без bubbletea. Спиннер печатает активные задачи со сменой кадра, а завершённые сдвигает выше со значком [✓]

Использование

progress.SetTranslator(myT)
sp := progress.New(progress.Colors{Filled: "#26a269", Empty: "#c4c8c6"})
sp.Start()

sp.Update(progress.TaskUpdate{Name: "update", View: "Обновление списка пакетов"})
// ... позже, по тому же Name:
sp.Update(progress.TaskUpdate{Name: "update", View: "Обновление списка пакетов", Done: true})

sp.Stop() 

Задача адресуется по Name: первый Update добавляет её, последующие с тем же именем обновляют. Done: true переводит задачу в завершённые.

Прогресс-бар

sp.Update(progress.TaskUpdate{
    Name:       "download",
    View:       "ftp.altlinux.org release",
    IsProgress: true,
    Percent:    42,
})

IsProgress рисует полосу с процентами вместо простой строки со спиннером. При завершении, если задан DoneText, печатается строка Progress: <DoneText> completed.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var T_ = func(msgID string) string { return msgID }

T_ translates a message id, no-op by default.

Functions

func SetTranslator

func SetTranslator(fn func(msgID string) string)

SetTranslator sets the translation function.

Types

type Colors

type Colors struct {
	Filled string
	Empty  string
}

Colors is the progress bar palette (filled/empty).

type Spinner

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

Spinner is a terminal task/progress indicator.

func New

func New(colors Colors) *Spinner

New creates a spinner with the palette, not started yet.

func (*Spinner) Start

func (sp *Spinner) Start()

Start hides the cursor, disables echo and runs the redraw loop.

func (*Spinner) Stop

func (sp *Spinner) Stop()

Stop halts animation, flushes completed tasks and restores the terminal.

func (*Spinner) Update

func (sp *Spinner) Update(u TaskUpdate)

Update adds or updates a task.

type TaskUpdate

type TaskUpdate struct {
	Name       string  // stable task id
	View       string  // display text
	IsProgress bool    // render a percent bar
	Percent    float64 // current percent (for IsProgress)
	DoneText   string  // completion text (for IsProgress)
	Done       bool    // task finished
}

TaskUpdate is a neutral task update for the spinner.

Jump to

Keyboard shortcuts

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