Documentation
¶
Overview ¶
Package herald provides a reusable TUI typography library.
It offers HTML-analogous rendering functions (H1-H6, P, Blockquote, lists, inline styles, etc.) that output styled strings via lipgloss v2.
Quick start:
ty := herald.New() // default theme
fmt.Println(ty.H1("Hello, World!"))
fmt.Println(ty.P("Some body text."))
fmt.Println(ty.UL("Apples", "Bananas", "Cherries"))
Customization via functional options:
ty := herald.New(
herald.WithHRWidth(60),
herald.WithBulletChar("-"),
herald.WithH1Style(lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Color("#FF0000"))),
)
Index ¶
- Constants
- Variables
- func DefaultAlertConfigs(ap AlertPalette) map[AlertType]AlertConfig
- type AlertConfig
- type AlertPalette
- type AlertType
- type Alignment
- type CaptionPosition
- type ColorPalette
- type ListItem
- type ListKind
- type Option
- func WithAbbrStyle(s lipgloss.Style) Option
- func WithAddressCardBorderStyle(s lipgloss.Style) Option
- func WithAddressCardStyle(s lipgloss.Style) Option
- func WithAddressStyle(s lipgloss.Style) Option
- func WithAlertBar(c string) Option
- func WithAlertIcon(at AlertType, icon string) Option
- func WithAlertLabel(at AlertType, label string) Option
- func WithAlertPalette(ap AlertPalette) Option
- func WithAlertStyle(at AlertType, s lipgloss.Style) Option
- func WithBadgeStyle(s lipgloss.Style) Option
- func WithBlockquoteBar(c string) Option
- func WithBlockquoteBarStyle(s lipgloss.Style) Option
- func WithBlockquoteStyle(s lipgloss.Style) Option
- func WithBoldStyle(s lipgloss.Style) Option
- func WithBulletChar(c string) Option
- func WithCodeBlockStyle(s lipgloss.Style) Option
- func WithCodeFormatter(fn func(code, language string) string) Option
- func WithCodeInlineStyle(s lipgloss.Style) Option
- func WithCodeLineNumberSep(sep string) Option
- func WithCodeLineNumberStyle(s lipgloss.Style) Option
- func WithCodeLineNumbers(enabled bool) Option
- func WithDDStyle(s lipgloss.Style) Option
- func WithDTStyle(s lipgloss.Style) Option
- func WithDelPrefix(c string) Option
- func WithDelStyle(s lipgloss.Style) Option
- func WithFootnoteDividerChar(c string) Option
- func WithFootnoteDividerStyle(s lipgloss.Style) Option
- func WithFootnoteDividerWidth(w int) Option
- func WithFootnoteItemStyle(s lipgloss.Style) Option
- func WithFootnoteRefStyle(s lipgloss.Style) Option
- func WithH1Style(s lipgloss.Style) Option
- func WithH1UnderlineChar(c string) Option
- func WithH2Style(s lipgloss.Style) Option
- func WithH2UnderlineChar(c string) Option
- func WithH3Style(s lipgloss.Style) Option
- func WithH3UnderlineChar(c string) Option
- func WithH4Style(s lipgloss.Style) Option
- func WithH5Style(s lipgloss.Style) Option
- func WithH6Style(s lipgloss.Style) Option
- func WithHRChar(c string) Option
- func WithHRStyle(s lipgloss.Style) Option
- func WithHRWidth(w int) Option
- func WithHeadingBarChar(c string) Option
- func WithHierarchicalNumbers(enabled bool) Option
- func WithInsPrefix(c string) Option
- func WithInsStyle(s lipgloss.Style) Option
- func WithItalicStyle(s lipgloss.Style) Option
- func WithKbdStyle(s lipgloss.Style) Option
- func WithLinkStyle(s lipgloss.Style) Option
- func WithListBulletStyle(s lipgloss.Style) Option
- func WithListIndent(n int) Option
- func WithListItemStyle(s lipgloss.Style) Option
- func WithMarkStyle(s lipgloss.Style) Option
- func WithNestedBulletChars(chars []string) Option
- func WithPalette(p ColorPalette) Option
- func WithParagraphStyle(s lipgloss.Style) Option
- func WithSmallStyle(s lipgloss.Style) Option
- func WithStrikethroughStyle(s lipgloss.Style) Option
- func WithTableBorderSet(bs TableBorderSet) Option
- func WithTableBorderStyle(s lipgloss.Style) Option
- func WithTableCaptionStyle(s lipgloss.Style) Option
- func WithTableCellPad(n int) Option
- func WithTableCellStyle(s lipgloss.Style) Option
- func WithTableFooterStyle(s lipgloss.Style) Option
- func WithTableHeaderStyle(s lipgloss.Style) Option
- func WithTableStripedCellStyle(s lipgloss.Style) Option
- func WithTagStyle(s lipgloss.Style) Option
- func WithTheme(t Theme) Option
- func WithUnderlineStyle(s lipgloss.Style) Option
- type TableBorderSet
- type TableOption
- func WithCaption(text string) TableOption
- func WithCaptionBottom(text string) TableOption
- func WithColumnAlign(col int, align Alignment) TableOption
- func WithColumnAligns(aligns ...Alignment) TableOption
- func WithColumnMaxWidth(col, n int) TableOption
- func WithFooterRow(enabled bool) TableOption
- func WithMaxColumnWidth(n int) TableOption
- func WithRowSeparators(enabled bool) TableOption
- func WithStripedRows(enabled bool) TableOption
- type Theme
- type Typography
- func (t *Typography) Abbr(abbr string, desc ...string) string
- func (t *Typography) Address(text string) string
- func (t *Typography) AddressCard(text string) string
- func (t *Typography) Alert(at AlertType, text string) string
- func (t *Typography) Badge(text string) string
- func (t *Typography) BadgeWithStyle(text string, style lipgloss.Style) string
- func (t *Typography) Blockquote(text string) string
- func (t *Typography) Bold(text string) string
- func (t *Typography) Caution(text string) string
- func (t *Typography) Code(text string, lang ...string) string
- func (t *Typography) CodeBlock(text string, lang ...string) string
- func (t *Typography) DD(text string) string
- func (t *Typography) DL(pairs [][2]string) string
- func (t *Typography) DT(text string) string
- func (t *Typography) Del(text string) string
- func (t *Typography) FootnoteRef(n int) string
- func (t *Typography) FootnoteSection(notes []string) string
- func (t *Typography) H1(text string) string
- func (t *Typography) H2(text string) string
- func (t *Typography) H3(text string) string
- func (t *Typography) H4(text string) string
- func (t *Typography) H5(text string) string
- func (t *Typography) H6(text string) string
- func (t *Typography) HR() string
- func (t *Typography) Important(text string) string
- func (t *Typography) Ins(text string) string
- func (t *Typography) Italic(text string) string
- func (t *Typography) Kbd(text string) string
- func (t *Typography) Link(label string, url ...string) string
- func (t *Typography) Mark(text string) string
- func (t *Typography) NestOL(items ...ListItem) string
- func (t *Typography) NestUL(items ...ListItem) string
- func (t *Typography) Note(text string) string
- func (t *Typography) OL(items ...string) string
- func (t *Typography) P(text string) string
- func (t *Typography) Small(text string) string
- func (t *Typography) Strikethrough(text string) string
- func (t *Typography) Sub(text string) string
- func (t *Typography) Sup(text string) string
- func (t *Typography) Table(rows [][]string) string
- func (t *Typography) TableWithOpts(rows [][]string, opts ...TableOption) string
- func (t *Typography) Tag(text string) string
- func (t *Typography) TagWithStyle(text string, style lipgloss.Style) string
- func (t *Typography) Theme() Theme
- func (t *Typography) Tip(text string) string
- func (t *Typography) UL(items ...string) string
- func (t *Typography) Underline(text string) string
- func (t *Typography) Warning(text string) string
Constants ¶
const ( DefaultAlertNoteIcon = "○" DefaultAlertTipIcon = "▸" DefaultAlertImportantIcon = "‼" DefaultAlertWarningIcon = "⚠" DefaultAlertCautionIcon = "◇" )
Default icon constants for each alert type. All are plain Unicode (no emoji) for broad terminal compatibility.
const ( DefaultAlertNoteLabel = "Note" DefaultAlertTipLabel = "Tip" DefaultAlertImportantLabel = "Important" DefaultAlertWarningLabel = "Warning" DefaultAlertCautionLabel = "Caution" )
Default label constants for each alert type.
const ( DefaultH1UnderlineChar = "═" DefaultH2UnderlineChar = "─" DefaultH3UnderlineChar = "·" DefaultHeadingBarChar = "▎" DefaultBulletChar = "•" DefaultListIndent = 2 DefaultHRChar = "─" DefaultHRWidth = 40 DefaultBlockquoteBar = "│" DefaultAlertBar = "│" DefaultCodeLineNumberSep = "│" DefaultTableCellPad = 1 DefaultInsPrefix = "+" DefaultDelPrefix = "-" DefaultFootnoteDividerChar = "─" DefaultFootnoteDividerWidth = 20 )
Default token values used by DefaultTheme and ThemeFromPalette.
Variables ¶
var DefaultNestedBulletChars = []string{"•", "◦", "▪", "▹"}
DefaultNestedBulletChars is the default set of bullet characters that cycle through nesting levels in nested unordered lists.
Functions ¶
func DefaultAlertConfigs ¶ added in v0.3.0
func DefaultAlertConfigs(ap AlertPalette) map[AlertType]AlertConfig
DefaultAlertConfigs builds a full map[AlertType]AlertConfig from an AlertPalette, using default icons and labels and creating a lipgloss.Style with the palette color as foreground.
Types ¶
type AlertConfig ¶ added in v0.3.0
type AlertConfig struct {
Icon string // Unicode icon for the header line
Label string // Text label (e.g. "Note")
Style lipgloss.Style // Foreground color applied to bar, icon, label, and content
}
AlertConfig holds the display properties for a single alert type.
type AlertPalette ¶ added in v0.3.0
type AlertPalette struct {
Note color.Color // blue
Tip color.Color // green
Important color.Color // purple
Warning color.Color // yellow/amber
Caution color.Color // red
}
AlertPalette defines the five colors used to derive alert styles. It is separate from ColorPalette because the existing 9-color palette does not cleanly map to 5 alert semantics.
type AlertType ¶ added in v0.3.0
type AlertType int
AlertType identifies a GitHub-style alert category.
const ( // AlertNote renders a blue informational alert. AlertNote AlertType = iota // AlertTip renders a green helpful-hint alert. AlertTip // AlertImportant renders a purple important-information alert. AlertImportant // AlertWarning renders a yellow/amber warning alert. AlertWarning // AlertCaution renders a red caution/danger alert. AlertCaution )
type Alignment ¶ added in v0.5.0
type Alignment int
Alignment represents the horizontal alignment of text within a table cell.
type CaptionPosition ¶ added in v0.5.0
type CaptionPosition int
CaptionPosition specifies where a table caption is rendered.
const ( // CaptionTop renders the caption above the table. CaptionTop CaptionPosition = iota // CaptionBottom renders the caption below the table. CaptionBottom )
type ColorPalette ¶ added in v0.2.0
type ColorPalette struct {
Primary color.Color // main text, H1 headings
Secondary color.Color // H2, list bullets, accents
Tertiary color.Color // H3, links
Accent color.Color // H4, marks/highlights
Highlight color.Color // H5, abbreviations
Muted color.Color // H6, comments, sub/sup, blockquote, DD, HR
Text color.Color // default body text, paragraphs, list items, DT
Surface color.Color // background for kbd
Base color.Color // background for inline code, code blocks, mark foreground
}
ColorPalette defines a minimal set of colors from which a full Theme can be derived. This allows users to share a single color palette across herald and other Charm ecosystem libraries (e.g. huh).
type ListItem ¶ added in v0.2.0
type ListItem struct {
Text string
Children []ListItem
Kind ListKind // how Children are rendered (UL vs OL)
}
ListItem represents a single entry in a nested list. It may contain children to create hierarchical lists.
func ItemWithChildren ¶ added in v0.2.0
ItemWithChildren creates a ListItem whose children are rendered as an unordered sub-list.
func ItemWithOLChildren ¶ added in v0.2.0
ItemWithOLChildren creates a ListItem whose children are rendered as an ordered sub-list.
type ListKind ¶ added in v0.2.0
type ListKind int
ListKind determines whether a list is rendered as unordered or ordered.
type Option ¶
type Option func(*Typography)
Option is a functional option for configuring a Typography instance.
func WithAbbrStyle ¶
WithAbbrStyle overrides the abbreviation style.
func WithAddressCardBorderStyle ¶ added in v0.6.0
WithAddressCardBorderStyle overrides the address card border style.
func WithAddressCardStyle ¶ added in v0.6.0
WithAddressCardStyle overrides the address card content style.
func WithAddressStyle ¶ added in v0.6.0
WithAddressStyle overrides the address/contact block style.
func WithAlertBar ¶ added in v0.3.0
WithAlertBar sets the left-bar character for alerts.
func WithAlertIcon ¶ added in v0.3.0
WithAlertIcon overrides the icon for a specific alert type.
func WithAlertLabel ¶ added in v0.3.0
WithAlertLabel overrides the label for a specific alert type.
func WithAlertPalette ¶ added in v0.3.0
func WithAlertPalette(ap AlertPalette) Option
WithAlertPalette rebuilds all alert configs from the given AlertPalette, using default icons and labels.
func WithAlertStyle ¶ added in v0.3.0
WithAlertStyle overrides the style for a specific alert type.
func WithBadgeStyle ¶ added in v0.6.0
WithBadgeStyle overrides the badge/tag pill style.
func WithBlockquoteBar ¶
WithBlockquoteBar sets the left-bar character for blockquotes.
func WithBlockquoteBarStyle ¶ added in v0.6.0
WithBlockquoteBarStyle overrides the blockquote bar character style.
func WithBlockquoteStyle ¶
WithBlockquoteStyle overrides the blockquote style.
func WithBoldStyle ¶
WithBoldStyle overrides the bold style.
func WithBulletChar ¶
WithBulletChar sets the bullet character for unordered lists.
func WithCodeBlockStyle ¶
WithCodeBlockStyle overrides the code block style.
func WithCodeFormatter ¶ added in v0.2.0
WithCodeFormatter sets a callback that receives raw code and a language hint, returning syntax-highlighted text. The highlighted text is then wrapped in the CodeInline or CodeBlock style for consistent padding/margins.
func WithCodeInlineStyle ¶
WithCodeInlineStyle overrides the inline code style.
func WithCodeLineNumberSep ¶ added in v0.4.0
WithCodeLineNumberSep sets the separator between line numbers and code content.
func WithCodeLineNumberStyle ¶ added in v0.4.0
WithCodeLineNumberStyle overrides the style for code block line numbers.
func WithCodeLineNumbers ¶ added in v0.4.0
WithCodeLineNumbers enables or disables line numbers in code blocks.
func WithDDStyle ¶
WithDDStyle overrides the definition description style.
func WithDTStyle ¶
WithDTStyle overrides the definition term style.
func WithDelPrefix ¶ added in v0.6.0
WithDelPrefix sets the prefix for deleted text.
func WithDelStyle ¶ added in v0.6.0
WithDelStyle overrides the deleted text style.
func WithFootnoteDividerChar ¶ added in v0.6.0
WithFootnoteDividerChar sets the character used for the footnote section divider.
func WithFootnoteDividerStyle ¶ added in v0.6.0
WithFootnoteDividerStyle overrides the footnote divider style.
func WithFootnoteDividerWidth ¶ added in v0.6.0
WithFootnoteDividerWidth sets the width of the footnote section divider.
func WithFootnoteItemStyle ¶ added in v0.6.0
WithFootnoteItemStyle overrides the footnote item style.
func WithFootnoteRefStyle ¶ added in v0.6.0
WithFootnoteRefStyle overrides the inline footnote reference marker style.
func WithH1Style ¶
WithH1Style overrides the H1 heading style.
func WithH1UnderlineChar ¶
WithH1UnderlineChar sets the character used for the H1 underline.
func WithH2Style ¶
WithH2Style overrides the H2 heading style.
func WithH2UnderlineChar ¶
WithH2UnderlineChar sets the character used for the H2 underline.
func WithH3Style ¶
WithH3Style overrides the H3 heading style.
func WithH3UnderlineChar ¶
WithH3UnderlineChar sets the character used for the H3 underline.
func WithH4Style ¶
WithH4Style overrides the H4 heading style.
func WithH5Style ¶
WithH5Style overrides the H5 heading style.
func WithH6Style ¶
WithH6Style overrides the H6 heading style.
func WithHRChar ¶
WithHRChar sets the character used for horizontal rules.
func WithHRStyle ¶
WithHRStyle overrides the horizontal rule style.
func WithHRWidth ¶
WithHRWidth sets the width of horizontal rules in characters.
func WithHeadingBarChar ¶
WithHeadingBarChar sets the bar prefix character for H4-H6.
func WithHierarchicalNumbers ¶ added in v0.2.0
WithHierarchicalNumbers enables hierarchical numbering for nested ordered lists (e.g. 1., 1.1, 1.2, 2., 2.1). When false (default), each nested sub-list restarts numbering at 1.
func WithInsPrefix ¶ added in v0.6.0
WithInsPrefix sets the prefix for inserted text.
func WithInsStyle ¶ added in v0.6.0
WithInsStyle overrides the inserted text style.
func WithItalicStyle ¶
WithItalicStyle overrides the italic style.
func WithKbdStyle ¶
WithKbdStyle overrides the keyboard key style.
func WithLinkStyle ¶
WithLinkStyle overrides the link style.
func WithListBulletStyle ¶
WithListBulletStyle overrides the bullet/number marker style.
func WithListIndent ¶ added in v0.2.0
WithListIndent sets the number of spaces per nesting level for nested lists.
func WithListItemStyle ¶
WithListItemStyle overrides the list item text style.
func WithMarkStyle ¶
WithMarkStyle overrides the highlight/mark style.
func WithNestedBulletChars ¶ added in v0.2.0
WithNestedBulletChars sets the bullet characters that cycle through nesting levels in nested unordered lists.
func WithPalette ¶ added in v0.2.0
func WithPalette(p ColorPalette) Option
WithPalette derives a complete theme from a ColorPalette and sets it. It is a convenience shortcut for WithTheme(ThemeFromPalette(p)).
func WithParagraphStyle ¶
WithParagraphStyle overrides the paragraph style.
func WithSmallStyle ¶
WithSmallStyle overrides the small/faint style.
func WithStrikethroughStyle ¶
WithStrikethroughStyle overrides the strikethrough style.
func WithTableBorderSet ¶ added in v0.5.0
func WithTableBorderSet(bs TableBorderSet) Option
WithTableBorderSet sets the box-drawing character set for tables.
func WithTableBorderStyle ¶ added in v0.5.0
WithTableBorderStyle overrides the style applied to table border characters.
func WithTableCaptionStyle ¶ added in v0.5.0
WithTableCaptionStyle overrides the table caption style.
func WithTableCellPad ¶ added in v0.5.0
WithTableCellPad sets the number of spaces of padding inside each table cell.
func WithTableCellStyle ¶ added in v0.5.0
WithTableCellStyle overrides the table body cell style.
func WithTableFooterStyle ¶ added in v0.5.0
WithTableFooterStyle overrides the table footer row style.
func WithTableHeaderStyle ¶ added in v0.5.0
WithTableHeaderStyle overrides the table header cell style.
func WithTableStripedCellStyle ¶ added in v0.5.0
WithTableStripedCellStyle overrides the style for alternating body rows when striped rows are enabled.
func WithTagStyle ¶ added in v0.6.0
WithTagStyle overrides the tag/category label style.
func WithUnderlineStyle ¶
WithUnderlineStyle overrides the underline style.
type TableBorderSet ¶ added in v0.5.0
type TableBorderSet struct {
Top string // horizontal line for top border
Bottom string // horizontal line for bottom border
Left string // vertical line for left border
Right string // vertical line for right border
Header string // horizontal line separating header from body
Row string // horizontal line between rows (optional, empty = no row separators)
TopLeft string // top-left corner
TopRight string // top-right corner
BottomLeft string // bottom-left corner
BottomRight string // bottom-right corner
TopJunction string // top edge junction (┬)
BottomJunction string // bottom edge junction (┴)
LeftJunction string // left edge junction (├)
RightJunction string // right edge junction (┤)
Cross string // interior junction (┼)
HeaderLeft string // header-row left junction
HeaderRight string // header-row right junction
HeaderCross string // header-row interior junction
}
TableBorderSet holds all box-drawing characters needed to render a table.
func BoxBorderSet ¶ added in v0.5.0
func BoxBorderSet() TableBorderSet
BoxBorderSet returns a TableBorderSet using full Unicode box-drawing characters.
func MinimalBorderSet ¶ added in v0.5.0
func MinimalBorderSet() TableBorderSet
MinimalBorderSet returns a TableBorderSet with no outer borders — only column separators and a header underline.
type TableOption ¶ added in v0.5.0
type TableOption func(*tableConfig)
TableOption is a functional option for per-table configuration. It is distinct from Option, which configures the Typography instance.
func WithCaption ¶ added in v0.5.0
func WithCaption(text string) TableOption
WithCaption adds a caption above the table.
func WithCaptionBottom ¶ added in v0.5.0
func WithCaptionBottom(text string) TableOption
WithCaptionBottom adds a caption below the table.
func WithColumnAlign ¶ added in v0.5.0
func WithColumnAlign(col int, align Alignment) TableOption
WithColumnAlign sets the alignment for a specific column (0-indexed). Columns without an explicit alignment default to AlignLeft.
func WithColumnAligns ¶ added in v0.5.0
func WithColumnAligns(aligns ...Alignment) TableOption
WithColumnAligns sets the alignment for columns 0, 1, 2, ... in order. Columns beyond the length of the slice default to AlignLeft.
func WithColumnMaxWidth ¶ added in v0.5.0
func WithColumnMaxWidth(col, n int) TableOption
WithColumnMaxWidth sets the maximum visible width for a specific column (0-indexed). Cells exceeding this width are truncated with "…". This overrides the global WithMaxColumnWidth for the given column.
func WithFooterRow ¶ added in v0.5.0
func WithFooterRow(enabled bool) TableOption
WithFooterRow treats the last row as a footer with a distinct separator and the TableFooter style.
func WithMaxColumnWidth ¶ added in v0.5.0
func WithMaxColumnWidth(n int) TableOption
WithMaxColumnWidth sets a global maximum visible width for all columns. Cells exceeding this width are truncated with "…". A value of 0 disables truncation. Per-column limits set via WithColumnMaxWidth take precedence.
func WithRowSeparators ¶ added in v0.5.0
func WithRowSeparators(enabled bool) TableOption
WithRowSeparators enables horizontal separator lines between every body row.
func WithStripedRows ¶ added in v0.5.0
func WithStripedRows(enabled bool) TableOption
WithStripedRows enables alternating row background styles for readability. Odd body rows use the TableStripedCell style instead of TableCell.
type Theme ¶
type Theme struct {
// Headings H1-H6
H1 lipgloss.Style
H2 lipgloss.Style
H3 lipgloss.Style
H4 lipgloss.Style
H5 lipgloss.Style
H6 lipgloss.Style
// Text block elements
Paragraph lipgloss.Style
Blockquote lipgloss.Style
BlockquoteBarStyle lipgloss.Style // style for the blockquote bar character(s)
CodeInline lipgloss.Style
CodeBlock lipgloss.Style
HR lipgloss.Style
// List elements
ListBullet lipgloss.Style // style for the bullet/number marker
ListItem lipgloss.Style // style for list item text
// Inline styles
Bold lipgloss.Style
Italic lipgloss.Style
Underline lipgloss.Style
Strikethrough lipgloss.Style
Small lipgloss.Style
Mark lipgloss.Style
Link lipgloss.Style
Kbd lipgloss.Style
Abbr lipgloss.Style
Sub lipgloss.Style
Sup lipgloss.Style
Ins lipgloss.Style
Del lipgloss.Style
// Definition list
DT lipgloss.Style // definition term
DD lipgloss.Style // definition description
// Address element
Address lipgloss.Style // style for address/contact blocks
AddressCard lipgloss.Style // content style for bordered address card
AddressCardBorder lipgloss.Style // border color/style for address card (same pattern as TableBorder)
// Badge / Tag elements
Badge lipgloss.Style // style for bold pill/status labels
Tag lipgloss.Style // style for subtle pill/category labels
// Footnote elements
FootnoteRef lipgloss.Style // style for inline reference markers (e.g. "[1]")
FootnoteItem lipgloss.Style // style for each footnote entry in the section
FootnoteDivider lipgloss.Style // style for the divider line above the footnote section
// Callbacks
CodeFormatter func(code, language string) string // optional syntax highlighter
// Heading decoration
H1UnderlineChar string // character repeated under H1 (e.g. "═")
H2UnderlineChar string // character repeated under H2 (e.g. "─")
H3UnderlineChar string // character repeated under H3 (e.g. "·")
HeadingBarChar string // left-bar prefix for H4-H6 (e.g. "▎")
// Code block line numbers
CodeLineNumber lipgloss.Style // style for line number text
CodeLineNumberSep string // separator between line number and code (e.g. "│")
ShowLineNumbers bool // whether to render line numbers in CodeBlock
// Configurable tokens
BulletChar string // character used for unordered list bullets
NestedBulletChars []string // bullet chars cycling per depth for nested lists
ListIndent int // spaces per nesting level for nested lists
HierarchicalNumbers bool // use hierarchical numbering (e.g. 2.1, 2.2) for nested OL
HRChar string // character repeated for horizontal rules
HRWidth int // width of horizontal rule in characters
BlockquoteBar string // left-bar character for blockquotes
InsPrefix string // prefix for inserted text (e.g. "+")
DelPrefix string // prefix for deleted text (e.g. "-")
FootnoteDividerChar string // character for footnote section divider (default "─")
FootnoteDividerWidth int // width of footnote divider (default 20)
// Table elements
TableHeader lipgloss.Style // style for header cell text (e.g. bold + primary color)
TableCell lipgloss.Style // style for body cell text
TableStripedCell lipgloss.Style // style for alternating (odd) body rows when striping is enabled
TableCaption lipgloss.Style // style for table caption text
TableBorder lipgloss.Style // style (color) applied to border characters
TableBorderSet TableBorderSet // box-drawing character set
TableCellPad int // spaces of padding inside each cell (default 1)
// Alert elements
Alerts map[AlertType]AlertConfig // per-type icon, label, and style
AlertBar string // left-bar character for alerts
}
Theme holds all style definitions used by Typography to render elements. Each field corresponds to a visual element and is a lipgloss.Style.
func Base16Theme ¶ added in v0.2.0
func Base16Theme() Theme
Base16Theme returns a Theme based on ANSI base16 terminal colors. Colors match huh's ThemeBase16. Base16 uses standard ANSI color indices; adaptive colors are used for API consistency.
func CatppuccinTheme ¶ added in v0.2.0
func CatppuccinTheme() Theme
CatppuccinTheme returns a Theme based on the Catppuccin color palette. Adapts to the terminal background: Mocha on dark, Latte on light. Colors match huh's ThemeCatppuccin.
func CharmTheme ¶ added in v0.2.0
func CharmTheme() Theme
CharmTheme returns a Theme based on Charm's brand color palette. Auto-detects terminal background for light/dark variants. Colors match huh's ThemeCharm.
func DefaultTheme ¶
func DefaultTheme() Theme
DefaultTheme returns a Theme based on the Rose Pine color palette.
func DraculaTheme ¶ added in v0.2.0
func DraculaTheme() Theme
DraculaTheme returns a Theme based on the Dracula color palette. Colors match huh's ThemeDracula. Dracula is a dark-only palette; adaptive colors are used for API consistency.
func ThemeFromPalette ¶ added in v0.2.0
func ThemeFromPalette(p ColorPalette) Theme
ThemeFromPalette constructs a complete Theme by mapping palette colors to all style fields. Configurable tokens use the same defaults as DefaultTheme.
type Typography ¶
type Typography struct {
// contains filtered or unexported fields
}
Typography is the central renderer. It holds a Theme and exposes methods for every supported typographic element.
func New ¶
func New(opts ...Option) *Typography
New creates a new Typography instance with the default theme, then applies any provided functional options.
func (*Typography) Abbr ¶
func (t *Typography) Abbr(abbr string, desc ...string) string
Abbr renders an abbreviation. If a description is provided it is shown in parentheses after the abbreviation.
func (*Typography) Address ¶ added in v0.6.0
func (t *Typography) Address(text string) string
Address renders a styled contact/author information block.
func (*Typography) AddressCard ¶ added in v0.6.0
func (t *Typography) AddressCard(text string) string
AddressCard renders a contact/author block inside a bordered card. The border color is taken from the AddressCardBorder theme style.
func (*Typography) Alert ¶ added in v0.3.0
func (t *Typography) Alert(at AlertType, text string) string
Alert renders a GitHub-style alert callout. The header line (bar + icon + label) is bold + colored; content lines have a colored bar but unstyled text, matching GitHub's visual style. If the alert type is not configured, it falls back to blockquote rendering.
func (*Typography) Badge ¶ added in v0.6.0
func (t *Typography) Badge(text string) string
Badge renders text as a styled pill/tag label.
func (*Typography) BadgeWithStyle ¶ added in v0.6.0
func (t *Typography) BadgeWithStyle(text string, style lipgloss.Style) string
BadgeWithStyle renders a badge using a one-off style override, useful for semantic variants (success, warning, error) without changing the theme.
func (*Typography) Blockquote ¶
func (t *Typography) Blockquote(text string) string
Blockquote renders a blockquote with a left border bar. Multi-line text is handled by prepending the bar to every line. The bar is styled separately from the text so it remains visually distinct.
func (*Typography) Caution ¶ added in v0.3.0
func (t *Typography) Caution(text string) string
Caution renders a red caution/danger alert.
func (*Typography) Code ¶
func (t *Typography) Code(text string, lang ...string) string
Code renders inline code. If a language is provided and a CodeFormatter is set on the theme, the formatter is applied before wrapping in the style.
func (*Typography) CodeBlock ¶
func (t *Typography) CodeBlock(text string, lang ...string) string
CodeBlock renders a fenced code block. If a language is provided and a CodeFormatter is set on the theme, the formatter is applied before wrapping in the style. When ShowLineNumbers is true, line numbers are prepended to each line after formatting.
func (*Typography) DD ¶
func (t *Typography) DD(text string) string
DD renders a single definition description.
func (*Typography) DL ¶
func (t *Typography) DL(pairs [][2]string) string
DL renders a definition list from term-description pairs. Each pair is a two-element array: [term, description]. Odd-length slices ignore the last unpaired element.
func (*Typography) DT ¶
func (t *Typography) DT(text string) string
DT renders a single definition term.
func (*Typography) Del ¶ added in v0.6.0
func (t *Typography) Del(text string) string
Del renders deleted (removed) text with a prefix marker.
func (*Typography) FootnoteRef ¶ added in v0.6.0
func (t *Typography) FootnoteRef(n int) string
FootnoteRef renders an inline footnote reference marker, e.g. "[1]".
func (*Typography) FootnoteSection ¶ added in v0.6.0
func (t *Typography) FootnoteSection(notes []string) string
FootnoteSection renders the collected footnotes as a numbered list, preceded by a divider line. Returns an empty string if notes is empty.
func (*Typography) H1 ¶
func (t *Typography) H1(text string) string
H1 renders text as a level-1 heading with a double-line underline.
func (*Typography) H2 ¶
func (t *Typography) H2(text string) string
H2 renders text as a level-2 heading with a single-line underline.
func (*Typography) H3 ¶
func (t *Typography) H3(text string) string
H3 renders text as a level-3 heading with a dotted underline.
func (*Typography) H4 ¶
func (t *Typography) H4(text string) string
H4 renders text as a level-4 heading with a bar prefix.
func (*Typography) H5 ¶
func (t *Typography) H5(text string) string
H5 renders text as a level-5 heading with a bar prefix.
func (*Typography) H6 ¶
func (t *Typography) H6(text string) string
H6 renders text as a level-6 heading with a bar prefix.
func (*Typography) Important ¶ added in v0.3.0
func (t *Typography) Important(text string) string
Important renders a purple important-information alert.
func (*Typography) Ins ¶ added in v0.6.0
func (t *Typography) Ins(text string) string
Ins renders inserted (added) text with a prefix marker.
func (*Typography) Italic ¶
func (t *Typography) Italic(text string) string
Italic renders italic text.
func (*Typography) Kbd ¶
func (t *Typography) Kbd(text string) string
Kbd renders a keyboard key indicator.
func (*Typography) Link ¶
func (t *Typography) Link(label string, url ...string) string
Link renders a styled URL or link text. If both label and url are provided, it renders as "label (url)". If only one argument is given, it is treated as both the label and the URL.
func (*Typography) Mark ¶
func (t *Typography) Mark(text string) string
Mark renders highlighted text.
func (*Typography) NestOL ¶ added in v0.2.0
func (t *Typography) NestOL(items ...ListItem) string
NestOL renders a nested ordered list from the provided ListItems.
func (*Typography) NestUL ¶ added in v0.2.0
func (t *Typography) NestUL(items ...ListItem) string
NestUL renders a nested unordered list from the provided ListItems.
func (*Typography) Note ¶ added in v0.3.0
func (t *Typography) Note(text string) string
Note renders a blue informational alert.
func (*Typography) OL ¶
func (t *Typography) OL(items ...string) string
OL renders an ordered (numbered) list from the provided items.
func (*Typography) Small ¶
func (t *Typography) Small(text string) string
Small renders small/faint text.
func (*Typography) Strikethrough ¶
func (t *Typography) Strikethrough(text string) string
Strikethrough renders strikethrough text.
func (*Typography) Sub ¶
func (t *Typography) Sub(text string) string
Sub renders a subscript marker. In a terminal we prefix with an underscore to visually indicate subscript.
func (*Typography) Sup ¶
func (t *Typography) Sup(text string) string
Sup renders a superscript marker. In a terminal we prefix with a caret to visually indicate superscript.
func (*Typography) Table ¶ added in v0.5.0
func (t *Typography) Table(rows [][]string) string
Table renders a table from a slice of rows. The first row is treated as the header. Each row is a slice of cell strings. Rows may have different lengths; shorter rows are padded with empty cells. Returns an empty string if rows is nil or empty.
func (*Typography) TableWithOpts ¶ added in v0.5.0
func (t *Typography) TableWithOpts(rows [][]string, opts ...TableOption) string
TableWithOpts renders a table like Table but accepts per-table options such as column alignment. The first row is treated as the header.
t.TableWithOpts(rows,
herald.WithColumnAlign(0, herald.AlignCenter),
herald.WithColumnAlign(2, herald.AlignRight),
)
func (*Typography) Tag ¶ added in v0.6.0
func (t *Typography) Tag(text string) string
Tag renders text as a subtle pill/category label.
func (*Typography) TagWithStyle ¶ added in v0.6.0
func (t *Typography) TagWithStyle(text string, style lipgloss.Style) string
TagWithStyle renders a tag using a one-off style override.
func (*Typography) Theme ¶
func (t *Typography) Theme() Theme
Theme returns a copy of the current theme.
func (*Typography) Tip ¶ added in v0.3.0
func (t *Typography) Tip(text string) string
Tip renders a green helpful-hint alert.
func (*Typography) UL ¶
func (t *Typography) UL(items ...string) string
UL renders an unordered (bulleted) list from the provided items.
func (*Typography) Underline ¶
func (t *Typography) Underline(text string) string
Underline renders underlined text.
func (*Typography) Warning ¶ added in v0.3.0
func (t *Typography) Warning(text string) string
Warning renders a yellow/amber warning alert.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
00_default-theme
command
herald with the default Rose Pine theme.
|
herald with the default Rose Pine theme. |
|
01_lists
command
Demonstrates flat lists, nested lists, mixed nesting, and hierarchical numbering.
|
Demonstrates flat lists, nested lists, mixed nesting, and hierarchical numbering. |
|
02_alerts
command
GitHub-style alerts demo with the default Rose Pine theme.
|
GitHub-style alerts demo with the default Rose Pine theme. |
|
03_custom-options
command
Customizing herald with functional options: override individual styles, decoration characters, and tokens without replacing the entire theme.
|
Customizing herald with functional options: override individual styles, decoration characters, and tokens without replacing the entire theme. |
|
04_palette
command
Using ColorPalette to create a consistent theme from just 8 colors.
|
Using ColorPalette to create a consistent theme from just 8 colors. |
|
05_builtin-themes
command
Using herald's built-in named themes that match huh's color palettes.
|
Using herald's built-in named themes that match huh's color palettes. |
|
09_table
command
Table rendering: bordered (default), minimal, custom padding, custom styles, column alignment, row separators, striped rows, captions, footer rows, and auto-truncation.
|
Table rendering: bordered (default), minimal, custom padding, custom styles, column alignment, row separators, striped rows, captions, footer rows, and auto-truncation. |
|
demos/alerts
command
GitHub-style alerts: Note, Tip, Important, Warning, Caution.
|
GitHub-style alerts: Note, Tip, Important, Warning, Caution. |
|
demos/blocks
command
Block-level elements: paragraph, blockquote, code block, HR, and definition list.
|
Block-level elements: paragraph, blockquote, code block, HR, and definition list. |
|
demos/builtin-themes/base16
command
Base16 theme showcase.
|
Base16 theme showcase. |
|
demos/builtin-themes/catppuccin
command
Catppuccin theme showcase.
|
Catppuccin theme showcase. |
|
demos/builtin-themes/charm
command
Charm theme showcase.
|
Charm theme showcase. |
|
demos/builtin-themes/dracula
command
Dracula theme showcase.
|
Dracula theme showcase. |
|
demos/headings
command
All six heading levels with the default Rose Pine theme.
|
All six heading levels with the default Rose Pine theme. |
|
demos/hero
command
Compact highlight reel for the README hero image.
|
Compact highlight reel for the README hero image. |
|
demos/inline
command
Inline styles, links, and abbreviations.
|
Inline styles, links, and abbreviations. |
|
demos/lists
command
Flat and nested lists with mixed nesting.
|
Flat and nested lists with mixed nesting. |
|
demos/tables
command
Table elements: bordered, minimal, alignment, striped rows, caption, footer, and auto-truncation.
|
Table elements: bordered, minimal, alignment, striped rows, caption, footer, and auto-truncation. |



