diff --git a/exp/term/ansi/parser.go b/exp/term/ansi/parser.go index 4a03d919..baa188f2 100644 --- a/exp/term/ansi/parser.go +++ b/exp/term/ansi/parser.go @@ -68,6 +68,12 @@ func NewParser(paramsSize, dataSize int) *Parser { // Reset resets the parser to its initial state. func (p *Parser) Reset() { + p.clear() + p.State = parser.GroundState +} + +// clear clears the parser parameters and command. +func (p *Parser) clear() { if len(p.Params) > 0 { p.Params[0] = parser.MissingParam } @@ -147,6 +153,13 @@ func (p *Parser) advance(d ParserDispatcher, b byte, more bool) parser.Action { case parser.EscapeState: p.performAction(d, parser.ClearAction, b) } + if action == parser.PutAction && + p.State == parser.DcsEntryState && state == parser.DcsStringState { + // XXX: This is a special case where we need to start collecting + // non-string parameterized data i.e. doesn't follow the ECMA-48 § + // 5.4.1 string parameters format. + p.performAction(d, parser.StartAction, 0) + } } // Handle special cases @@ -194,7 +207,7 @@ func (p *Parser) performAction(dispatcher ParserDispatcher, action parser.Action break case parser.ClearAction: - p.Reset() + p.clear() case parser.PrintAction: if utf8ByteLen(b) > 1 { diff --git a/exp/term/ansi/parser/transition_table.go b/exp/term/ansi/parser/transition_table.go index 274279b1..febde15d 100644 --- a/exp/term/ansi/parser/transition_table.go +++ b/exp/term/ansi/parser/transition_table.go @@ -165,7 +165,8 @@ func GenerateTransitionTable() TransitionTable { } // Dcs_entry - table.AddRange(0x00, 0x17, DcsEntryState, IgnoreAction, DcsEntryState) + table.AddRange(0x00, 0x07, DcsEntryState, IgnoreAction, DcsEntryState) + table.AddRange(0x0E, 0x17, DcsEntryState, IgnoreAction, DcsEntryState) table.AddOne(0x19, DcsEntryState, IgnoreAction, DcsEntryState) table.AddRange(0x1C, 0x1F, DcsEntryState, IgnoreAction, DcsEntryState) table.AddOne(0x7F, DcsEntryState, IgnoreAction, DcsEntryState) @@ -175,6 +176,10 @@ func GenerateTransitionTable() TransitionTable { table.AddRange(0x30, 0x3B, DcsEntryState, ParamAction, DcsParamState) table.AddRange(0x3C, 0x3F, DcsEntryState, MarkerAction, DcsParamState) // Dcs_entry -> Dcs_passthrough + table.AddRange(0x08, 0x0D, DcsEntryState, PutAction, DcsStringState) // Follows ECMA-48 § 8.3.27 + // XXX: allows passing ESC (not a ECMA-48 standard) this to allow for + // passthrough of ANSI sequences like in Screen or Tmux passthrough mode. + table.AddOne(0x1B, DcsEntryState, PutAction, DcsStringState) table.AddRange(0x40, 0x7E, DcsEntryState, StartAction, DcsStringState) // Dcs_intermediate