pango

package
v0.0.0-...-5e9ad74 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Package pango provides a type-safe way to construct pango markup. Using nested Span and Text nodes, pango formatted output can be easily constructed with compile-time validation of nesting and automatic escaping.

For example, to construct pango markup for:

<span color="#ff0000">Red <span weight="bold">Bold Text</span></span>

the go code would be:

pango.New(
  pango.Text("Red "),
  pango.Text("Bold Text").Bold()).
Color(colors.Hex("#ff0000"))

or:

pango.Text("Red ").
  Color(colors.Hex("#ff0000")).
  Append(pango.Text("Bold Text").Bold())

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddIconProvider

func AddIconProvider(name string, provider IconProvider)

AddIconProvider adds an icon provider for a given prefix. This is intended for use only by the pango/icons package. See "pango/icons".LoadFromFile for more details.

func SetUnitFormatter

func SetUnitFormatter(f func(format.Values) *Node)

SetUnitFormatter sets the formatter to use in pango.Unit.

Types

type IconProvider

type IconProvider func(string) *Node

IconProvider is an interface for providing pango Icons. The function should return a pango node for the given icon name, or nil if an icon could not be found.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node represents a node in a pango "document".

func Icon

func Icon(ident string) *Node

Icon returns a pango node that displays the given icon. The identifier must be of the form $provider-$name, and the returned node will render the $name icon using $provider. e.g. "fa-add" will render the "add" icon using font awesome.

func New

func New(children ...*Node) *Node

New constructs a markup node that wraps the given Nodes.

func Text

func Text(s string) *Node

Text constructs a text node.

func Textf

func Textf(format string, args ...interface{}) *Node

Textf constructs a text node by interpolating arguments. Note that it will escape both the format string and arguments, so you should use pango constructs to add formatting. i.e.,

Textf("<span color='%s'>%s</span>", "red", "text")

won't give you red text.

func Unit

func Unit(val ...format.Value) *Node

Unit formats a format.Value into a pango.Node.

func (*Node) Alpha

func (n *Node) Alpha(alpha float64) *Node

Alpha applies just a foreground alpha, keeping the default text colour.

func (*Node) Append

func (n *Node) Append(nodes ...*Node) *Node

Append adds one or more nodes as children of the current node. The new nodes will inherit styles by virtue of being descendants, to insert them *adjacent* to the current node, use .Concat(...).

func (*Node) AppendText

func (n *Node) AppendText(texts ...string) *Node

AppendText is a shortcut for Append(pango.Text(...), pango.Text(...), ...)

func (*Node) AppendTextf

func (n *Node) AppendTextf(format string, args ...interface{}) *Node

AppendTextf is a shortcut for Append(pango.Textf(...))

func (*Node) Background

func (n *Node) Background(c color.Color) *Node

Background applies a background color and alpha.

func (*Node) Bold

func (n *Node) Bold() *Node

Bold sets the pango weight to "bold".

func (*Node) Color

func (n *Node) Color(c color.Color) *Node

Color applies a foreground color and alpha.

func (*Node) Concat

func (n *Node) Concat(nodes ...*Node) *Node

Concat adds the given nodes as siblings rather than children of the current node, and returns a wrapping node for further operations.

For example,

Text("c").Condensed().Color(red).Concat(Text("foo")).UnderlineError()

will create

<span underline='error'><span stretch='condensed' color='#ff0000'>c</span>foo</span>

where the appended "foo" is not condensed or red, and everything is underlined.

func (*Node) ConcatText

func (n *Node) ConcatText(texts ...string) *Node

ConcatText is a shortcut for Concat(pango.Text(...), pango.Text(...), ...)

func (*Node) ConcatTextf

func (n *Node) ConcatTextf(format string, args ...interface{}) *Node

ConcatTextf is a shortcut for Append(pango.Textf(...))

func (*Node) Condensed

func (n *Node) Condensed() *Node

Condensed sets the pango stretch to "condensed".

func (*Node) Expanded

func (n *Node) Expanded() *Node

Expanded sets the pango stretch to "expanded".

func (*Node) ExtraCondensed

func (n *Node) ExtraCondensed() *Node

ExtraCondensed sets the pango stretch to "extracondensed".

func (*Node) ExtraExpanded

func (n *Node) ExtraExpanded() *Node

ExtraExpanded sets the pango stretch to "extraexpanded".

func (*Node) Font

func (n *Node) Font(face string) *Node

Font sets the font face.

func (*Node) Heavy

func (n *Node) Heavy() *Node

Heavy sets the pango weight to "heavy".

func (*Node) Italic

func (n *Node) Italic() *Node

Italic sets the pango style to "italic".

func (*Node) Large

func (n *Node) Large() *Node

Large sets the pango size to "large".

func (*Node) Larger

func (n *Node) Larger() *Node

Larger increases the font size of the contents by wrapping them in <big>...</big>

func (*Node) LetterSpacing

func (n *Node) LetterSpacing(spacing float64) *Node

LetterSpacing sets the letter spacing, in points.

func (*Node) Light

func (n *Node) Light() *Node

Light sets the pango weight to "light".

func (*Node) Medium

func (n *Node) Medium() *Node

