mirror of
https://github.com/jixishi/SerialTerminalForWindowsTerminal.git
synced 2026-06-16 00:52:44 +00:00
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:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user