Skip to content

Commit 4c32e9f

Browse files
fix(tui): filter split OSC rgb color tails in the prompt (#744)
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 5bdbf0c commit 4c32e9f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

‎internal/tui/prompt_noise.go‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import (
1212

1313
var (
1414
oscHexFragment = regexp.MustCompile(`^[0-9a-fA-F]{1,4}(/[0-9a-fA-F]{1,4}){1,2}\\?$`)
15+
// Split OSC rgb tail: optional r/g/b prefix (0–3), then : or /, then 1–3
16+
// channels of exactly 4 hex digits. e.g. "b:0000/0000/0000", ":0000/0000/0000".
17+
oscRGBTail = regexp.MustCompile(`^[rgb]{0,3}[:/][0-9a-fA-F]{4}(?:[:/][0-9a-fA-F]{4}){0,2}$`)
1518
// Core CPR payload after optional mangled CSI/OSC prefixes are stripped.
1619
cprCore = regexp.MustCompile(`^\d{0,4};\d{1,4}R$`)
1720
cprCorePartial = regexp.MustCompile(`^\d{0,4};?\d{0,4}$`)
@@ -119,7 +122,7 @@ func isTerminalEscape(s string) bool {
119122
if strings.Contains(s, "rgb:") || strings.HasPrefix(s, "]10;") || strings.HasPrefix(s, "]11;") {
120123
return true
121124
}
122-
if oscHexFragment.MatchString(s) {
125+
if oscHexFragment.MatchString(s) || oscRGBTail.MatchString(s) {
123126
return true
124127
}
125128
if cprCore.MatchString(stripCPRPrefix(s)) {

‎internal/tui/run_test.go‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,12 @@ func TestIsTerminalEscape_DetectsOSCFragments(t *testing.T) {
544544
{"58e/193a/1e75\\", true},
545545
{"158e/193a/1e75", true},
546546
{"ffff/0000/0000", true},
547+
{"b:0000/0000/0000", true},
548+
{"gb/0000:0000:0000", true},
549+
{":0000/0000/0000", true},
550+
{"b: hello", false},
551+
{"/exit", false},
552+
{"ff00", false},
547553
{"hello world", false},
548554
{"a", false},
549555
{"abc", false},

0 commit comments

Comments
 (0)