|
122 | 122 | from .options.types import Options, nullable_colors |
123 | 123 | from .options.utils import MINIMUM_FONT_SIZE, KeyboardMode, KeyDefinition |
124 | 124 | from .os_window_size import initial_window_size_func |
125 | | -from .session import Session, create_sessions, default_save_as_session_opts, get_os_window_sizing_data, goto_session, save_as_session |
| 125 | +from .session import ( |
| 126 | + Session, |
| 127 | + close_session_with_confirm, |
| 128 | + create_sessions, |
| 129 | + default_save_as_session_opts, |
| 130 | + get_os_window_sizing_data, |
| 131 | + goto_session, |
| 132 | + save_as_session, |
| 133 | +) |
126 | 134 | from .shaders import load_shader_programs |
127 | 135 | from .simple_cli_definitions import grab_keyboard_docs |
128 | 136 | from .tabs import SpecialWindow, SpecialWindowInstance, Tab, TabDict, TabManager |
@@ -1025,7 +1033,7 @@ def mark_window_for_close(self, q: Window | None | int = None) -> None: |
1025 | 1033 | def close_window(self) -> None: |
1026 | 1034 | self.mark_window_for_close(self.window_for_dispatch) |
1027 | 1035 |
|
1028 | | - def close_windows_with_confirmation_msg(self, windows: Iterable[Window], active_window: Window | None) -> tuple[str, int]: |
| 1036 | + def close_windows_with_confirmation_msg(self, windows: Iterable[Window], active_window: Window | None = None) -> tuple[str, int]: |
1029 | 1037 | num_running_programs = 0 |
1030 | 1038 | num_background_programs = 0 |
1031 | 1039 | count_background = get_options().confirm_os_window_close[1] |
@@ -1268,6 +1276,12 @@ def close_tab_no_confirm(self, tab: Tab) -> None: |
1268 | 1276 | for window in tab: |
1269 | 1277 | self.mark_window_for_close(window) |
1270 | 1278 |
|
| 1279 | + def close_windows_no_confirm(self, windows: Sequence[Window]) -> None: |
| 1280 | + if self.current_visual_select is not None: |
| 1281 | + self.cancel_current_visual_select() |
| 1282 | + for window in windows: |
| 1283 | + self.mark_window_for_close(window) |
| 1284 | + |
1271 | 1285 | @ac('win', 'Toggle the fullscreen status of the active OS Window') |
1272 | 1286 | def toggle_fullscreen(self, os_window_id: int = 0) -> None: |
1273 | 1287 | if os_window_id == 0: |
@@ -1538,6 +1552,14 @@ def active_session(self) -> str: |
1538 | 1552 | return t.created_in_session_name |
1539 | 1553 | return '' |
1540 | 1554 |
|
| 1555 | + @property |
| 1556 | + def all_loaded_session_names(self) -> Iterator[str]: |
| 1557 | + seen = set() |
| 1558 | + for w in self.all_windows: |
| 1559 | + if w.created_in_session_name and w.created_in_session_name not in seen: |
| 1560 | + seen.add(w.created_in_session_name) |
| 1561 | + yield w.created_in_session_name |
| 1562 | + |
1541 | 1563 | def refresh_active_tab_bar(self) -> bool: |
1542 | 1564 | tm = self.active_tab_manager |
1543 | 1565 | if tm: |
@@ -3057,14 +3079,29 @@ def done2(target_window_id: int, self: Boss) -> None: |
3057 | 3079 | ) |
3058 | 3080 | return q if isinstance(q, Window) else None |
3059 | 3081 |
|
3060 | | - @ac('misc', 'Switch to the specified session, creating it if not already present. See :ref:`goto_session`.') |
| 3082 | + @ac('session', 'Switch to the specified session, creating it if not already present. See :ref:`goto_session`.') |
3061 | 3083 | def goto_session(self, *cmdline: str) -> None: |
3062 | 3084 | goto_session(self, cmdline) |
3063 | 3085 |
|
3064 | | - @ac('misc', 'Save the current kitty state as a session file. See :ref:`save_as_session`.') |
| 3086 | + @ac('session', 'Save the current kitty state as a session file. See :ref:`save_as_session`.') |
3065 | 3087 | def save_as_session(self, *cmdline: str) -> None: |
3066 | 3088 | save_as_session(self, cmdline) |
3067 | 3089 |
|
| 3090 | + @ac('session', ''' |
| 3091 | + Close a session, that is, close all windows that belong to the session. |
| 3092 | + Examples:: |
| 3093 | + # Ask for the session to close |
| 3094 | + map f1 close_session |
| 3095 | + # Close the currently active session |
| 3096 | + map f1 close_session . |
| 3097 | + # Close session by name |
| 3098 | + map f1 close_session "my session" |
| 3099 | + # Close session by path to session file |
| 3100 | + map f1 close_session "/path/to/session/file.kitty-session" |
| 3101 | + ''') |
| 3102 | + def close_session(self, *cmdline: str) -> None: |
| 3103 | + close_session_with_confirm(self, cmdline) |
| 3104 | + |
3068 | 3105 | @ac('tab', 'Interactively select a tab to switch to') |
3069 | 3106 | def select_tab(self) -> None: |
3070 | 3107 |
|
|
0 commit comments