Fix #3470
This commit is contained in:
parent
cdcf8ed3bd
commit
05fb09f56c
@ -3,7 +3,7 @@
|
||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import json
|
||||
from typing import Any, Optional
|
||||
from typing import Any, Dict, Optional
|
||||
|
||||
from kitty.constants import appname
|
||||
|
||||
@ -24,7 +24,8 @@ class LS(RemoteCommand):
|
||||
f' operating system {appname} windows. Each OS window has an :italic:`id` and a list'
|
||||
' of :italic:`tabs`. Each tab has its own :italic:`id`, a :italic:`title` and a list of :italic:`windows`.'
|
||||
' Each window has an :italic:`id`, :italic:`title`, :italic:`current working directory`, :italic:`process id (PID)`, '
|
||||
' :italic:`command-line` and :italic:`environment` of the process running in the window.\n\n'
|
||||
' :italic:`command-line` and :italic:`environment` of the process running in the window. Additionally, when'
|
||||
' running the command inside a kitty window, that window can be identified by the :italic:`is_self` parameter.\n\n'
|
||||
'You can use these criteria to select windows/tabs for the other commands.'
|
||||
)
|
||||
argspec = ''
|
||||
@ -33,7 +34,19 @@ class LS(RemoteCommand):
|
||||
pass
|
||||
|
||||
def response_from_kitty(self, boss: Boss, window: Optional[Window], payload_get: PayloadGetType) -> ResponseType:
|
||||
|
||||
def serialize_callback(w: Window, result: Dict[str, Any]) -> Dict[str, Any]:
|
||||
result['is_self'] = True
|
||||
return result
|
||||
|
||||
if window is not None:
|
||||
orig_callback = window.serialize_callback
|
||||
window.serialize_callback = serialize_callback
|
||||
try:
|
||||
data = list(boss.list_os_windows())
|
||||
finally:
|
||||
if window is not None:
|
||||
window.serialize_callback = orig_callback
|
||||
return json.dumps(data, indent=2, sort_keys=True)
|
||||
|
||||
|
||||
|
||||
@ -308,6 +308,7 @@ class Window:
|
||||
self.id: int = add_window(tab.os_window_id, tab.id, self.title)
|
||||
self.margin = EdgeWidths()
|
||||
self.padding = EdgeWidths()
|
||||
self.serialize_callback: Optional[Callable[[Window, Dict[str, Any]], Dict[str, Any]]] = None
|
||||
if not self.id:
|
||||
raise Exception('No tab with id: {} in OS Window: {} was found, or the window counter wrapped'.format(tab.id, tab.os_window_id))
|
||||
self.tab_id = tab.id
|
||||
@ -393,7 +394,7 @@ class Window:
|
||||
)
|
||||
|
||||
def serialize_state(self) -> Dict[str, Any]:
|
||||
return {
|
||||
ans = {
|
||||
'version': 1,
|
||||
'id': self.id,
|
||||
'child_title': self.child_title,
|
||||
@ -407,6 +408,9 @@ class Window:
|
||||
'margin': self.margin.serialize(),
|
||||
'padding': self.padding.serialize(),
|
||||
}
|
||||
if self.serialize_callback is not None:
|
||||
ans = self.serialize_callback(self, ans)
|
||||
return ans
|
||||
|
||||
@property
|
||||
def current_colors(self) -> Dict:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user