ansi

package
Version: v0.0.0-...-fdaaeef Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2016 License: MIT Imports: 6 Imported by: 0

README

ansi

Implements the ANSI VT100 control set. Please refer to http://www.termsys.demon.co.uk/vtansi.htm

Install

go get github.com/jpillora/ansi

Usage

Get ANSI control code bytes:

ansi.Goto(2,4)
ansi.Set(ansi.Green, ansi.BlueBG)

Wrap an io.ReadWriteCloser:


a := ansi.Wrap(tcpConn)

//Read, Write, Close as normal
a.Read()
a.Write()
a.Close()

//Shorthand for a.Write(ansi.Set(..))
a.Set(ansi.Green, ansi.BlueBG)

//Send query
a.QueryCursorPosition()
//Await report
report := <- a.Reports
report.Type//=> ansi.Position
report.Pos.Row
report.Pos.Col

Wrapped connections will intercept and remove ANSI report codes from a.Read()

API

http://godoc.org/github.com/jpillora/ansi

MIT License

Copyright © 2014 <dev@jpillora.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Implements the ANSI VT100 control set. Please refer to http://www.termsys.demon.co.uk/vtansi.htm

Index

Constants

View Source
const Esc = byte(27)

Variables

View Source
var (
	ResetBytes      = Set(Reset)
	BrightBytes     = Set(Bright)
	DimBytes        = Set(Dim)
	ItalicBytes     = Set(Italic)
	UnderscoreBytes = Set(Underscore)
	BlinkBytes      = Set(Blink)
	ReverseBytes    = Set(Reverse)
	HiddenBytes     = Set(Hidden)
	//foreground colors
	BlackBytes   = Set(Black)
	RedBytes     = Set(Red)
	GreenBytes   = Set(Green)
	YellowBytes  = Set(Yellow)
	BlueBytes    = Set(Blue)
	MagentaBytes = Set(Magenta)
	CyanBytes    = Set(Cyan)
	WhiteBytes   = Set(White)
	//background colors
	BlackBGBytes   = Set(BlackBG)
	RedBGBytes     = Set(RedBG)
	GreenBGBytes   = Set(GreenBG)
	YellowBGBytes  = Set(YellowBG)
	BlueBGBytes    = Set(BlueBG)
	MagentaBGBytes = Set(MagentaBG)
	CyanBGBytes    = Set(CyanBG)
	WhiteBGBytes   = Set(WhiteBG)
)
View Source
var ClearAllTabs = []byte{Esc, '[', '3', 'g'}
View Source
var ClearTab = []byte{Esc, '[', 'g'}
View Source
var CursorHide = []byte{Esc, '[', '?', '2', '5', 'l'}
View Source
var CursorShow = []byte{Esc, '[', '?', '2', '5', 'h'}
View Source
var DisableLineWrap = []byte{Esc, '[', '7', 'l'}
View Source
var EnableLineWrap = []byte{Esc, '[', '7', 'h'}
View Source
var EraseDown = []byte{Esc, '[', 'J'}
View Source
var EraseEndLine = []byte{Esc, '[', 'K'}
View Source
var EraseLine = []byte{Esc, '[', '2', 'K'}
View Source
var EraseScreen = []byte{Esc, '[', '2', 'J'}
View Source
var EraseStartLine = []byte{Esc, '[', '1', 'K'}
View Source
var EraseUp = []byte{Esc, '[', '1', 'J'}
View Source
var FontSetG0 = []byte{Esc, '('}
View Source
var FontSetG1 = []byte{Esc, ')'}
View Source
var PrintLine = []byte{Esc, '[', '1', 'i'}
View Source
var PrintScreen = []byte{Esc, '[', 'i'}

Printing

