terminalparser

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: May 28, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NUL rune = 0x00 + iota
	SOH
	STX
	ETX
	EOT
	ENQ
	ACK
	BEL
	BS

	ST     rune = 0x9c
	ESCKey      = 0x1b
)
View Source
const UnsupportedMsg = "Unsupported"

Variables

View Source
var ASCIITable = [128]rune{}/* 128 elements not displayed */
View Source
var Alphabetic = ASCIITable[64:128]
View Source
var C0Control = ASCIITable[0:32]
View Source
var C1Control = []rune{
	0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
	0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
}
View Source
var CSIFuncMap = map[rune]screenCsiFunc{
	'@': func(s *Screen, params []rune) {
		currentRow := s.GetCursorRow()
		switch len(params) {
		case 1:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				insertData := make([]rune, ps)
				for i := 0; i < ps; i++ {
					insertData[i] = Spaces[0]
				}
				currentRow.changeCursorToX(s.Cursor.X)
				currentRow.insertCharacters(insertData)
			}
		case 2:
			if params[len(params)-1] == Spaces[0] {
				if _, err := strconv.Atoi(string(params[0])); err == nil {
				}
			}
		default:
			currentRow.changeCursorToX(s.Cursor.X)
			currentRow.insertCharacters([]rune{Spaces[0]})
		}
	},
	'A': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.Cursor.MoveUp(1)
		case 1:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveUp(ps)
			}
		case 2:
			if params[len(params)-1] == Spaces[0] {
				if ps, err := strconv.Atoi(string(params[0])); err == nil {
					s.Cursor.MoveRight(ps)
				}
			}
		default:
			if params[len(params)-1] == Spaces[0] {
				if ps, err := strconv.Atoi(string(params[0])); err == nil {
					s.Cursor.MoveRight(ps)
				}
			}

		}

	},
	'B': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.Cursor.MoveDown(1)
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveDown(ps)
			}
		}

	},
	'C': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.Cursor.MoveRight(1)
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveRight(ps)
			}
		}

	},
	'D': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.Cursor.MoveLeft(1)
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveLeft(ps)
			}
		}
	},

	'E': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.Cursor.MoveDown(1)
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveDown(ps)
			}
		}

	},
	'F': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.Cursor.MoveUp(1)
		case 1:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveUp(ps)
			}
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.MoveUp(ps)
			}
		}
	},
	'I': func(screen *Screen, params []rune) {
	},
	'G': func(s *Screen, params []rune) {
		switch len(params) {
		case 1:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.X = ps
			}
		}
	},
	'H': func(s *Screen, params []rune) {
		if len(params) == 3 && params[1] == ';' {
			if row, err := strconv.Atoi(string(params[0])); err == nil {
				s.Cursor.Y = row
			}
			if column, err := strconv.Atoi(string(params[2])); err == nil {
				s.Cursor.X = column
			}
		}
		if len(params) == 0 {
			s.Cursor.MoveHome()
		}
	},
	'J': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.eraseFromCursor()
		case 1:
			if ps, err := strconv.Atoi(string(params[0])); err == nil {
				switch ps {
				case 0:
					s.eraseBelow()
				case 1:
					s.eraseAbove()
				case 2:
					s.eraseAll()
				case 3:
				default:
				}
			}
		}
	},
	'K': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.eraseEndToLine()
		default:
			paramsS := string(params)
			if strings.HasPrefix(paramsS, "?") {
				return
			}
			if ps, err := strconv.Atoi(paramsS); err == nil {
				switch ps {
				case 0:
					s.eraseRight()
				case 1:
					s.eraseLeft()
				case 2:
					s.eraseAll()
				}
			}

		}
	},
	'L': func(o *Screen, params []rune) {

	},
	'M': func(o *Screen, params []rune) {

	},
	'P': func(s *Screen, params []rune) {

		switch len(params) {
		case 0:
			s.deleteChars(1)
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.deleteChars(ps)
			}
		}

	},
	'X': func(s *Screen, params []rune) {
		switch len(params) {
		case 0:
			s.deleteChars(1)
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.deleteChars(ps)
			}
		}
	},
	'd': func(s *Screen, params []rune) {
		switch len(params) {
		case 0:
			s.Cursor.Y = 1
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				s.Cursor.Y = ps
			}

		}
	},

	'l': func(screen *Screen, params []rune) {
		screen.pasteMode = false
	},
	'h': func(screen *Screen, params []rune) {
		screen.pasteMode = true
	},

	'm': func(s *Screen, params []rune) {
		switch len(params) {
		case 0:
		default:
			if ps, err := strconv.Atoi(string(params)); err == nil {
				switch ps {
				case 30:

					if s.Cursor.Y >= 1 && len(s.Rows) > 0 {
						index := s.Cursor.Y - 1
						if index >= len(s.Rows) {
							index = len(s.Rows) - 1
						}
						s.Rows[index].stopRecord()
					}

				case 90:
					if s.Cursor.Y >= 1 && len(s.Rows) > 0 {
						index := s.Cursor.Y - 1
						if index >= len(s.Rows) {
							index = len(s.Rows) - 1
						}
						s.Rows[index].startRecord()
					}
				}
			}
		}

	},
}
View Source
var Delete rune = 0x7f

Always and everywhere ignored

View Source
var G1Display = []rune{
	0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
	0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
	0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
	0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
	0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe,
}
View Source
var Intermediate = ASCIITable[32:48]
View Source
var Lowercase = ASCIITable[96:128]
View Source
var Parameters = ASCIITable[48:64]
View Source
var Spaces = []rune{0x20, 0xa0}
View Source
var SpecialDelete = 0xff
View Source
var SpecialSpace = 0xa0
View Source
var Uppercase = ASCIITable[64:96]

Functions

func DebugString

func DebugString(p string) string

func IsAlphabetic

func IsAlphabetic(r rune) bool

func ReadRunePacket

func ReadRunePacket(p []byte) (code rune, rest []byte)

Types

type Cursor

type Cursor struct {
	X, Y int
}

func (*Cursor) MoveDown

func (c *Cursor) MoveDown(ps int)

func (*Cursor) MoveHome

func (c *Cursor) MoveHome()

func (*Cursor) MoveLeft

func (c *Cursor) MoveLeft(ps int)

func (*Cursor) MoveRight

func (c *Cursor) MoveRight(ps int)

func (*Cursor) MoveUp

func (c *Cursor) MoveUp(ps int)

type Row

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

func (*Row) String

func (r *Row) String() string

type Screen

type Screen struct {
	Rows []*Row

	Cursor *Cursor
	// contains filtered or unexported fields
}

func (*Screen) GetCursorRow

func (s *Screen) GetCursorRow() *Row

func (*Screen) Parse

func (s *Screen) Parse(data []byte) []string

Jump to

Keyboard shortcuts

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