Documentation
¶
Overview ¶
Package display provides functions for styled terminal output.
Package display provides functions for styled terminal output and theme management.
Index ¶
- Constants
- Variables
- func DetermineGlamourStyle(opts *Options) string
- func Error(s string)deprecated
- func IsTerminalColorCapable() bool
- func Title(s string)deprecated
- type Options
- type ProgressEvent
- type StyleSheet
- type TerminalDisplay
- func (td *TerminalDisplay) ClearProgress()
- func (td *TerminalDisplay) Display(ctx context.Context, markdownContent string) error
- func (td *TerminalDisplay) DisplayWithProgress(ctx context.Context, markdownContent string, progressCh <-chan ProgressEvent) error
- func (td *TerminalDisplay) ShowProgress(percent float64, message string)
- type Theme
Constants ¶
const ( // None disables all terminal styling. None = "none" // Custom indicates a custom color profile is in use. Custom = "custom" // Auto enables automatic color profile detection. Auto = "auto" // Notty indicates no TTY is available (non-interactive mode). Notty = "notty" // Truecolor indicates a terminal supporting 24-bit true color. Truecolor = "truecolor" // Bit24 is an alias for 24-bit color support. Bit24 = "24bit" )
Theme and terminal color constants used throughout the display package.
const (
// DefaultWordWrapWidth is the default word wrap width for terminal display.
DefaultWordWrapWidth = 120
)
Variables ¶
var ErrRawMarkdown = errors.New("raw markdown display requested")
ErrRawMarkdown is a sentinel error indicating that raw markdown should be displayed.
Functions ¶
func DetermineGlamourStyle ¶
DetermineGlamourStyle returns the Glamour style string to use for markdown rendering based on the provided options, considering color enablement, terminal color support, and the selected theme.
func IsTerminalColorCapable ¶
func IsTerminalColorCapable() bool
IsTerminalColorCapable returns true if the current terminal environment supports color output, based on environment variables and terminal type heuristics.
Types ¶
type Options ¶
Options holds display configuration settings.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns an Options struct with the default theme, word wrap width, and both tables and colors enabled.
type ProgressEvent ¶
ProgressEvent represents a progress update event.
type StyleSheet ¶
type StyleSheet struct {
Title lipgloss.Style
Subtitle lipgloss.Style
Table lipgloss.Style
Error lipgloss.Style
Warning lipgloss.Style
// contains filtered or unexported fields
}
StyleSheet holds styles for various terminal display elements.
func NewStyleSheet ¶
func NewStyleSheet() *StyleSheet
NewStyleSheet returns a new StyleSheet configured with an automatically detected theme based on the current environment.
func NewStyleSheetWithTheme ¶
func NewStyleSheetWithTheme(theme Theme) *StyleSheet
NewStyleSheetWithTheme returns a new StyleSheet configured with the provided theme. The StyleSheet includes styled elements for titles, subtitles, tables, errors, and warnings, using colors from the specified theme.
func (*StyleSheet) ErrorPrint ¶
func (s *StyleSheet) ErrorPrint(text string)
ErrorPrint prints an error-styled text on the terminal.
func (*StyleSheet) SubtitlePrint ¶
func (s *StyleSheet) SubtitlePrint(text string)
SubtitlePrint prints a subtitle-styled text on the terminal.
func (*StyleSheet) TablePrint ¶
func (s *StyleSheet) TablePrint(text string)
TablePrint prints a table-styled text on the terminal.
func (*StyleSheet) TitlePrint ¶
func (s *StyleSheet) TitlePrint(text string)
TitlePrint prints a title-styled text on the terminal.
func (*StyleSheet) WarningPrint ¶
func (s *StyleSheet) WarningPrint(text string)
WarningPrint prints a warning-styled text on the terminal.
type TerminalDisplay ¶
type TerminalDisplay struct {
// contains filtered or unexported fields
}
TerminalDisplay represents a terminal markdown displayer.
func NewTerminalDisplay ¶
func NewTerminalDisplay() *TerminalDisplay
NewTerminalDisplay creates a TerminalDisplay with default display options and progress bar settings.
func NewTerminalDisplayWithMarkdownOptions ¶
func NewTerminalDisplayWithMarkdownOptions(mdOpts converter.Options) *TerminalDisplay
NewTerminalDisplayWithMarkdownOptions creates a TerminalDisplay with markdown options. This provides compatibility with the markdown package options.
func NewTerminalDisplayWithOptions ¶
func NewTerminalDisplayWithOptions(opts Options) *TerminalDisplay
NewTerminalDisplayWithOptions returns a TerminalDisplay configured with the provided options, initializing the progress bar with theme-based colors and setting the wrap width if not specified.
func NewTerminalDisplayWithTheme
deprecated
func NewTerminalDisplayWithTheme(theme Theme) *TerminalDisplay
NewTerminalDisplayWithTheme creates a TerminalDisplay with the specified theme. NewTerminalDisplayWithTheme creates a TerminalDisplay with the specified theme and terminal width.
Deprecated: Use NewTerminalDisplayWithOptions instead.
func (*TerminalDisplay) ClearProgress ¶
func (td *TerminalDisplay) ClearProgress()
ClearProgress clears the progress indicator from the terminal.
func (*TerminalDisplay) Display ¶
func (td *TerminalDisplay) Display(ctx context.Context, markdownContent string) error
Display renders and displays markdown content in the terminal with syntax highlighting.
func (*TerminalDisplay) DisplayWithProgress ¶
func (td *TerminalDisplay) DisplayWithProgress( ctx context.Context, markdownContent string, progressCh <-chan ProgressEvent, ) error
DisplayWithProgress renders and displays markdown content with progress events.
func (*TerminalDisplay) ShowProgress ¶
func (td *TerminalDisplay) ShowProgress(percent float64, message string)
ShowProgress displays a progress bar with the given completion percentage and message.
type Theme ¶
Theme represents a color theme with customizable palettes.
func CustomTheme ¶
func CustomTheme() Theme
CustomTheme returns a Theme with an empty palette and Glamour style set to "auto", intended for user customization.
func DarkTheme ¶
func DarkTheme() Theme
DarkTheme returns a Theme configured with a predefined dark color palette and the Glamour style "dark".
func DetectTheme ¶
DetectTheme determines the theme based on configuration and environment. DetectTheme determines the terminal color theme to use based on the provided configuration, the OPNDOSSIER_THEME environment variable, or automatic detection if neither is set.
func LightTheme ¶
func LightTheme() Theme
LightTheme returns a Theme configured with a predefined light color palette and the Glamour style "light".
func (*Theme) ApplyTheme ¶
ApplyTheme applies the theme colors to a lipgloss style.
func (*Theme) GetGlamourStyleName ¶
GetGlamourStyleName returns the Glamour style name for this theme.