Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

only record explicit params (don't default to 0) #3

Merged
merged 1 commit into from
Oct 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type Parser struct {
intermediateIdx int
params *params
param uint16
hasParam bool
oscRaw []byte
oscParams [maxOscParams][2]int
oscNumParams int
Expand Down Expand Up @@ -311,7 +312,7 @@ func (p *Parser) performAction(action, b byte) {
case CsiDispatchAction:
if p.params.IsFull() {
p.ignoring = true
} else {
} else if p.hasParam {
p.params.Push(p.param)
}

Expand Down Expand Up @@ -346,19 +347,26 @@ func (p *Parser) performAction(action, b byte) {
if b == ';' {
p.params.Push(p.param)
p.param = 0
// accept a 0 for the following param even if we don't see a
// number, since the semicolon makes it obvious that a value should
// be there.
p.hasParam = true
} else if b == ':' {
p.params.Extend(p.param)
p.param = 0
p.hasParam = false
} else {
p.param = smulu16(p.param, 10)
p.param = saddu16(p.param, uint16((b - '0')))
p.hasParam = true
}

case ClearAction:
// Reset everything on ESC/CSI/DCS entry
p.intermediateIdx = 0
p.ignoring = false
p.param = 0
p.hasParam = false

p.params.Clear()

Expand Down
18 changes: 18 additions & 0 deletions parser_csi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ func TestCsiParamsIgnoreLong(t *testing.T) {
assert.Equal(t, expected, dispatcher.dispatched[0])
}

func TestCsiNoParams(t *testing.T) {
expected := testCsiSequence{
intermediates: []byte{},
ignore: false,
rune: 'C',
}

dispatcher := &testDispatcher{}
parser := NewParser(dispatcher)

for _, b := range []byte("\x1b[C") {
parser.Advance(b)
}

assert.Equal(t, 1, len(dispatcher.dispatched))
assert.Equal(t, expected, dispatcher.dispatched[0])
}

func TestCsiParamsTrailingSemicolon(t *testing.T) {
expected := testCsiSequence{
params: [][]uint16{{4}, {0}},
Expand Down