summaryrefslogtreecommitdiff
path: root/poezio/core
diff options
context:
space:
mode:
Diffstat (limited to 'poezio/core')
-rw-r--r--poezio/core/commands.py14
-rw-r--r--poezio/core/core.py35
-rw-r--r--poezio/core/tabs.py34
3 files changed, 82 insertions, 1 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 6bf1d338..46dab5cc 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -219,6 +219,20 @@ class CommandCore:
return
self.core.tabs.set_current_tab(match)
+ @command_args_parser.quoted(1)
+ def wup(self, args):
+ """
+ /wup <prefix of name>
+ """
+ if args is None:
+ return self.help('wup')
+
+ prefix = args[0]
+ _, match = self.core.tabs.find_by_unique_prefix(prefix)
+ if match is None:
+ return
+ self.core.tabs.set_current_tab(match)
+
@command_args_parser.quoted(2)
def move_tab(self, args):
"""
diff --git a/poezio/core/core.py b/poezio/core/core.py
index 06d56062..8ac88dd4 100644
--- a/poezio/core/core.py
+++ b/poezio/core/core.py
@@ -209,6 +209,7 @@ class Core:
'_show_plugins': self.command.plugins,
'_show_xmltab': self.command.xml_tab,
'_toggle_pane': self.toggle_left_pane,
+ "_go_to_room_name": self.go_to_room_name,
###### status actions ######
'_available': lambda: self.command.status('available'),
'_away': lambda: self.command.status('away'),
@@ -1108,6 +1109,34 @@ class Core:
keyboard.continuation_keys_callback = read_next_digit
+ def go_to_room_name(self) -> None:
+ room_name_jump = []
+
+ def read_next_letter(s) -> None:
+ nonlocal room_name_jump
+ room_name_jump.append(s)
+ any_matched, unique_tab = self.tabs.find_by_unique_prefix(
+ "".join(room_name_jump)
+ )
+
+ if not any_matched:
+ return
+
+ if unique_tab is not None:
+ self.tabs.set_current_tab(unique_tab)
+ # NOTE: returning here means that as soon as the tab is
+ # matched, normal input resumes. If we do *not* return here,
+ # any further characters matching the prefix of the tab will
+ # be swallowed (and a lot of tab switching will happen...),
+ # until a non-matching character or escape or something is
+ # pressed.
+ # This behaviour *may* be desirable.
+ return
+
+ keyboard.continuation_keys_callback = read_next_letter
+
+ keyboard.continuation_keys_callback = read_next_letter
+
def go_to_roster(self) -> None:
"Select the roster as the current tab"
self.tabs.set_current_tab(self.tabs.first())
@@ -1709,6 +1738,12 @@ class Core:
usage='<number or name>',
shortdesc='Go to the specified room',
completion=self.completion.win)
+ self.register_command(
+ 'wup',
+ self.command.wup,
+ usage='<prefix>',
+ shortdesc='Go to the tab whose name uniquely starts with prefix',
+ completion=self.completion.win)
self.commands['w'] = self.commands['win']
self.register_command(
'move_tab',
diff --git a/poezio/core/tabs.py b/poezio/core/tabs.py
index abea7313..d5909d39 100644
--- a/poezio/core/tabs.py
+++ b/poezio/core/tabs.py
@@ -24,11 +24,12 @@ have become [0|1|2|3], with the tab "4" renumbered to "3" if gap tabs are
disabled.
"""
-from typing import List, Dict, Type, Optional, Union
+from typing import List, Dict, Type, Optional, Union, Tuple
from collections import defaultdict
from slixmpp import JID
from poezio import tabs
from poezio.events import EventHandler
+from poezio.config import config
class Tabs:
@@ -139,6 +140,37 @@ class Tabs:
return self._tabs[i]
return None
+ def find_by_unique_prefix(self, prefix: str) -> Tuple[bool, Optional[tabs.Tab]]:
+ """
+ Get a tab by its unique name prefix, ignoring case.
+
+ :return: A tuple indicating the presence of any match, as well as the
+ uniquely matched tab (if any).
+
+ The first element, a boolean, in the returned tuple indicates whether
+ at least one tab matched.
+
+ The second element (a Tab) in the returned tuple is the uniquely
+ matched tab, if any. If multiple or no tabs match the prefix, the
+ second element in the tuple is :data:`None`.
+ """
+
+ # TODO: should this maybe use something smarter than .lower()?
+ # something something stringprep?
+ prefix = prefix.lower()
+ candidate = None
+ any_matched = False
+ for tab in self._tabs:
+ if not tab.name.lower().startswith(prefix):
+ continue
+ any_matched = True
+ if candidate is not None:
+ # multiple tabs match -> return None
+ return True, None
+ candidate = tab
+
+ return any_matched, candidate
+
def by_name_and_class(self, name: str,
cls: Type[tabs.Tab]) -> Optional[tabs.Tab]:
"""Get a tab with its name and class"""