Documentation ¶
Overview ¶
Package textutil contains utilities for handling Pango markup and TextBuffer shenanigans.
Index ¶
- Constants
- Variables
- func Attrs(attrs ...*pango.Attribute) *pango.AttrList
- func ColorIsDark[F float64 | float32](r, g, b F) bool
- func ErrorLabel(markup string) *gtk.Label
- func ErrorMarkup(msg string) string
- func HashTag(table *gtk.TextTagTable, attrs TextTag) *gtk.TextTag
- func IsDarkTheme() bool
- func LookupColor(color string) (rgba *gdk.RGBA, ok bool)
- func NewAttrOpacity(alpha float64) *pango.Attribute
- func RGBHex(c color.RGBA) string
- func SetTabSize(text *gtk.TextView)
- type TextTag
- type TextTagsMap
Constants ¶
const ( ThemeBackgroundColor = "theme_bg_color" ThemeForegroundColor = "theme_fg_color" )
Constants for LookupColor.
Variables ¶
var TabWidth = prefs.NewInt(4, prefs.IntMeta{
Name: "Tab Width",
Section: "Text",
Description: "The tab width in characters.",
Min: 0,
Max: 16,
})
TabWidth is the width of a tab character in regular monospace characters.
Functions ¶
func ColorIsDark ¶
ColorIsDark determines if the given RGB colors are dark or not. It takes in colors of range [0.0, 1.0].
func ErrorLabel ¶
func ErrorLabel(markup string) *gtk.Label
ErrorLabel makes a new label with the class `.error'.
func ErrorMarkup ¶
ErrorMarkup formats the given message red using Pango markup.
func HashTag ¶
func HashTag(table *gtk.TextTagTable, attrs TextTag) *gtk.TextTag
HashTag creates a tag inside the text tag table using the hash of the text tag attributes as the name. If the same tag has already been created, then it is returned.
func IsDarkTheme ¶
func IsDarkTheme() bool
IsDarkTheme returns true if we're inside an application with a dark theme. A dark theme implies the background color is dark.
func LookupColor ¶
LookupColor looks up the color from a global StyleContext.
func NewAttrOpacity ¶
NewAttrOpacity creates a new AttrForegroundAlpha.
func RGBHex ¶
RGBHex converts the given color to a HTML hex color string. The alpha value is ignored.
func SetTabSize ¶
func SetTabSize(text *gtk.TextView)
SetTabSize sets the given TextView's tab size.
Types ¶
type TextTag ¶
type TextTag map[string]interface{}
TextTag describes a map of attribute/property name to its value for a TextTag. Attributes that need a -set suffix will be set to true automatically.
func (TextTag) FromTable ¶
FromTable gets the tag with the given name from the given table, else it'll make a new tag with the attributes from TextTag.
type TextTagsMap ¶
TextTagsMap describes a map of tag names to its attributes. It is used to declaratively construct a TextTagTable using NewTextTags.
func LinkTags ¶
func LinkTags() TextTagsMap
LinkTags gets the text tags with colors for a, a:hover and a:visited. The output of the function is cached for a short while, so the user doesn't have to store it. It is concurrently safe to call this function.
func (TextTagsMap) Combine ¶
func (m TextTagsMap) Combine(other TextTagsMap)
Combine adds all tags from other into m. If m already contains a tag that appears in other, then the tag is not overridden.
func (TextTagsMap) FromBuffer ¶
func (m TextTagsMap) FromBuffer(buffer *gtk.TextBuffer, name string) *gtk.TextTag
FromBuffer call FromTable on the buffer's tag table.
func (TextTagsMap) FromTable ¶
func (m TextTagsMap) FromTable(table *gtk.TextTagTable, name string) *gtk.TextTag
FromTable gets the tag with the given name from the given tag table, or if the tag doesn't exist, then a new one is added instead. If the name isn't known in either the table or the map, then the function will panic.
func (TextTagsMap) SetTagAttr ¶
func (m TextTagsMap) SetTagAttr(name, attr string, value interface{})
SetTagAttr sets the attribute/property of the tag with the given name.