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`.
This commit is contained in:
Jonas Schäfer 2020-05-10 11:21:27 +02:00
parent eab4615fe0
commit a15e52dc39
4 changed files with 52 additions and 1 deletions

View file

@ -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

View file

@ -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``

View file

@ -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,

View file

@ -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: