~mna/zzcsi

52b4953a9299d351b1e314f108b3109252321379 — Martin Angers 1 year, 2 months ago 41fad45
implement more csi funcs
4 files changed, 141 insertions(+), 14 deletions(-)

A .builds/arch.yml
A .builds/github.yml
M csi.go
M csi_test.go
A .builds/arch.yml => .builds/arch.yml +34 -0
@@ 0,0 1,34 @@
image: archlinux
packages:
  - go

sources:
  - git@git.sr.ht:~mna/zztermcsi

environment:
  GO111MODULE: "on"

tasks:
  - setup: |
      cd zztermcsi
      go version
      curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b . v1.24.0
      ./golangci-lint --version

  - test: |
      cd zztermcsi
      go test -v -vet all -bench . -benchmem ./...

  - cover: |
      cd zztermcsi
      go test -cover ./...

  - lint: |
      cd zztermcsi
      ./golangci-lint run

triggers:
  - condition: "failure"
    action: "email"
    to: "Martin Angers <martin.n.angers+sourcehut@gmail.com>"


A .builds/github.yml => .builds/github.yml +11 -0
@@ 0,0 1,11 @@
image: alpine/latest
sources:
  - git@git.sr.ht:~mna/zztermcsi
tasks:
  - build: |
      cd zztermcsi
      git remote add mirror git@github.com:mna/zztermcsi.git
      git push mirror master --tag
secrets:
  - 8a632639-cb32-49f8-b6b8-8040972f80a7
  - fbb26d7f-ea1b-41c0-97b3-882ad37c66a0

M csi.go => csi.go +92 -14
@@ 6,6 6,31 @@ import (
	"strings"
)

const (
	EraseScrBelow    = 0
	EraseScrAbove    = 1
	EraseScrAll      = 2
	EraseScrSavedLns = 3

	SelEraseScrBelow    = 0
	SelEraseScrAbove    = 1
	SelEraseScrAll      = 2
	SelEraseScrSavedLns = 3

	EraseLnRight = 0
	EraseLnLeft  = 1
	EraseLnAll   = 2

	SelEraseLnRight = 0
	SelEraseLnLeft  = 1
	SelEraseLnAll   = 2

	RstTitleModeSetLabelsHex  = 0
	RstTitleModeQryLabelsHex  = 1
	RstTitleModeSetLabelsUTF8 = 2
	RstTitleModeQryLabelsUTF8 = 3
)

// CSI represents a Control Sequence Introducer function as supported
// by xterm-compatible terminals.
//


@@ 22,6 47,24 @@ const (
	CurDown
	CurFwd
	CurBwd
	CurNextLn
	CurPrevLn
	CurColAbs
	CurPos
	CurFwdTab
	EraseScr
	SelEraseScr
	EraseLn
	SelEraseLn
	InsLn
	DelLn
	DelCh
	ScrlUp
	_ // TODO: Set or request graphics attribute
	ScrlDown
	_ // TODO: Initiate highlight mouse tracking
	RstTitleMode
	EraseCh
)

var (


@@ 30,23 73,57 @@ var (
	// The CSI "Ps" (single number) parameter is encoded as "\x01" and the "Pm"
	// (multiple numbers separated by ;) is encoded as "\x02".

	insCh   = []byte("\x1b[\x01@")
	shLeft  = []byte("\x1b[\x01 @")
	curUp   = []byte("\x1b[\x01A")
	shRight = []byte("\x1b[\x01 A")
	curDown = []byte("\x1b[\x01B")
	curFwd  = []byte("\x1b[\x01C")
	curBwd  = []byte("\x1b[\x01D")
	insCh        = []byte("\x1b[\x01@")
	shLeft       = []byte("\x1b[\x01 @")
	curUp        = []byte("\x1b[\x01A")
	shRight      = []byte("\x1b[\x01 A")
	curDown      = []byte("\x1b[\x01B")
	curFwd       = []byte("\x1b[\x01C")
	curBwd       = []byte("\x1b[\x01D")
	curNextLn    = []byte("\x1b[\x01E")
	curPrevLn    = []byte("\x1b[\x01F")
	curColAbs    = []byte("\x1b[\x01G")
	curPos       = []byte("\x1b[\x01;\x01H")
	curFwdTab    = []byte("\x1b[\x01I")
	eraseScr     = []byte("\x1b[\x01J")
	selEraseScr  = []byte("\x1b[?\x01J")
	eraseLn      = []byte("\x1b[\x01K")
	selEraseLn   = []byte("\x1b[?\x01K")
	insLn        = []byte("\x1b[\x01L")
	delLn        = []byte("\x1b[\x01M")
	delCh        = []byte("\x1b[\x01P")
	scrlUp       = []byte("\x1b[\x01S")
	scrlDown     = []byte("\x1b[\x01T")
	rstTitleMode = []byte("\x1b[>\x02T")
	eraseCh      = []byte("\x1b[\x01X")
)

var csiSeqs = [...][]byte{
	InsCh:   insCh,
	ShLeft:  shLeft,
	CurUp:   curUp,
	ShRight: shRight,
	CurDown: curDown,
	CurFwd:  curFwd,
	CurBwd:  curBwd,
	InsCh:       insCh,
	ShLeft:      shLeft,
	CurUp:       curUp,
	ShRight:     shRight,
	CurDown:     curDown,
	CurFwd:      curFwd,
	CurBwd:      curBwd,
	CurNextLn:   curNextLn,
	CurPrevLn:   curPrevLn,
	CurColAbs:   curColAbs,
	CurPos:      curPos,
	CurFwdTab:   curFwdTab,
	EraseScr:    eraseScr,
	SelEraseScr: selEraseScr,
	EraseLn:     eraseLn,
	SelEraseLn:  selEraseLn,
	InsLn:       insLn,
	DelLn:       delLn,
	DelCh:       delCh,
	ScrlUp:      scrlUp,

	ScrlDown: scrlDown,

	RstTitleMode: rstTitleMode,
	EraseCh:      eraseCh,
}

// Func returns the sequence of bytes to execute this CSI function with


@@ 105,6 182,7 @@ func appendFunc(buf, seq []byte, args []int) []byte {
			buf = append(buf, seq[start:]...)
			break
		}
		ix += start
		buf = append(buf, seq[start:ix]...)
		start = ix + 1
		if len(args) > 0 {

M csi_test.go => csi_test.go +4 -0
@@ 20,6 20,10 @@ func TestFunc_NoArg(t *testing.T) {

func TestIsCSI(t *testing.T) {
	for _, seq := range csiSeqs {
		if len(seq) == 0 {
			continue
		}

		t.Run(string(seq), func(t *testing.T) {
			if !IsCSI(seq) {
				t.Fatalf("sequence not detected as CSI: %q", seq)