Documentation
¶
Overview ¶
Package herald provides a reusable TUI typography library inspired by CSS frameworks such as Tailwind Typography, Bootstrap, and Pico CSS.
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 ¶
- type Option
- func WithAbbrStyle(s lipgloss.Style) Option
- func WithBlockquoteBar(c string) 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 WithCodeInlineStyle(s lipgloss.Style) Option
- func WithDDStyle(s lipgloss.Style) Option
- func WithDTStyle(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 WithItalicStyle(s lipgloss.Style) Option
- func WithKbdStyle(s lipgloss.Style) Option
- func WithLinkStyle(s lipgloss.Style) Option
- func WithListBulletStyle(s lipgloss.Style) Option
- func WithListItemStyle(s lipgloss.Style) Option
- func WithMarkStyle(s lipgloss.Style) Option
- func WithParagraphStyle(s lipgloss.Style) Option
- func WithSmallStyle(s lipgloss.Style) Option
- func WithStrikethroughStyle(s lipgloss.Style) Option
- func WithTheme(t Theme) Option
- func WithUnderlineStyle(s lipgloss.Style) Option
- type Theme
- type Typography
- func (t *Typography) Abbr(abbr string, desc ...string) string
- func (t *Typography) Blockquote(text string) string
- func (t *Typography) Bold(text string) string
- func (t *Typography) Code(text string) string
- func (t *Typography) CodeBlock(text 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) 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) 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) 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) Theme() Theme
- func (t *Typography) UL(items ...string) string
- func (t *Typography) Underline(text string) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Typography)
Option is a functional option for configuring a Typography instance.
func WithAbbrStyle ¶
WithAbbrStyle overrides the abbreviation style.
func WithBlockquoteBar ¶
WithBlockquoteBar sets the left-bar character for blockquotes.
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 WithCodeInlineStyle ¶
WithCodeInlineStyle overrides the inline code style.
func WithDDStyle ¶
WithDDStyle overrides the definition description style.
func WithDTStyle ¶
WithDTStyle overrides the definition term 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 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 WithListItemStyle ¶
WithListItemStyle overrides the list item text style.
func WithMarkStyle ¶
WithMarkStyle overrides the highlight/mark style.
func WithParagraphStyle ¶
WithParagraphStyle overrides the paragraph style.
func WithSmallStyle ¶
WithSmallStyle overrides the small/faint style.
func WithStrikethroughStyle ¶
WithStrikethroughStyle overrides the strikethrough style.
func WithUnderlineStyle ¶
WithUnderlineStyle overrides the underline style.
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
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
// Definition list
DT lipgloss.Style // definition term
DD lipgloss.Style // definition description
// 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. "▎")
// Configurable tokens
BulletChar string // character used for unordered list bullets
HRChar string // character repeated for horizontal rules
HRWidth int // width of horizontal rule in characters
BlockquoteBar string // left-bar character for blockquotes
}
Theme holds all style definitions used by Typography to render elements. Each field corresponds to a visual element and is a lipgloss.Style.
func DefaultTheme ¶
func DefaultTheme() Theme
DefaultTheme returns a Theme with sensible default styles that look great in most terminal environments.
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) 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.
func (*Typography) CodeBlock ¶
func (t *Typography) CodeBlock(text string) string
CodeBlock renders a fenced code block.
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) 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) 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) 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) Theme ¶
func (t *Typography) Theme() Theme
Theme returns a copy of the current theme.
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
basic
command
Basic usage of herald with the default Rose Pine theme.
|
Basic usage of herald with the default Rose Pine theme. |
|
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. |