summaryrefslogtreecommitdiff
path: root/poezio
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 /poezio
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`.
Diffstat (limited to 'poezio')
-rw-r--r--poezio/config.py1
-rw-r--r--poezio/windows/info_bar.py34
2 files changed, 34 insertions, 1 deletions
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: