attributedtext

package module
v0.0.0-...-fc402b7 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2015 License: MIT Imports: 2 Imported by: 0

README

go-attributedtext

Package
github.com/muhqu/go-attributedtext GoDoc
github.com/muhqu/go-attributedtext/textstyle GoDoc
github.com/muhqu/go-attributedtext/textstyle/ansiformater GoDoc
github.com/muhqu/go-attributedtext/textstyle/htmlformater GoDoc
Author
© 2015 by Mathias Leppich
github.com/muhqu, @muhqu

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attribute

type Attribute interface{}

type AttributeAtRange

type AttributeAtRange struct {
	Index     int
	Length    int
	Attribute Attribute
}

type AttributeMapping

type AttributeMapping map[Attribute]Attributes

type AttributedString

type AttributedString struct {
	Str   string
	Attrs []*AttributeAtRange
}

func NewAttributedString

func NewAttributedString(Str string) *AttributedString

func (*AttributedString) AddAttribute

func (a *AttributedString) AddAttribute(index, length int, attribute Attribute)

func (*AttributedString) SliceOfStringsWithAtributes

func (a *AttributedString) SliceOfStringsWithAtributes() SliceOfStringsWithAtributes

func (*AttributedString) String

func (a *AttributedString) String() string

type Attributes

type Attributes []Attribute

func Multi

func Multi(a Attribute, b ...Attribute) Attributes

func (Attributes) Flatten

func (m Attributes) Flatten() Attributes

func (Attributes) String

func (a Attributes) String() string

type Attributor

type Attributor interface {
	Attribute(*AttributedString) *AttributedString
	AttributeString(string) *AttributedString
}

func NewAttributeMappingAttributor

func NewAttributeMappingAttributor(m map[Attribute]Attributes) Attributor

func NewAttributor

func NewAttributor(fn AttributorFn) Attributor

func NewMultiAttributor

func NewMultiAttributor(m ...Attributor) Attributor

func NewRegexAttributor

func NewRegexAttributor(r ...*regexp.Regexp) Attributor
Example
str := "Hello World,\n\"string\" is a string and 123 is a number."

exp := regexp.MustCompile(`(?P<STR>"(?:[^"]|\\")*")|(?P<NUM>\d+)`)
attributor := attributedtext.NewRegexAttributor(exp)
attrstr := attributor.AttributeString(str)

for i, swa := range attrstr.SliceOfStringsWithAtributes() {
	fmt.Printf("%d. %-20s %#v\n", i+1, "String:", swa.Str)
	for k, attr := range swa.Attrs {
		fmt.Printf("   %-20s %T %+v\n", fmt.Sprintf("Attribute(%d):", k+1), attr, attr)
	}
}
Output:


1. String:              "Hello World,\n"
2. String:              "\"string\""
   Attribute(1):        string STR
3. String:              " is a string and "
4. String:              "123"
   Attribute(1):        string NUM
5. String:              " is a number."

type AttributorFn

type AttributorFn func(*AttributedString) *AttributedString

type MultiAttribute

type MultiAttribute interface {
	Flatten() Attributes
}

type SliceOfStringsWithAtributes

type SliceOfStringsWithAtributes []*StringWithAttributes
Example
attrstr := attributedtext.NewAttributedString("Some Message")
attrstr.AddAttribute(0, 4, "A")
attrstr.AddAttribute(5, 7, 1234)

for i, swa := range attrstr.SliceOfStringsWithAtributes() {
	fmt.Printf("%d. %-20s %#v\n", i+1, "String:", swa.Str)
	for k, attr := range swa.Attrs {
		fmt.Printf("   %-20s %T %+v\n", fmt.Sprintf("Attribute(%d):", k+1), attr, attr)
	}
}
Output:


1. String:              "Some"
   Attribute(1):        string A
2. String:              " "
3. String:              "Message"
   Attribute(1):        int 1234

type StringWithAttributes

type StringWithAttributes struct {
	Str   string
	Attrs Attributes
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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