Allow specifying whether to count windows at prompts or not for confirm_clsoe
This commit is contained in:
parent
8397970bf8
commit
5bc569c4dd
@ -541,8 +541,9 @@ class Boss:
|
||||
self.confirm_tab_close(tab)
|
||||
|
||||
def confirm_tab_close(self, tab: Tab) -> None:
|
||||
num = tab.number_of_windows_with_running_programs
|
||||
needs_confirmation = get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close
|
||||
x = get_options().confirm_os_window_close
|
||||
num = tab.number_of_windows_with_running_programs if x < 0 else len(tab)
|
||||
needs_confirmation = x != 0 and num >= abs(x)
|
||||
if not needs_confirmation:
|
||||
self.close_tab_no_confirm(tab)
|
||||
return
|
||||
@ -930,8 +931,9 @@ class Boss:
|
||||
|
||||
def confirm_os_window_close(self, os_window_id: int) -> None:
|
||||
tm = self.os_window_map.get(os_window_id)
|
||||
num = 0 if tm is None else tm.number_of_windows_with_running_programs
|
||||
needs_confirmation = tm is not None and get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close
|
||||
q = get_options().confirm_os_window_close
|
||||
num = 0 if tm is None else (tm.number_of_windows_with_running_programs if q < 0 else tm.number_of_windows)
|
||||
needs_confirmation = tm is not None and q != 0 and num >= abs(q)
|
||||
if not needs_confirmation:
|
||||
mark_os_window_for_close(os_window_id)
|
||||
return
|
||||
@ -967,9 +969,10 @@ class Boss:
|
||||
def quit(self, *args: Any) -> None:
|
||||
tm = self.active_tab
|
||||
num = 0
|
||||
x = get_options().confirm_os_window_close
|
||||
for q in self.os_window_map.values():
|
||||
num += q.number_of_windows_with_running_programs
|
||||
needs_confirmation = tm is not None and get_options().confirm_os_window_close > 0 and num >= get_options().confirm_os_window_close
|
||||
num += q.number_of_windows_with_running_programs if x < 0 else q.number_of_windows
|
||||
needs_confirmation = tm is not None and x != 0 and num >= abs(x)
|
||||
if not needs_confirmation:
|
||||
set_application_quit_request(IMPERATIVE_CLOSE_REQUESTED)
|
||||
return
|
||||
|
||||
@ -859,13 +859,15 @@ does not currently work on Wayland.
|
||||
)
|
||||
|
||||
opt('confirm_os_window_close', '0',
|
||||
option_type='positive_int',
|
||||
option_type='int',
|
||||
long_text='''
|
||||
Ask for confirmation when closing an OS window or a tab that has at least this
|
||||
number of kitty windows in it. A value of zero disables confirmation. This
|
||||
confirmation also applies to requests to quit the entire application (all OS
|
||||
windows, via the quit action). Note that if you have :ref:`shell_integration`
|
||||
enabled, a window that is sitting at a shell prompt is not counted.
|
||||
windows, via the quit action). Negative values are converted to positive ones,
|
||||
however, with :ref:`shell_integration` enabled, using negative values means
|
||||
windows sitting at a shell prompt are not counted, only windows where some command is
|
||||
currently running.
|
||||
'''
|
||||
)
|
||||
egr() # }}}
|
||||
|
||||
2
kitty/options/parse.py
generated
2
kitty/options/parse.py
generated
@ -880,7 +880,7 @@ class Parser:
|
||||
ans['command_on_bell'] = to_cmdline(val)
|
||||
|
||||
def confirm_os_window_close(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['confirm_os_window_close'] = positive_int(val)
|
||||
ans['confirm_os_window_close'] = int(val)
|
||||
|
||||
def copy_on_select(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||
ans['copy_on_select'] = copy_on_select(val)
|
||||
|
||||
@ -814,6 +814,13 @@ class TabManager: # {{{
|
||||
count += tab.number_of_windows_with_running_programs
|
||||
return count
|
||||
|
||||
@property
|
||||
def number_of_windows(self) -> int:
|
||||
count = 0
|
||||
for tab in self:
|
||||
count += len(tab)
|
||||
return count
|
||||
|
||||
def tab_for_id(self, tab_id: int) -> Optional[Tab]:
|
||||
for t in self.tabs:
|
||||
if t.id == tab_id:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user