fix(tui): remove obsolete OSC helpers
- commit
- 46fa06b4d6f99d9ad017fcde74943641e791e28f
- author
- brice · · 2026-08-05 09:15 UTC
- parent
- 6435059
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +0 -71
M packages/tui/detect_bg.go +0 -71
| @@ -229,74 +229,3 @@ func parseTerminalRGB(value string) (TerminalColor, bool) { | |||
| 229 | 229 | } | |
| 230 | 230 | return ColorRGB(channels[0], channels[1], channels[2]), true | |
| 231 | 231 | } | |
| 232 | - | ||
| 233 | - | // readOSCResponse drains stdin into a small buffer until either a terminator | |
| 234 | - | // (BEL or ST) is seen, the deadline expires, or stdin hits EOF. It remains a | |
| 235 | - | // small helper for callers that only need one OSC reply. | |
| 236 | - | func readOSCResponse(deadline time.Time) string { | |
| 237 | - | var buf [128]byte | |
| 238 | - | n := 0 | |
| 239 | - | for time.Now().Before(deadline) { | |
| 240 | - | remaining := time.Until(deadline) | |
| 241 | - | if remaining <= 0 { | |
| 242 | - | break | |
| 243 | - | } | |
| 244 | - | b, ok, err := peekStdin(os.Stdin, remaining) | |
| 245 | - | if err != nil || !ok { | |
| 246 | - | return string(buf[:n]) | |
| 247 | - | } | |
| 248 | - | if n < len(buf) { | |
| 249 | - | buf[n] = b | |
| 250 | - | n++ | |
| 251 | - | } | |
| 252 | - | if b == 0x07 { | |
| 253 | - | return string(buf[:n]) | |
| 254 | - | } | |
| 255 | - | if n >= 2 && buf[n-2] == 0x1b && buf[n-1] == '\\' { | |
| 256 | - | return string(buf[:n]) | |
| 257 | - | } | |
| 258 | - | } | |
| 259 | - | return string(buf[:n]) | |
| 260 | - | } | |
| 261 | - | ||
| 262 | - | // parseOSC11Reply extracts the (r, g, b) colour components from an OSC 11 | |
| 263 | - | // reply of the form "\\x1b]11;rgb:RRRR/GGGG/BBBB\\x07" (or with ST | |
| 264 | - | // terminator). The component widths can be 1, 2, 3, or 4 hex digits per | |
| 265 | - | // channel; we normalise them into the 0..1 range. | |
| 266 | - | func parseOSC11Reply(s string) (float64, float64, float64, bool) { | |
| 267 | - | i := strings.Index(s, "rgb:") | |
| 268 | - | if i < 0 { | |
| 269 | - | return 0, 0, 0, false | |
| 270 | - | } | |
| 271 | - | body := strings.TrimRight(s[i+len("rgb:"):], "\x07") | |
| 272 | - | body = strings.TrimSuffix(body, "\x1b\\") | |
| 273 | - | parts := strings.Split(body, "/") | |
| 274 | - | if len(parts) != 3 { | |
| 275 | - | return 0, 0, 0, false | |
| 276 | - | } | |
| 277 | - | parse := func(hexstr string) (float64, bool) { | |
| 278 | - | if len(hexstr) == 0 || len(hexstr) > 4 { | |
| 279 | - | return 0, false | |
| 280 | - | } | |
| 281 | - | v, err := strconv.ParseUint(hexstr, 16, 32) | |
| 282 | - | if err != nil { | |
| 283 | - | return 0, false | |
| 284 | - | } | |
| 285 | - | max := uint64(1) | |
| 286 | - | for range hexstr { | |
| 287 | - | max *= 16 | |
| 288 | - | } | |
| 289 | - | max-- | |
| 290 | - | if max == 0 { | |
| 291 | - | return 0, false | |
| 292 | - | } | |
| 293 | - | return float64(v) / float64(max), true | |
| 294 | - | } | |
| 295 | - | r, ok1 := parse(parts[0]) | |
| 296 | - | g, ok2 := parse(parts[1]) | |
| 297 | - | b, ok3 := parse(parts[2]) | |
| 298 | - | if !ok1 || !ok2 || !ok3 { | |
| 299 | - | return 0, 0, 0, false | |
| 300 | - | } | |
| 301 | - | return r, g, b, true | |
| 302 | - | } | |
| @@ -229,74 +229,3 @@ func parseTerminalRGB(value string) (TerminalColor, bool) { | |||||
| 229 | } | 229 | } | ||
| 230 | return ColorRGB(channels[0], channels[1], channels[2]), true | 230 | return ColorRGB(channels[0], channels[1], channels[2]), true | ||
| 231 | } | 231 | } | ||
| 232 | - | ||||
| 233 | - | // readOSCResponse drains stdin into a small buffer until either a terminator | |||
| 234 | - | // (BEL or ST) is seen, the deadline expires, or stdin hits EOF. It remains a | |||
| 235 | - | // small helper for callers that only need one OSC reply. | |||
| 236 | - | func readOSCResponse(deadline time.Time) string { | |||
| 237 | - | var buf [128]byte | |||
| 238 | - | n := 0 | |||
| 239 | - | for time.Now().Before(deadline) { | |||
| 240 | - | remaining := time.Until(deadline) | |||
| 241 | - | if remaining <= 0 { | |||
| 242 | - | break | |||
| 243 | - | } | |||
| 244 | - | b, ok, err := peekStdin(os.Stdin, remaining) | |||
| 245 | - | if err != nil || !ok { | |||
| 246 | - | return string(buf[:n]) | |||
| 247 | - | } | |||
| 248 | - | if n < len(buf) { | |||
| 249 | - | buf[n] = b | |||
| 250 | - | n++ | |||
| 251 | - | } | |||
| 252 | - | if b == 0x07 { | |||
| 253 | - | return string(buf[:n]) | |||
| 254 | - | } | |||
| 255 | - | if n >= 2 && buf[n-2] == 0x1b && buf[n-1] == '\\' { | |||
| 256 | - | return string(buf[:n]) | |||
| 257 | - | } | |||
| 258 | - | } | |||
| 259 | - | return string(buf[:n]) | |||
| 260 | - | } | |||
| 261 | - | ||||
| 262 | - | // parseOSC11Reply extracts the (r, g, b) colour components from an OSC 11 | |||
| 263 | - | // reply of the form "\\x1b]11;rgb:RRRR/GGGG/BBBB\\x07" (or with ST | |||
| 264 | - | // terminator). The component widths can be 1, 2, 3, or 4 hex digits per | |||
| 265 | - | // channel; we normalise them into the 0..1 range. | |||
| 266 | - | func parseOSC11Reply(s string) (float64, float64, float64, bool) { | |||
| 267 | - | i := strings.Index(s, "rgb:") | |||
| 268 | - | if i < 0 { | |||
| 269 | - | return 0, 0, 0, false | |||
| 270 | - | } | |||
| 271 | - | body := strings.TrimRight(s[i+len("rgb:"):], "\x07") | |||
| 272 | - | body = strings.TrimSuffix(body, "\x1b\\") | |||
| 273 | - | parts := strings.Split(body, "/") | |||
| 274 | - | if len(parts) != 3 { | |||
| 275 | - | return 0, 0, 0, false | |||
| 276 | - | } | |||
| 277 | - | parse := func(hexstr string) (float64, bool) { | |||
| 278 | - | if len(hexstr) == 0 || len(hexstr) > 4 { | |||
| 279 | - | return 0, false | |||
| 280 | - | } | |||
| 281 | - | v, err := strconv.ParseUint(hexstr, 16, 32) | |||
| 282 | - | if err != nil { | |||
| 283 | - | return 0, false | |||
| 284 | - | } | |||
| 285 | - | max := uint64(1) | |||
| 286 | - | for range hexstr { | |||
| 287 | - | max *= 16 | |||
| 288 | - | } | |||
| 289 | - | max-- | |||
| 290 | - | if max == 0 { | |||
| 291 | - | return 0, false | |||
| 292 | - | } | |||
| 293 | - | return float64(v) / float64(max), true | |||
| 294 | - | } | |||
| 295 | - | r, ok1 := parse(parts[0]) | |||
| 296 | - | g, ok2 := parse(parts[1]) | |||
| 297 | - | b, ok3 := parse(parts[2]) | |||
| 298 | - | if !ok1 || !ok2 || !ok3 { | |||
| 299 | - | return 0, 0, 0, false | |||
| 300 | - | } | |||
| 301 | - | return r, g, b, true | |||
| 302 | - | } | |||