mirror of
https://github.com/psviderski/uncloud.git
synced 2026-10-06 13:18:58 +00:00
* chore(deps): bump bubbletea to v2.0.10, drop the uncloud fork v2.0.10 carries the upstream fix for terminal capability replies leaking into the shell (charmbracelet/bubbletea#1801). It skips every query that expects a reply when input is disabled: the startup probe for synchronized output and Unicode core, clipboard reads, background, foreground and cursor colour requests, cursor position reports, and terminal version and termcap queries. That supersedes the unlabs-dev fork, whose patch covered only the startup probe, so the replace directive goes away and uncloud tracks upstream again. The bump on its own does not fix the leak. Bubble Tea skips the queries only when a program declares that it has no input, and nothing in uncloud declares that yet. Measured: this tree still leaks "^[[?2026;2$y^[[?2027;0$y" under a PTY harness. The next commit is what makes the spinners declare it. Refs: #286, charmbracelet/bubbletea#1801
40 lines
1.2 KiB
Go
40 lines
1.2 KiB
Go
package tui
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"os"
|
|
|
|
"charm.land/huh/v2/spinner"
|
|
"charm.land/lipgloss/v2"
|
|
)
|
|
|
|
// RunSpinner shows an animated spinner that prints title while running action.
|
|
// When the terminal (TTY) is not available, it prints the title as plain text.
|
|
// It renders to stderr so stdout stays clean for command output.
|
|
func RunSpinner(ctx context.Context, title string, action func(ctx context.Context) error) error {
|
|
// Fall back to plain text when a terminal is not available to avoid the bubbletea /dev/tty error and to keep
|
|
// escape codes out of redirected output.
|
|
if !IsTerminalAvailable() {
|
|
fmt.Fprintln(os.Stderr, title)
|
|
return action(ctx)
|
|
}
|
|
|
|
return spinner.New().
|
|
// Leading space offsets the title from the spinner glyph.
|
|
Title(" " + title).
|
|
Type(spinner.MiniDot).
|
|
WithTheme(spinner.ThemeFunc(func(isDark bool) *spinner.Styles {
|
|
return &spinner.Styles{
|
|
Spinner: lipgloss.NewStyle().Foreground(lipgloss.Yellow),
|
|
Title: lipgloss.NewStyle(),
|
|
}
|
|
})).
|
|
WithOutput(os.Stderr).
|
|
// A spinner reads no keys, saying so makes Bubble Tea skip unnecessary terminal capability queries.
|
|
WithInput(nil).
|
|
Context(ctx).
|
|
ActionWithErr(action).
|
|
Run()
|
|
}
|