display

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package display provides functions for styled terminal output.

Package display provides functions for styled terminal output and theme management.

Index

Constants

View Source
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.

View Source
const (
	// DefaultWordWrapWidth is the default word wrap width for terminal display.
	DefaultWordWrapWidth = 120
)

Variables

View Source
var ErrRawMarkdown = errors.New("raw markdown display requested")

ErrRawMarkdown is a sentinel error indicating that raw markdown should be displayed.

Functions

func DetermineGlamourStyle

func DetermineGlamourStyle(opts *Options) string

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 Error deprecated

func Error(s string)

Error prints the input string to the terminal using a bold red error style. Error prints the given string as an error message using the global StyleSheet.

Deprecated: Use StyleSheet.ErrorPrint instead.

func IsTerminalColorCapable

func IsTerminalColorCapable() bool

IsTerminalColorCapable returns true if the current terminal environment supports color output, based on environment variables and terminal type heuristics.

func Title deprecated

func Title(s string)

Title prints the given string to the console using the predefined title style. Title prints the given string as a styled title using the global StyleSheet.

Deprecated: Use StyleSheet.TitlePrint instead.

Types

type Options

type Options struct {
	Theme        Theme
	WrapWidth    int
	EnableTables bool
	EnableColors bool
}

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

type ProgressEvent struct {
	Percent float64
	Message string
}

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

type Theme struct {
	Name         string
	Palette      map[string]string
	GlamourStyle string
}

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

func DetectTheme(configTheme string) Theme

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

func (t *Theme) ApplyTheme(style lipgloss.Style, colorKey string) lipgloss.Style

ApplyTheme applies the theme colors to a lipgloss style.

func (*Theme) GetColor

func (t *Theme) GetColor(colorKey string) string

GetColor returns a color from the theme palette.

func (*Theme) GetGlamourStyleName

func (t *Theme) GetGlamourStyleName() string

GetGlamourStyleName returns the Glamour style name for this theme.

func (*Theme) IsDark

func (t *Theme) IsDark() bool

IsDark returns true if the theme is a dark theme.

func (*Theme) IsLight

func (t *Theme) IsLight() bool

IsLight returns true if the theme is a light theme.

Jump to

Keyboard shortcuts

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