textutil

package
v0.0.0-...-bedf5c0 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MPL-2.0 Imports: 15 Imported by: 7

Documentation

Overview

Package textutil contains utilities for handling Pango markup and TextBuffer shenanigans.

Index

Constants

View Source
const (
	ThemeBackgroundColor = "theme_bg_color"
	ThemeForegroundColor = "theme_fg_color"
)

Constants for LookupColor.

Variables

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

func Attrs(attrs ...*pango.Attribute) *pango.AttrList

Attrs is a way to declaratively create a pango.AttrList.

func ColorIsDark

func ColorIsDark(r, g, b float64) bool

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

func ErrorMarkup(msg string) string

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

func LookupColor(color string) (rgba *gdk.RGBA, ok bool)

LookupColor looks up the color from a global StyleContext.

func NewAttrOpacity

func NewAttrOpacity(alpha float64) *pango.Attribute

NewAttrOpacity creates a new AttrForegroundAlpha.

func RGBHex

func RGBHex(c color.RGBA) string

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

func (t TextTag) FromTable(table *gtk.TextTagTable, name string) *gtk.TextTag

FromTable gets the tag with the given name from the given table, else it'll make a new tag with the attributes from TextTag.

func (TextTag) Hash

func (t TextTag) Hash() string

Hash returns a 24-byte string of the text tag hashed.

func (TextTag) Tag

func (t TextTag) Tag(name string) *gtk.TextTag

Tag creates a new text tag from the attributes.

type TextTagsMap

type TextTagsMap map[string]TextTag

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.

Jump to

Keyboard shortcuts

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