1
1
from __future__ import division
2
2
3
+ import json
3
4
import base64
4
5
import errno
5
6
import os
@@ -468,15 +469,23 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
468
469
'org.kde.konsole.Session.processId' ), stdout = subprocess .PIPE ) as proc :
469
470
pid = int (proc .communicate ()[0 ].decode ())
470
471
elif terminal in ('kitty' , 'kitten' ):
471
- pid = p .pid
472
-
472
+ pid = None
473
473
out , _ = p .communicate ()
474
474
try :
475
475
kittyid = int (out )
476
476
except ValueError :
477
477
kittyid = None
478
478
if kittyid is None :
479
479
log .error ("Could not parse kitty window ID from output (%r)" , out )
480
+ else :
481
+ lsout , _ = subprocess .Popen (["kitten" , "@" , "ls" , "--match" , "id:%d" % kittyid ], stdin = stdin , stdout = stdout , stderr = stderr ).communicate ()
482
+ try :
483
+ lsj = json .loads (lsout )
484
+ pid = int (lsj [0 ]["tabs" ][0 ]["windows" ][0 ]["pid" ])
485
+ except json .JSONDecodeError as e :
486
+ pid = None
487
+ log .error ("Json decode failed while parsing 'kitten @ ls' output (%r) (error: %r)" , lsout , e )
488
+
480
489
elif terminal == 'cmd.exe' :
481
490
# p.pid is cmd.exe's pid instead of the WSL process we want to start eventually.
482
491
# I don't know how to trace the execution through Windows and back into the WSL2 VM.
@@ -501,8 +510,6 @@ def kill():
501
510
try :
502
511
if terminal == 'qdbus' :
503
512
os .kill (pid , signal .SIGHUP )
504
- elif terminal in ('kitty' , 'kitten' ):
505
- subprocess .Popen (["kitten" , "@" , "close-window" , "--match" , "id:{}" .format (kittyid )], stderr = stderr )
506
513
else :
507
514
os .kill (pid , signal .SIGTERM )
508
515
except OSError :
0 commit comments