Skip to content

Commit

Permalink
fix csi goto
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgatis committed Dec 10, 2024
1 parent f593698 commit 2163adf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions performer_csi.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ func (p *Performer) CsiDispatch(params [][]uint16, intermediates []byte, ignore

case action == 'd' && len(intermediates) == 0:
n := paramsIter.GetNextOrDefault(1)

if n < 1 {
n = 1
}

p.handler.GotoLine(int(n - 1))

case action == 'E' && len(intermediates) == 0:
Expand All @@ -213,6 +218,11 @@ func (p *Performer) CsiDispatch(params [][]uint16, intermediates []byte, ignore

case action == 'G' && len(intermediates) == 0, action == '`' && len(intermediates) == 0:
n := paramsIter.GetNextOrDefault(1)

if n < 1 {
n = 1
}

p.handler.GotoCol(int(n - 1))

case action == 'g' && len(intermediates) == 0:
Expand All @@ -229,6 +239,14 @@ func (p *Performer) CsiDispatch(params [][]uint16, intermediates []byte, ignore
y := paramsIter.GetNextOrDefault(1)
x := paramsIter.GetNextOrDefault(1)

if x < 1 {
x = 1
}

if y < 1 {
y = 1
}

p.handler.Goto(int(y-1), int(x-1))

case action == 'I' && len(intermediates) == 0:
Expand Down
4 changes: 4 additions & 0 deletions performer_csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func TestPerformer_CsiDispatch(t *testing.T) {

// CSI Ps `
{name: "CSI 3 `", args: args{params: [][]uint16{{3}}, action: '`'}, want: want{mock: m("GotoCol", 2)}},
{name: "CSI 0 `", args: args{params: [][]uint16{{0}}, action: '`'}, want: want{mock: m("GotoCol", 0)}},

// CSI Ps @
{name: "CSI 3 @", args: args{params: [][]uint16{{3}}, action: '@'}, want: want{mock: m("InsertBlank", 3)}},
Expand Down Expand Up @@ -55,6 +56,7 @@ func TestPerformer_CsiDispatch(t *testing.T) {

// CSI Ps d
{name: "CSI 3 d", args: args{params: [][]uint16{{3}}, action: 'd'}, want: want{mock: m("GotoLine", 2)}},
{name: "CSI 0 d", args: args{params: [][]uint16{{0}}, action: 'd'}, want: want{mock: m("GotoLine", 0)}},

// CSI Ps E
{name: "CSI 3 E", args: args{params: [][]uint16{{3}}, action: 'E'}, want: want{mock: m("MoveDownCr", 2)}},
Expand All @@ -74,9 +76,11 @@ func TestPerformer_CsiDispatch(t *testing.T) {

// CSI Ps ; Ps H
{name: "CSI 5 ; 3 H", args: args{params: [][]uint16{{5}, {3}}, action: 'H'}, want: want{mock: m("Goto", 4, 2)}},
{name: "CSI 0 ; 0 H", args: args{params: [][]uint16{{0}, {0}}, action: 'H'}, want: want{mock: m("Goto", 0, 0)}},

// CSI Ps ; Ps f
{name: "CSI 5 ; 3 f", args: args{params: [][]uint16{{5}, {3}}, action: 'f'}, want: want{mock: m("Goto", 4, 2)}},
{name: "CSI 0 ; 0 f", args: args{params: [][]uint16{{0}, {0}}, action: 'f'}, want: want{mock: m("Goto", 0, 0)}},

// CSI Ps I
{name: "CSI 3 I", args: args{params: [][]uint16{{3}}, action: 'I'}, want: want{mock: m("MoveForwardTabs", 3)}},
Expand Down

0 comments on commit 2163adf

Please sign in to comment.