mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-24 17:27:39 +02:00
Allow using boolean operators when matching windows or tabs
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
# License: GPL v3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import os
|
||||
import re
|
||||
import stat
|
||||
import weakref
|
||||
from collections import deque
|
||||
@@ -10,7 +11,7 @@ from operator import attrgetter
|
||||
from time import monotonic
|
||||
from typing import (
|
||||
Any, Deque, Dict, Generator, Iterable, Iterator, List, NamedTuple,
|
||||
Optional, Pattern, Sequence, Set, Tuple, Union
|
||||
Optional, Sequence, Set, Tuple, Union
|
||||
)
|
||||
|
||||
from .borders import Border, Borders
|
||||
@@ -687,11 +688,26 @@ class Tab: # {{{
|
||||
for w in self:
|
||||
yield w.as_dict(is_focused=w is active_window, is_self=w is self_window)
|
||||
|
||||
def matches(self, field: str, pat: 'Pattern[str]') -> bool:
|
||||
if field == 'id':
|
||||
return bool(pat.pattern == str(self.id))
|
||||
def matches_query(self, field: str, query: str, active_tab_manager: Optional['TabManager'] = None) -> bool:
|
||||
if field == 'title':
|
||||
return pat.search(self.effective_title) is not None
|
||||
return re.search(query, self.effective_title) is not None
|
||||
if field == 'id':
|
||||
return query == str(self.id)
|
||||
if field in ('window_id', 'window_title'):
|
||||
field = field.partition('_')[-1]
|
||||
for w in self:
|
||||
if w.matches_query(field, query):
|
||||
return True
|
||||
return False
|
||||
if field == 'index':
|
||||
if active_tab_manager and len(active_tab_manager.tabs):
|
||||
idx = (int(query) + len(active_tab_manager.tabs)) % len(active_tab_manager.tabs)
|
||||
return active_tab_manager.tabs[idx] is self
|
||||
return False
|
||||
if field == 'recent':
|
||||
if active_tab_manager and len(active_tab_manager.tabs):
|
||||
return self is active_tab_manager.nth_active_tab(int(query))
|
||||
return False
|
||||
return False
|
||||
|
||||
def __iter__(self) -> Iterator[Window]:
|
||||
|
||||
Reference in New Issue
Block a user