mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-25 01:38:02 +02:00
Pass session serialization options into all contexts where they might be needed
This commit is contained in:
@@ -26,7 +26,7 @@ from weakref import WeakValueDictionary
|
||||
|
||||
from .child import cached_process_data, default_env, set_default_env
|
||||
from .cli import create_opts, green, parse_args
|
||||
from .cli_stub import CLIOptions
|
||||
from .cli_stub import CLIOptions, SaveAsSessionOptions
|
||||
from .clipboard import (
|
||||
Clipboard,
|
||||
ClipboardType,
|
||||
@@ -122,7 +122,7 @@ from .notifications import NotificationManager
|
||||
from .options.types import Options, nullable_colors
|
||||
from .options.utils import MINIMUM_FONT_SIZE, KeyboardMode, KeyDefinition
|
||||
from .os_window_size import initial_window_size_func
|
||||
from .session import Session, create_sessions, get_os_window_sizing_data, goto_session, save_as_session
|
||||
from .session import Session, create_sessions, default_save_as_session_opts, get_os_window_sizing_data, goto_session, save_as_session
|
||||
from .shaders import load_shader_programs
|
||||
from .simple_cli_definitions import grab_keyboard_docs
|
||||
from .tabs import SpecialWindow, SpecialWindowInstance, Tab, TabDict, TabManager
|
||||
@@ -501,11 +501,13 @@ class Boss:
|
||||
'background_opacity': bo,
|
||||
}
|
||||
|
||||
def serialize_state_as_session(self) -> Iterator[str]:
|
||||
def serialize_state_as_session(self, ser_opts: SaveAsSessionOptions | None = None) -> Iterator[str]:
|
||||
if ser_opts is None:
|
||||
ser_opts = default_save_as_session_opts()
|
||||
s = {current_focused_os_window_id(): 2, last_focused_os_window_id(): 1}
|
||||
for i, os_window_id in enumerate(sorted(self.os_window_map, key=lambda wid: s.get(wid, 0))):
|
||||
tm = self.os_window_map[os_window_id]
|
||||
yield from tm.serialize_state_as_session(is_first=i==0)
|
||||
yield from tm.serialize_state_as_session(is_first=i==0, ser_opts=ser_opts)
|
||||
|
||||
@property
|
||||
def all_tab_managers(self) -> Iterator[TabManager]:
|
||||
|
||||
@@ -467,6 +467,12 @@ def save_as_session_part2(boss: BossType, opts: SaveAsSessionOptions, path: str)
|
||||
boss.edit_file(path)
|
||||
|
||||
|
||||
def default_save_as_session_opts() -> SaveAsSessionOptions:
|
||||
from kitty.cli import parse_args
|
||||
return parse_args(
|
||||
[], save_as_session_options, result_class=SaveAsSessionOptions)[0]
|
||||
|
||||
|
||||
def save_as_session(boss: BossType, cmdline: Sequence[str]) -> None:
|
||||
from kitty.cli import parse_args
|
||||
opts: SaveAsSessionOptions
|
||||
|
||||
@@ -20,7 +20,7 @@ from typing import (
|
||||
|
||||
from .borders import Border, Borders
|
||||
from .child import Child
|
||||
from .cli_stub import CLIOptions
|
||||
from .cli_stub import CLIOptions, SaveAsSessionOptions
|
||||
from .constants import appname
|
||||
from .fast_data_types import (
|
||||
GLFW_MOUSE_BUTTON_LEFT,
|
||||
@@ -292,14 +292,14 @@ class Tab: # {{{
|
||||
'name': self.name,
|
||||
}
|
||||
|
||||
def serialize_state_as_session(self) -> list[str]:
|
||||
def serialize_state_as_session(self, ser_opts: SaveAsSessionOptions) -> list[str]:
|
||||
import shlex
|
||||
launch_cmds = []
|
||||
active_idx = self.windows.active_group_idx
|
||||
for i, g in enumerate(self.windows.iter_all_layoutable_groups()):
|
||||
gw: list[str] = []
|
||||
for window in g:
|
||||
lc = window.as_launch_command(is_overlay=bool(gw))
|
||||
lc = window.as_launch_command(ser_opts, is_overlay=bool(gw))
|
||||
if lc:
|
||||
gw.append(shlex.join(lc))
|
||||
if gw:
|
||||
@@ -1205,7 +1205,7 @@ class TabManager: # {{{
|
||||
'active_tab_idx': self.active_tab_idx,
|
||||
}
|
||||
|
||||
def serialize_state_as_session(self, is_first: bool = False) -> list[str]:
|
||||
def serialize_state_as_session(self, ser_opts: SaveAsSessionOptions, is_first: bool = False) -> list[str]:
|
||||
ans = []
|
||||
hmap = {tab_id: i for i, tab_id in enumerate(self.active_tab_history)}
|
||||
if (at := self.active_tab) is not None:
|
||||
@@ -1213,7 +1213,7 @@ class TabManager: # {{{
|
||||
def skey(tab: Tab) -> int:
|
||||
return hmap.get(tab.id, -1)
|
||||
for tab in sorted(self, key=skey):
|
||||
ans.extend(tab.serialize_state_as_session())
|
||||
ans.extend(tab.serialize_state_as_session(ser_opts))
|
||||
if ans:
|
||||
prefix = [] if is_first else ['', '', 'new_os_window']
|
||||
if self.wm_class:
|
||||
|
||||
@@ -27,7 +27,7 @@ from typing import (
|
||||
)
|
||||
|
||||
from .child import ProcessDesc
|
||||
from .cli_stub import CLIOptions
|
||||
from .cli_stub import CLIOptions, SaveAsSessionOptions
|
||||
from .clipboard import ClipboardRequestManager, set_clipboard_string
|
||||
from .constants import (
|
||||
appname,
|
||||
@@ -1945,7 +1945,7 @@ class Window:
|
||||
' Return the last position at which a mouse event was received by this window '
|
||||
return get_mouse_data_for_window(self.os_window_id, self.tab_id, self.id)
|
||||
|
||||
def as_launch_command(self, is_overlay: bool = False) -> list[str]:
|
||||
def as_launch_command(self, ser_opts: SaveAsSessionOptions, is_overlay: bool = False) -> list[str]:
|
||||
' Return a launch command that can be used to serialize this window. Empty list indicates not serializable. '
|
||||
if self.actions_on_close or self.actions_on_focus_change or self.actions_on_removal:
|
||||
# such windows are typically UI kittens. The actions are not
|
||||
|
||||
Reference in New Issue
Block a user