fix: TUI CSI u key parsing and console escape sequence order

- TUI: Add parseCSIuBytes to handle CSI u sequences that bubbletea
  v1.3.6 returns as []byte (unknownCSISequenceMsg). Parses codepoint
  and modifier bits to reconstruct key string for hotkey routing.
- Console: Reorder escape parser checks. Check 2-byte non-CSI
  sequences first, then CSI terminator only after ESC[ introducer.
  Fixes CSI u sequences being truncated at '[' byte (0x5b).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
JiXieShi
2026-05-24 03:25:40 +08:00
parent 319ed108d8
commit b1c499b340
2 changed files with 37 additions and 2 deletions
+33
View File
@@ -1,6 +1,7 @@
package tui
import (
"strconv"
"strings"
tea "github.com/charmbracelet/bubbletea"
@@ -146,3 +147,35 @@ func completionBase(line string) string {
}
return line[:i+1]
}
func parseCSIuBytes(b []byte) (string, bool) {
s := string(b)
if !strings.HasPrefix(s, "\x1b[") || !strings.HasSuffix(s, "u") {
return "", false
}
inner := s[2 : len(s)-1]
parts := strings.SplitN(inner, ";", 2)
if len(parts) != 2 {
return "", false
}
cp, err := strconv.Atoi(parts[0])
if err != nil || cp < 'a' || cp > 'z' {
return "", false
}
mod, err := strconv.Atoi(parts[1])
if err != nil {
return "", false
}
var seq []string
if mod&4 != 0 {
seq = append(seq, "ctrl")
}
if mod&2 != 0 {
seq = append(seq, "alt")
}
if mod&1 != 0 {
seq = append(seq, "shift")
}
seq = append(seq, string(rune(cp)))
return strings.Join(seq, "+"), true
}