Skip to content
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
11 changes: 11 additions & 0 deletions escape.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (self noInstruction) isInstruction() {}
const (
stateNone escapeState = iota
stateEscape
stateCharacterSetDesignation
stateCSI
stateParams
stateOSC
Expand Down Expand Up @@ -144,9 +145,19 @@ func (ei *escapeInterpreter) parseOne(ch []byte) (isEscape bool, err error) {
case characterEquals(ch, ']'):
ei.state = stateOSC
return true, nil
case characterEquals(ch, '('),
characterEquals(ch, ')'),
characterEquals(ch, '*'),
characterEquals(ch, '+'):
ei.state = stateCharacterSetDesignation
return true, nil
default:
return false, errNotCSI
}
case stateCharacterSetDesignation:
// Not supported, so just skip it
ei.state = stateNone
return true, nil
case stateCSI:
switch {
case len(ch) == 1 && ch[0] >= '0' && ch[0] <= '9':
Expand Down
20 changes: 20 additions & 0 deletions escape_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ func TestParseOne(t *testing.T) {
parseEscRunes(t, ei, "\x1b[1K")
_, ok = ei.instruction.(noInstruction)
assert.Equal(t, true, ok)

ei = newEscapeInterpreter(OutputNormal)
parseEscRunes(t, ei, "\x1b(B")
_, ok = ei.instruction.(noInstruction)
assert.Equal(t, true, ok)

ei = newEscapeInterpreter(OutputNormal)
parseEscRunes(t, ei, "\x1b)0")
_, ok = ei.instruction.(noInstruction)
assert.Equal(t, true, ok)

ei = newEscapeInterpreter(OutputNormal)
parseEscRunes(t, ei, "\x1b*A")
_, ok = ei.instruction.(noInstruction)
assert.Equal(t, true, ok)

ei = newEscapeInterpreter(OutputNormal)
parseEscRunes(t, ei, "\x1b+K")
_, ok = ei.instruction.(noInstruction)
assert.Equal(t, true, ok)
}

func TestParseOneColours(t *testing.T) {
Expand Down
9 changes: 5 additions & 4 deletions view.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ type View struct {
// If HasLoader is true, the message will be appended with a spinning loader animation
HasLoader bool

// IgnoreCarriageReturns tells us whether to ignore '\r' characters
IgnoreCarriageReturns bool

// ParentView is the view which catches events bubbled up from the given view if there's no matching handler
ParentView *View

Expand Down Expand Up @@ -465,6 +462,10 @@ func characterEquals(chr []byte, b byte) bool {
return len(chr) == 1 && chr[0] == b
}

func isCRLF(chr []byte) bool {
return len(chr) == 2 && chr[0] == '\r' && chr[1] == '\n'
}

// String returns a string from a given cell slice.
func (l lineType) String() string {
var str strings.Builder
Expand Down Expand Up @@ -840,7 +841,7 @@ func (v *View) write(p []byte) {
chr, remaining, width, state = uniseg.FirstGraphemeCluster(remaining, state)

switch {
case characterEquals(chr, '\n'):
case characterEquals(chr, '\n') || isCRLF(chr):
finishLine()
advanceToNextLine()
case characterEquals(chr, '\r'):
Expand Down