summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonas Schäfer <j.wielicki@sotecware.net>2020-05-10 11:21:27 +0200
committerJonas Schäfer <j.wielicki@sotecware.net>2020-05-12 22:26:51 +0200
commita15e52dc39e7c916804c788ff1e832fd6f58c735 (patch)
tree6221a2730fbb015c56a66873b5a9916aef264805
parenteab4615fe046d40aefdf4cd18643f99183fc4aba (diff)
downloadpoezio-a15e52dc39e7c916804c788ff1e832fd6f58c735.tar.gz
poezio-a15e52dc39e7c916804c788ff1e832fd6f58c735.tar.bz2
poezio-a15e52dc39e7c916804c788ff1e832fd6f58c735.tar.xz
poezio-a15e52dc39e7c916804c788ff1e832fd6f58c735.zip
Add option to show only the unique prefix of tab names
When the set of tabs used fluctuate, the memory of which number belongs to which chat becomes difficult to work with. Non-numbers can be used to navigate tabs with `/win`, however, it is difficult to know which letters are required to select a certain tab. This option introduces a display mode for tab names where only the unique prefix of the tab name is shown, saving space and providing with a minimal string which can be used with `/win`.
-rw-r--r--data/default_config.cfg7
-rw-r--r--doc/source/configuration.rst11
-rw-r--r--poezio/config.py1
-rw-r--r--poezio/windows/info_bar.py34
4 files changed, 52 insertions, 1 deletions
diff --git a/data/default_config.cfg b/data/default_config.cfg
index 908a3d70..aef4d62a 100644
--- a/data/default_config.cfg
+++ b/data/default_config.cfg
@@ -548,6 +548,13 @@ use_bookmarks_method =
# “true” should be the most comfortable value
#lazy_resize = true
+# If set to true and if show_tab_names is set, the info bar will only show
+# the unique prefix of each tab name instead of the full name. This saves a
+# lot of space if many tabs exist or are active.
+# Best used with the `/wup` command or the `_go_to_room_name` action to select
+# a tab based on the prefix.
+#unique_prefix_tab_names = false
+
[bindings]
# Bindings are keyboard shortcut aliases. You can use them
# to define your own keys and bind them with some functions
diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst
index 9619022a..aceb6fb4 100644
--- a/doc/source/configuration.rst
+++ b/doc/source/configuration.rst
@@ -793,6 +793,17 @@ or the way messages are displayed.
If you want to show the tab name in the bottom Tab bar, set this to ``true``.
+ unique_prefix_tab_names
+
+ **Default value:** ``false``
+
+ If this and :term:`show_tab_names` is set to true, only the shortest
+ unique prefix of each tab name is shown instead of the full name. This
+ can declutter the interface in an instance with many tabs shown in the
+ interface, while not having to use numbers (which may change completely due to reordering).
+
+ Takes precedence over `use_tab_nicks`.
+
show_tab_numbers
**Default value:** ``true``
diff --git a/poezio/config.py b/poezio/config.py
index 8da71071..09d465cd 100644
--- a/poezio/config.py
+++ b/poezio/config.py
@@ -136,6 +136,7 @@ DEFAULT_CONFIG = {
'theme': 'default',
'themes_dir': '',
'tmp_image_dir': '',
+ 'unique_prefix_tab_names': False,
'use_bookmarks_method': '',
'use_log': True,
'use_remote_bookmarks': True,
diff --git a/poezio/windows/info_bar.py b/poezio/windows/info_bar.py
index ac900103..e94e1810 100644
--- a/poezio/windows/info_bar.py
+++ b/poezio/windows/info_bar.py
@@ -6,6 +6,7 @@ The GlobalInfoBar can be either horizontal or vertical
(VerticalGlobalInfoBar).
"""
import logging
+import itertools
log = logging.getLogger(__name__)
import curses
@@ -13,6 +14,7 @@ import curses
from poezio.config import config
from poezio.windows.base_wins import Win
from poezio.theming import get_theme, to_curses_attr
+from poezio.common import unique_prefix_of
class GlobalInfoBar(Win):
@@ -33,6 +35,34 @@ class GlobalInfoBar(Win):
show_nums = config.get('show_tab_numbers')
use_nicks = config.get('use_tab_nicks')
show_inactive = config.get('show_inactive_tabs')
+ unique_prefix_tab_names = config.get('unique_prefix_tab_names')
+
+ if unique_prefix_tab_names:
+ unique_prefixes = [None] * len(self.core.tabs)
+ sorted_tab_indices = sorted(
+ (str(tab.name), i)
+ for i, tab in enumerate(self.core.tabs)
+ )
+ prev_name = ""
+ for (name, i), next_item in itertools.zip_longest(
+ sorted_tab_indices, sorted_tab_indices[1:]):
+ # TODO: should this maybe use something smarter than .lower()?
+ # something something stringprep?
+ name = name.lower()
+ prefix_prev = unique_prefix_of(name, prev_name)
+ if next_item is not None:
+ prefix_next = unique_prefix_of(name, next_item[0].lower())
+ else:
+ prefix_next = name[0]
+
+ # to be unique, we have to use the longest prefix
+ if len(prefix_next) > len(prefix_prev):
+ prefix = prefix_next
+ else:
+ prefix = prefix_prev
+
+ unique_prefixes[i] = prefix
+ prev_name = name
for nb, tab in enumerate(self.core.tabs):
if not tab:
@@ -46,7 +76,9 @@ class GlobalInfoBar(Win):
if show_names:
self.addstr(' ', to_curses_attr(color))
if show_names:
- if use_nicks:
+ if unique_prefix_tab_names:
+ self.addstr(unique_prefixes[nb], to_curses_attr(color))
+ elif use_nicks:
self.addstr("%s" % str(tab.get_nick()),
to_curses_attr(color))
else: