Start work on specifying a color for extra cursors

This commit is contained in:
Kovid Goyal 2025-08-25 20:08:54 +05:30
parent 3239cec409
commit da641982e2
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 76 additions and 17 deletions

View file

@ -1594,13 +1594,15 @@ class TestScreen(BaseTest):
s = self.create_screen()
c = s.callbacks
# Test detection
parse_bytes(s, b'\x1b[> q') # ]
self.ae(c.wtcbuf, b'\x1b[>-2;-1;1;2;3 q') # ]
def ec(payload=''):
return f'\x1b[>{payload} q'.encode() # ]
parse_bytes(s, ec())
self.ae(c.wtcbuf, ec('-5;-4;-3;-2;-1;1;2;3'))
def current() -> dict[int, tuple[int, int]]:
ans = {}
c.clear()
parse_bytes(s, '\x1b[>-2 q'.encode()) # ]
parse_bytes(s, ec('-2'))
for entry in c.wtcbuf[6:-2].decode().split(';'):
if entry:
which, _, y, x = map(int, entry.split(':'))
@ -1615,10 +1617,10 @@ class TestScreen(BaseTest):
parse_bytes(s, ''.join(buf).encode() + b' q')
if region:
if region is True:
parse_bytes(s, f'\x1b[>{which};4 q'.encode()) # ]
parse_bytes(s, ec(f'{which};4'))
else:
left, top, right, bottom = region
parse_bytes(s, f'\x1b[>{which};4:{top+1}:{left+1}:{bottom+1}:{right+1} q'.encode()) # ]
parse_bytes(s, ec(f'{which};4:{top+1}:{left+1}:{bottom+1}:{right+1}'))
return current()
self.ae(a(1, region=True), {1:{(x, y) for x in range(s.columns) for y in range(s.lines)}})
@ -1628,13 +1630,33 @@ class TestScreen(BaseTest):
self.ae(a(0, (1, 2), (2, 3)), {-1: {(2, 2)}, 2: {(1, 3)}})
self.ae(a(0, region=True), {})
s.cursor.x, s.cursor.y = 1, 2
parse_bytes(s, b'\x1b[>3;0 q') # ]
parse_bytes(s, ec('3;0'))
self.ae(current(), {3: {(1, 2)}})
parse_bytes(s, b'\x1b[>3;2:3 q') # ]
parse_bytes(s, ec('3;2:3'))
self.ae(current(), {3: {(1, 2)}})
parse_bytes(s, b'\x1b[>0;4:3:1:4 q') # ]
parse_bytes(s, ec('0;4:3:1:4'))
self.ae(current(), {})
def sc(op, r=0, g=0, b=0, slot=-3):
parse_bytes(s, ec(f'{slot};{op}:{r}:{g}:{b}'))
c.clear()
parse_bytes(s, ec('-5'))
for x in c.wtcbuf[3:-2].decode().split(';')[1:]:
parts = x.split(':')
if int(parts[0]) == slot:
if op < 2:
self.ae(op, int(parts[1]))
elif op == 2:
self.ae((op, r, g, b), tuple(map(int, parts[1:])))
else:
self.ae((op, r), tuple(map(int, parts[1:])))
break
for slot in (-3, -4):
sc(0, slot=slot)
sc(1, slot=slot)
sc(2, 1, 2, 3, slot=slot)
sc(5, 13, slot=slot)
def detect_url(self, scale=1):
s = self.create_screen(cols=30 * scale)