ansi

package module
v0.0.0-...-89a6c03 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

README

ansi

Go Report Card GoDoc Build Status

A Golang package for parsing ANSI escape sequences.

Documentation

Index

Constants

View Source
const (
	// EscapeCode holds the ANSI escape character '\x1B'
	EscapeCode = '\x1B'
)

Variables

View Source
var (
	// ErrBadControlSequence is an error definition for malformed control
	// sequences
	ErrBadControlSequence = errors.New("malformed control sequence")
	// ControlSequenceIntroducer holds the ANSI control sequence introducer '['
	ControlSequenceIntroducer = byte('[')
	// SelectGraphicRendition holds the ANSI control sequence command 'm'
	SelectGraphicRendition = byte('m')
	// CursorPosition holds the ANSI control sequence command 'H'
	CursorPosition = byte('H')
	// EraseInDisplay holds the ANSI control sequence command 'J'
	EraseInDisplay = byte('J')
	// EraseInLine holds the ANSI control sequence command 'K'
	EraseInLine = byte('K')
	// CursorUp holds the ANSI control sequence command 'A'
	CursorUp = byte('A')
	// CursorDown holds the ANSI control sequence command 'B'
	CursorDown = byte('B')
	// CursorForward holds the ANSI control sequence command 'C'
	CursorForward = byte('C')
	// CursorBack holds the ANSI control sequence command 'D'
	CursorBack = byte('D')
)
View Source
var (
	// ItemTypeName holds the string names for ItemType
	ItemTypeName = []string{
		"EOF",
		"RawBytes",
		"TwoCharSequence",
		"ControlSequence",
	}
)

Functions

This section is empty.

Types

type Item

type Item struct {
	T     ItemType
	Value []byte
}

Item models a lexer token. The value it hols is the raw slice of bytes extracted from the stream.

type ItemType

type ItemType int

ItemType defines the item class

const (
	EOF ItemType = iota
	RawBytes
	TwoCharSequence
	ControlSequence
)

For references of possible escape sequences, refer to Standard ECMA-48: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-048.pdf

func (ItemType) String

func (t ItemType) String() string

type Lexer

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

Lexer implements reading and tokenizing bytes

func (*Lexer) Init

func (l *Lexer) Init(input []byte)

Init loads a Lexer instance with new input

func (*Lexer) NextItem

func (l *Lexer) NextItem() Item

NextItem returns the the next token from the source. Returns EOF at the end of the source.

type SequenceData

type SequenceData struct {
	Prefix  byte
	Params  []int
	Inters  []byte
	Command byte
}

SequenceData is a struct that describes a control sequence

func ParseControlSequence

func ParseControlSequence(v []byte) (*SequenceData, error)

ParseControlSequence takes a slice of bytes as input and returns SequenceData and an error

Jump to

Keyboard shortcuts

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