render

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2023 License: MIT Imports: 5 Imported by: 0

README

color

Turns github.com/fatih/color into HTML. Just kidding!

Just a tag based approach to write some nice text.

Usage

package main

import (
	"fmt"

	render "github.com/hygge-io/color"
)

func main() {

	s := `This is a #red[part of text with #bold[some] in bold] word.
Possible to #(green,italic)[combine]`

	renderer := render.New()
	fmt.Println(renderer.Render(s))
}

output

Depending on the text you want to format, it can be necessary to change how the parsing is done:

s := `In Markdown, @(bold)<a new paragraph> uses the # tag
while links are written as @green<[link](url)>`

renderer := render.New().WithTagMarker('@').WithTextLimiter('<', '>')
fmt.Println(renderer.Render(s))

output

Documentation

Index

Constants

View Source
const (
	Black = iota
	Red
	Green
	Yellow
	Blue
	Magenta
	Cyan
	White
)
View Source
const (
	None = iota
	Bold
	Italic
)

Variables

This section is empty.

Functions

func SameStyle

func SameStyle(a, b *Style) bool

Types

type Color

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

type Renderer

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

func New

func New() *Renderer

func (*Renderer) Render

func (renderer *Renderer) Render(text string) string

func (*Renderer) RenderWithTemplate added in v0.0.5

func (renderer *Renderer) RenderWithTemplate(text string, obj any) string

func (*Renderer) Scanner added in v0.0.3

func (renderer *Renderer) Scanner() *Scanner

func (*Renderer) WithTagMarker added in v0.0.3

func (renderer *Renderer) WithTagMarker(m int32) *Renderer

func (*Renderer) WithTextLimiter added in v0.0.3

func (renderer *Renderer) WithTextLimiter(start, end int32) *Renderer

type Scanner

type Scanner struct {
	TagMarker int32
	Start     int32
	End       int32
}

func NewScanner

func NewScanner() *Scanner

func (*Scanner) Scan

func (s *Scanner) Scan(text string) []Token

func (*Scanner) ScanWithTemplate added in v0.0.5

func (s *Scanner) ScanWithTemplate(text string, obj any) []Token

type Style

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

func NewStyle

func NewStyle() *Style

func (*Style) Add

func (style *Style) Add(ts ...string)

func (*Style) AddOne

func (style *Style) AddOne(t string)

func (*Style) Clone

func (style *Style) Clone() *Style

func (*Style) Color

func (style *Style) Color(color int) *Style

func (*Style) String

func (style *Style) String() string

func (*Style) Typography

func (style *Style) Typography(t int) *Style

type Theme

type Theme struct {
}

func (*Theme) Color

func (theme *Theme) Color(c Color) (color.Attribute, bool)

func (*Theme) Convert

func (theme *Theme) Convert(token Token) string

func (*Theme) Produce added in v0.0.6

func (theme *Theme) Produce(tokens []Token) string

func (*Theme) Typographies

func (theme *Theme) Typographies(typographies []Typography) []color.Attribute

type Token

type Token struct {
	Text  string
	Style *Style
}

type Type

type Type interface {
}

type Typography

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

Jump to

Keyboard shortcuts

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