fix(spawn): strip ANSI codes from zellij list-sessions output
Zellij outputs colored text with ANSI escape codes, which caused session name parsing to fail. Now strips escape codes before parsing. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -99,9 +99,11 @@ class SpawnMixin:
|
||||
|
||||
try:
|
||||
# Check rate limit inside lock
|
||||
# Use None sentinel to distinguish "never spawned" from "spawned at time 0"
|
||||
# (time.monotonic() can be close to 0 on fresh process start)
|
||||
now = time.monotonic()
|
||||
last_spawn = _spawn_timestamps.get(project, 0)
|
||||
if now - last_spawn < SPAWN_COOLDOWN_SEC:
|
||||
last_spawn = _spawn_timestamps.get(project)
|
||||
if last_spawn is not None and now - last_spawn < SPAWN_COOLDOWN_SEC:
|
||||
remaining = SPAWN_COOLDOWN_SEC - (now - last_spawn)
|
||||
self._send_json(429, {
|
||||
'ok': False,
|
||||
@@ -177,8 +179,11 @@ class SpawnMixin:
|
||||
)
|
||||
if result.returncode != 0:
|
||||
return False
|
||||
# Strip ANSI escape codes (Zellij outputs colored text)
|
||||
ansi_pattern = re.compile(r'\x1b\[[0-9;]*m')
|
||||
output = ansi_pattern.sub('', result.stdout)
|
||||
# Parse line-by-line to avoid substring false positives
|
||||
for line in result.stdout.splitlines():
|
||||
for line in output.splitlines():
|
||||
# Zellij outputs "session_name [Created ...]" or just "session_name"
|
||||
session_name = line.strip().split()[0] if line.strip() else ''
|
||||
if session_name == ZELLIJ_SESSION:
|
||||
|
||||
Reference in New Issue
Block a user