View Source
var QueryCode = []byte{Esc, '[', 'c'}
View Source
var QueryCursorPosition = []byte{Esc, '[', '6', 'n'}
View Source
var QueryDeviceStatus = []byte{Esc, '[', '5', 'n'}
View Source
var ResetDevice = []byte{Esc, 'c'}
View Source
var RestoreAttrCursor = []byte{Esc, '8'}
View Source
var SaveAttrCursor = []byte{Esc, '7'}
View Source
var SaveCursor = []byte{Esc, '[', 's'}
View Source
var ScrollDown = []byte{Esc, 'D'}
View Source
var ScrollScreen = []byte{Esc, '[', 'r'}
View Source
var ScrollUp = []byte{Esc, 'M'}
View Source
var SetTab = []byte{Esc, 'H'}

Tab Control

View Source
var StartPrintLog = []byte{Esc, '[', '5', 'i'}
View Source
var StopPrintLog = []byte{Esc, '[', '4', 'i'}
View Source
var UnsaveCursor = []byte{Esc, '[', 'u'}

Functions

func Goto

func Goto(r, c uint16) []byte

Cursor Home <ESC>[{ROW};{COLUMN}H Cursor Up <ESC>[{COUNT}A Cursor Down <ESC>[{COUNT}B Cursor Forward <ESC>[{COUNT}C Cursor Backward <ESC>[{COUNT}D Force Cursor Position <ESC>[{ROW};{COLUMN}f

func Scroll

func Scroll(start, end uint16) []byte

func Set

func Set(attrs ...Attribute) []byte

Set attributes

Types

type Ansi

type Ansi struct {
	Reports chan *Report
	// contains filtered or unexported fields
}

Ansi represents a wrapped io.ReadWriter. It will read the stream, parse and remove ANSI report codes and place them on the Reports queue.

func Wrap

func Wrap(rw io.ReadWriter) *Ansi

Wrap an io.ReadWriter (like a net.Conn) to easily read and write control codes

func (*Ansi) Close

func (a *Ansi) Close() error

Closes the underlying ReadWriter

func (*Ansi) CursorHide

func (a *Ansi) CursorHide()

func (*Ansi) CursorShow

func (a *Ansi) CursorShow()

func (*Ansi) DisableLineWrap

func (a *Ansi) DisableLineWrap()

func (*Ansi) EnableLineWrap

func (a *Ansi) EnableLineWrap()

func (*Ansi) EraseScreen

func (a *Ansi) EraseScreen()

func (*Ansi) Goto

func (a *Ansi) Goto(r, c uint16)

func (*Ansi) QueryCursorPosition

func (a *Ansi) QueryCursorPosition()

func (*Ansi) Read

func (a *Ansi) Read(dest []byte) (n int, err error)

Reads the underlying ReadWriter

func (*Ansi) Set

func (a *Ansi) Set(attrs ...Attribute)

Set Attribute Mode <ESC>[{attr1};...;{attrn}m

func (*Ansi) Write

func (a *Ansi) Write(p []byte) (n int, err error)

Writes the underlying ReadWriter

type Attribute

type Attribute string

Sets multiple display attribute settings. The following lists standard attributes:

const (
	//formatinn
	Reset      Attribute = "0"
	Bright     Attribute = "1"
	Dim        Attribute = "2"
	Italic     Attribute = "3"
	Underscore Attribute = "4"
	Blink      Attribute = "5"
	Reverse    Attribute = "7"
	Hidden     Attribute = "8"
	//foreground colors
	Black   Attribute = "30"
	Red     Attribute = "31"
	Green   Attribute = "32"
	Yellow  Attribute = "33"
	Blue    Attribute = "34"
	Magenta Attribute = "35"
	Cyan    Attribute = "36"
	White   Attribute = "37"
	//background colors
	BlackBG   Attribute = "40"
	RedBG     Attribute = "41"
	GreenBG   Attribute = "42"
	YellowBG  Attribute = "43"
	BlueBG    Attribute = "44"
	MagentaBG Attribute = "45"
	CyanBG    Attribute = "46"
	WhiteBG   Attribute = "47"
)

type Report

type Report struct {
	Type ReportType
	Code int
	Pos  struct {
		Row, Col int
	}
}

type ReportType

type ReportType int
const (
	Code ReportType = iota
	OK
	Failure
	Position
)

Source Files

Jump to

Keyboard shortcuts

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