ansi

package module
v0.0.0-...-91d4320 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2023 License: MIT Imports: 6 Imported by: 0

README

tcell-ansi

turn your tcells into ansi strings

Usage

package main

import "git.sr.ht/~rockorager/tcell-ansi"

func main() {
	// Make a tcell.Style
	mystyle := tcell.StyleDefault.Foreground(tcell.ColorPink)
	// Apply it to your string
	pink := ansi.ApplyStyle(mystyle, "this is pink")
	// Make another style
	bluestyle := tcell.StyleDefault.Foreground(tcell.ColorBlue)
	// Apply it to another string, and maybe the other styled string. Print
	// it and rejoice that you have blue and pink text
	fmt.Println(ansi.ApplyStyle(bluestyle, "this is blue. " + pink))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyStyle

func ApplyStyle(style tcell.Style, str string) string

Applies a style to a string. Any currently applied styles will not be overwritten

Types

type Parser

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

A Parser parses a string into a RuneBuffer

func NewParser

func NewParser() *Parser

func (*Parser) Parse

func (p *Parser) Parse(s string) *RuneBuffer

Parses a styled string into a RuneBuffer

type RuneBuffer

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

RuneBuffer is a buffer of runes styled with tcell.Style objects

func (*RuneBuffer) Len

func (rb *RuneBuffer) Len() int

func (*RuneBuffer) Runes

func (rb *RuneBuffer) Runes() []*StyledRune

Returns the internal slice of styled runes

func (*RuneBuffer) String

func (rb *RuneBuffer) String() string

String outputs a styled-string using TERM=xterm-256color

func (*RuneBuffer) Write

func (rb *RuneBuffer) Write(r rune, style tcell.Style)

Write writes a rune and it's associated style to the RuneBuffer

type StyledRune

type StyledRune struct {
	Value rune
	Width int
	Style tcell.Style
}

StyledRune is a rune and it's associated style. The rune has already been measured using go-runewidth

Jump to

Keyboard shortcuts

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