ProgressModal
Determinate vs indeterminate
Section titled “Determinate vs indeterminate”The modal defaults to indeterminate mode (spinner, progress = -1). Switch to determinate by calling SetProgress with a value in [0.0, 1.0], or explicitly with SetIndeterminate(false).
// Indeterminate (default) — shows animated spinnermodal := components.NewProgressModal(). SetTitle("Connecting...")
// Determinate — shows filled progress barmodal.SetProgress(0.45) // 45%Completion and failure
Section titled “Completion and failure”Call Complete() to show a success state and fire onComplete. Call Fail(err) to show an error state and fire onError. Both stop the spinner. After either call the modal stays visible until the user presses any key (or Close() is called directly).
Cancelable
Section titled “Cancelable”Set SetCancelable(true) and wire SetOnCancel to let the user abort. The cancel button appears in the modal footer when cancelable.
Usage
modal := components.NewProgressModal(). SetTitle("Deploying"). SetMessage("Uploading image..."). SetCancelable(true). SetProgress(0.4)modal.SetOnCancel(func() { fmt.Println("cancelled")})
fmt.Println(modal != nil)Methods
| Method | Signature | Description |
|---|---|---|
Close | func (p *ProgressModal) Close() | Close closes the modal |
Complete | func (p *ProgressModal) Complete(message string) *ProgressModal | Complete marks the operation as successfully completed |
Fail | func (p *ProgressModal) Fail(err error) *ProgressModal | Fail marks the operation as failed |
IsComplete | func (p *ProgressModal) IsComplete() bool | IsComplete returns true if operation completed successfully |
IsFailed | func (p *ProgressModal) IsFailed() bool | IsFailed returns true if operation failed |
SetCancelable | func (p *ProgressModal) SetCancelable(cancelable bool) *ProgressModal | SetCancelable enables/disables cancel functionality |
SetIndeterminate | func (p *ProgressModal) SetIndeterminate(indeterminate bool) *ProgressModal | SetIndeterminate sets indeterminate (spinner) mode |
SetMessage | func (p *ProgressModal) SetMessage(message string) *ProgressModal | SetMessage sets the status message |
SetOnCancel | func (p *ProgressModal) SetOnCancel(fn func()) *ProgressModal | SetOnCancel is called when user cancels |
SetOnClose | func (p *ProgressModal) SetOnClose(fn func()) *ProgressModal | SetOnClose is called when modal is closed |
SetOnComplete | func (p *ProgressModal) SetOnComplete(fn func()) *ProgressModal | SetOnComplete is called when Complete() is called |
SetProgress | func (p *ProgressModal) SetProgress(progress float64) *ProgressModal | SetProgress sets the progress percentage (0.0 - 1.0) Values < 0 switch to indeterminate mode |
SetShowBackdrop | func (p *ProgressModal) SetShowBackdrop(show bool) *ProgressModal | SetShowBackdrop enables/disables backdrop overlay |
SetSubMessage | func (p *ProgressModal) SetSubMessage(message string) *ProgressModal | SetSubMessage sets a secondary/detail message |
SetTitle | func (p *ProgressModal) SetTitle(title string) *ProgressModal | SetTitle sets the modal title |
SetWidth | func (p *ProgressModal) SetWidth(width int) *ProgressModal | SetWidth sets modal width |
StartSpinner | func (p *ProgressModal) StartSpinner(app *tview.Application) | StartSpinner starts the spinner animation for indeterminate mode |