Documentation
¶
Index ¶
- Constants
- Variables
- func Exit(err error)
- func ExitCodeFor(err error) int
- func HasColor(disableColor bool) bool
- func IsInteractive() bool
- func JoinStrings(parts []string, sep string) string
- func PadRight(s string, width int) string
- func SelectBook(ctx context.Context, books []api.UserBook, styles *Styles) (*api.UserBook, error)
- func SelectEdition(ctx context.Context, editions []api.EditionResult, styles *Styles) (*api.EditionResult, error)
- func SelectSearchResult(ctx context.Context, results []api.SearchResult, styles *Styles) (*api.SearchResult, error)
- func SelectStatus(ctx context.Context, styles *Styles) (int, error)
- func ShouldSpinner(jsonMode bool) bool
- func StatusName(statusID int) string
- func StripANSI(s string) string
- func TerminalWidth() int
- func Truncate(s string, n int) string
- func VisibleWidth(s string) int
- func WithSpinner(ctx context.Context, jsonMode bool, fn func(context.Context) error) error
- func WithSpinnerMsg(ctx context.Context, jsonMode bool, msg string, fn func(context.Context) error) error
- type Styles
- func (s *Styles) Apply(style lipgloss.Style, str string) string
- func (s *Styles) Bullet() string
- func (s *Styles) ProgressBar(pct float64, width int) string
- func (s *Styles) Separator(ch string, maxWidth int) string
- func (s *Styles) StatusColor(statusID int) lipgloss.Style
- func (s *Styles) Success(msg string) string
Constants ¶
const ( ExitOK = 0 ExitError = 1 // generic error, bad input, validation ExitAuth = 2 // missing/invalid token ExitNet = 3 // network errors, timeouts, 5xx )
Exit codes used by the CLI. Returned via os.Exit at the entrypoint.
Variables ¶
var StatusShort = map[string]int{
"want": 1,
"reading": 2,
"read": 3,
"paused": 4,
"dnf": 5,
"ignored": 6,
}
StatusShort maps short keys to status ids.
Functions ¶
func Exit ¶
func Exit(err error)
Exit prints the error to stderr (if any) and exits with the appropriate code.
func ExitCodeFor ¶
ExitCodeFor returns the appropriate exit code for the given error. It unwraps the error chain looking for known sentinels and falls back to ExitError for anything else.
IMPORTANT: every call site that wants to surface a sentinel must wrap with %w (fmt.Errorf("...: %w", errs.ErrNoToken)), never %v. errors.Is unwraps the %w chain; %v produces a fresh string error that won't match.
func HasColor ¶
HasColor reports whether colored output is appropriate. True when stdout is a terminal, NO_COLOR is not set, and --no-color was not passed (caller passes disableColor).
func IsInteractive ¶
func IsInteractive() bool
IsInteractive reports whether stdin and stdout are both terminals. Use for commands that prompt the user interactively.
func JoinStrings ¶
JoinStrings joins a slice with a separator, ignoring empty entries.
func SelectBook ¶
SelectBook runs an interactive picker and returns the chosen user_book. The context is forwarded to the bubbletea program so Ctrl-C cancels cleanly. Returns (nil, nil) if the user cancelled.
In a non-TTY environment (e.g. piped stdin), SelectBook falls back to returning the first book without launching a picker.
func SelectEdition ¶
func SelectEdition(ctx context.Context, editions []api.EditionResult, styles *Styles) (*api.EditionResult, error)
SelectEdition runs an interactive picker for book editions. If there is only one edition it is returned directly. Returns (nil, nil) if the user cancelled.
func SelectSearchResult ¶
func SelectSearchResult(ctx context.Context, results []api.SearchResult, styles *Styles) (*api.SearchResult, error)
SelectSearchResult runs an interactive picker for catalog search results. Returns (nil, nil) if the user cancelled.
func SelectStatus ¶
SelectStatus runs an interactive picker for reading statuses. Returns the chosen status ID, or (0, nil) if the user cancelled. In non-interactive mode, returns 1 ("Want to Read") without prompting.
func ShouldSpinner ¶
ShouldSpinner reports whether a yacspin spinner should be shown. True when stderr is a terminal and --json was not passed.
func StatusName ¶
StatusName returns a human-readable status name.
func TerminalWidth ¶
func TerminalWidth() int
TerminalWidth returns the width of the terminal in columns. Returns 0 if the width cannot be determined.
func VisibleWidth ¶
VisibleWidth returns the display width of s, stripping ANSI escapes and counting CJK/wide characters as 2 columns.
func WithSpinner ¶
WithSpinner displays a terminal spinner while fn runs. The spinner is suppressed when stdout is not a TTY or when jsonMode is true.
Types ¶
type Styles ¶
type Styles struct {
Color bool
Title lipgloss.Style
Bold lipgloss.Style
Dim lipgloss.Style
Green lipgloss.Style
Red lipgloss.Style
Yellow lipgloss.Style
Cyan lipgloss.Style
Magenta lipgloss.Style
BGreen lipgloss.Style
BYellow lipgloss.Style
BCyan lipgloss.Style
SuccessBold lipgloss.Style
}
ColorOn returns lipgloss with colors if hasColor is true, plain otherwise. Stash a package-level "Styles" struct as well as per-call adaptive renderers.
func (*Styles) ProgressBar ¶
ProgressBar renders a percentage progress bar with a color gradient. pct is 0-100, width is the number of characters in the bar.
func (*Styles) Separator ¶
Separator returns a horizontal line of the given character, sized to the terminal width (capped at maxWidth).
func (*Styles) StatusColor ¶
StatusColor returns the appropriate color style for a Hardcover status id. 1=Want, 2=Reading, 3=Read, 4=Paused, 5=DNF, 6=Ignored.