Medium sets the pango size to "medium".

func (*Node) NoStrikethrough

func (n *Node) NoStrikethrough() *Node

NoStrikethrough sets the pango strikethrough to "false".

func (*Node) Oblique

func (n *Node) Oblique() *Node

Oblique sets the pango style to "oblique".

func (*Node) Rise

func (n *Node) Rise(rise int) *Node

Rise sets the font "rise" in pango units. Negative for subscript, positive for superscript.

func (*Node) Segments

func (n *Node) Segments() []*bar.Segment

Segments implements bar.Output for a single pango Node.

func (*Node) SemiCondensed

func (n *Node) SemiCondensed() *Node

SemiCondensed sets the pango stretch to "semicondensed".

func (*Node) SemiExpanded

func (n *Node) SemiExpanded() *Node

SemiExpanded sets the pango stretch to "semiexpanded".

func (*Node) Size

func (n *Node) Size(size float64) *Node

Size sets the font size, in points.

func (*Node) Small

func (n *Node) Small() *Node

Small sets the pango size to "small".

func (*Node) SmallCaps

func (n *Node) SmallCaps() *Node

SmallCaps sets the pango variant to "smallcaps".

func (*Node) Smaller

func (n *Node) Smaller() *Node

Smaller decreases the font size of the contents by wrapping them in <small>...</small>

func (*Node) StretchNormal

func (n *Node) StretchNormal() *Node

StretchNormal sets the pango stretch to "normal".

func (*Node) Strikethrough

func (n *Node) Strikethrough() *Node

Strikethrough sets the pango strikethrough to "true".

func (*Node) StrikethroughColor

func (n *Node) StrikethroughColor(c color.Color) *Node

StrikethroughColor applies a strikethrough color.

func (*Node) String

func (n *Node) String() string

Pango returns a pango-formatted version of the node.

func (*Node) StyleNormal

func (n *Node) StyleNormal() *Node

StyleNormal sets the pango style to "normal".

func (*Node) UltraBold

func (n *Node) UltraBold() *Node

UltraBold sets the pango weight to "ultrabold".

func (*Node) UltraCondensed

func (n *Node) UltraCondensed() *Node

UltraCondensed sets the pango stretch to "ultracondensed".

func (*Node) UltraExpanded

func (n *Node) UltraExpanded() *Node

UltraExpanded sets the pango stretch to "ultraexpanded".

func (*Node) UltraLight

func (n *Node) UltraLight() *Node

UltraLight sets the pango weight to "ultralight".

func (*Node) UnderlineColor

func (n *Node) UnderlineColor(c color.Color) *Node

UnderlineColor applies an underline color.

func (*Node) UnderlineDouble

func (n *Node) UnderlineDouble() *Node

UnderlineDouble sets the pango underline to "double".

func (*Node) UnderlineError

func (n *Node) UnderlineError() *Node

UnderlineError sets the pango underline to "error".

func (*Node) UnderlineLow

func (n *Node) UnderlineLow() *Node

UnderlineLow sets the pango underline to "low".

func (*Node) UnderlineNone

func (n *Node) UnderlineNone() *Node

UnderlineNone sets the pango underline to "none".

func (*Node) UnderlineSingle

func (n *Node) UnderlineSingle() *Node

UnderlineSingle sets the pango underline to "single".

func (*Node) VariantNormal

func (n *Node) VariantNormal() *Node

VariantNormal sets the pango variant to "normal".

func (*Node) Weight

func (n *Node) Weight(weight int) *Node

Weight sets the font weight in numeric form.

func (*Node) WeightNormal

func (n *Node) WeightNormal() *Node

WeightNormal sets the pango weight to "normal".

func (*Node) XLarge

func (n *Node) XLarge() *Node

XLarge sets the pango size to "x-large".

func (*Node) XSmall

func (n *Node) XSmall() *Node

XSmall sets the pango size to "x-small".

func (*Node) XXLarge

func (n *Node) XXLarge() *Node

XXLarge sets the pango size to "xx-large".

func (*Node) XXSmall

func (n *Node) XXSmall() *Node

XXSmall sets the pango size to "xx-small".

Directories

Path Synopsis
Package icons provides an interface for using icon fonts in a bar.
Package icons provides an interface for using icon fonts in a bar.
fontawesome
Package fontawesome provides support for FontAwesome Icons from https://github.com/FortAwesome/Font-Awesome
Package fontawesome provides support for FontAwesome Icons from https://github.com/FortAwesome/Font-Awesome
material
Package material provides support for Google's Material Design Icons from https://github.com/google/material-design-icons
Package material provides support for Google's Material Design Icons from https://github.com/google/material-design-icons
mdi
Package mdi provides support for "Material Design Icons" from https://materialdesignicons.com/, a fork and extension of Material.
Package mdi provides support for "Material Design Icons" from https://materialdesignicons.com/, a fork and extension of Material.
symbols
Package material provides support for Google's Material Design Symbols.
Package material provides support for Google's Material Design Symbols.
typicons
Package typicons provides support for Typicons from https://github.com/stephenhutchings/typicons.font
Package typicons provides support for Typicons from https://github.com/stephenhutchings/typicons.font

Jump to

Keyboard shortcuts

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