diff options
| author | adamdotdevin <[email protected]> | 2025-07-10 15:49:49 -0500 |
|---|---|---|
| committer | adamdotdevin <[email protected]> | 2025-07-10 15:49:58 -0500 |
| commit | 294d0e7ee3476f4425c3d21fbaf82dfce3aba017 (patch) | |
| tree | 3c24c5caf7075612dc58ff4cdb1b1f87eedc2d9b /packages/tui/input/termcap.go | |
| parent | 8be1ca836c806c5a3ea3f2f5b49a696063dd3a91 (diff) | |
| download | opencode-294d0e7ee3476f4425c3d21fbaf82dfce3aba017.tar.gz opencode-294d0e7ee3476f4425c3d21fbaf82dfce3aba017.zip | |
fix(tui): mouse wheel ansi codes leaking into editor
Diffstat (limited to 'packages/tui/input/termcap.go')
| -rw-r--r-- | packages/tui/input/termcap.go | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/packages/tui/input/termcap.go b/packages/tui/input/termcap.go new file mode 100644 index 000000000..3502189ff --- /dev/null +++ b/packages/tui/input/termcap.go @@ -0,0 +1,54 @@ +package input + +import ( + "bytes" + "encoding/hex" + "strings" +) + +// CapabilityEvent represents a Termcap/Terminfo response event. Termcap +// responses are generated by the terminal in response to RequestTermcap +// (XTGETTCAP) requests. +// +// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands +type CapabilityEvent string + +func parseTermcap(data []byte) CapabilityEvent { + // XTGETTCAP + if len(data) == 0 { + return CapabilityEvent("") + } + + var tc strings.Builder + split := bytes.Split(data, []byte{';'}) + for _, s := range split { + parts := bytes.SplitN(s, []byte{'='}, 2) + if len(parts) == 0 { + return CapabilityEvent("") + } + + name, err := hex.DecodeString(string(parts[0])) + if err != nil || len(name) == 0 { + continue + } + + var value []byte + if len(parts) > 1 { + value, err = hex.DecodeString(string(parts[1])) + if err != nil { + continue + } + } + + if tc.Len() > 0 { + tc.WriteByte(';') + } + tc.WriteString(string(name)) + if len(value) > 0 { + tc.WriteByte('=') + tc.WriteString(string(value)) + } + } + + return CapabilityEvent(tc.String()) +} |
