summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-05-24 23:11:26 +0200
committermathieui <mathieui@mathieui.net>2012-05-24 23:11:26 +0200
commit5e6838fd9f501f656d71ecfa04658f2f690b4ce7 (patch)
tree9fa7bc8274117e3023f7dbc12c27f002baaa7ac8
parent32f8ada92deb7788a46b787ce08d97aa622140f2 (diff)
downloadpoezio-5e6838fd9f501f656d71ecfa04658f2f690b4ce7.tar.gz
poezio-5e6838fd9f501f656d71ecfa04658f2f690b4ce7.tar.bz2
poezio-5e6838fd9f501f656d71ecfa04658f2f690b4ce7.tar.xz
poezio-5e6838fd9f501f656d71ecfa04658f2f690b4ce7.zip
Truncate everything in the roster if needed.
Group names, resources jids, and bare jid/roster name combinations are now truncated if they are bigger than the window size. If there is a resource (for a contct) or a number of online contacts (for groups), it will still be displayed at the end of the line.
-rw-r--r--src/windows.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/windows.py b/src/windows.py
index 06214abb..f399938e 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -1696,11 +1696,16 @@ class RosterWin(Win):
else:
self.addstr(y, 0, '[-] ')
contacts = " (%s/%s)" % (group.get_nb_connected_contacts(), len(group))
- self.addstr(y, 4, group.name + contacts)
+ self.addstr(y, 4, self.truncate_name(group.name, len(contacts)+4) + contacts)
if colored:
self._win.attroff(to_curses_attr(get_theme().COLOR_SELECTED_ROW))
self.finish_line()
+ def truncate_name(self, name, added):
+ if len(name) + added <= self.width:
+ return name
+ return name[:self.width - added - 1] + '…'
+
def draw_contact_line(self, y, contact, colored):
"""
Draw on a line all informations about one contact.
@@ -1708,6 +1713,7 @@ class RosterWin(Win):
Use 'color' to draw the jid/display_name to show what is
the currently selected contact in the list
"""
+
resource = contact.get_highest_priority_resource()
if not resource:
# There's no online resource
@@ -1717,23 +1723,31 @@ class RosterWin(Win):
presence = resource.presence
nb = ' (%s)' % len(contact)
color = RosterWin.color_show[presence]()
- if config.getl('show_roster_jids', 'true') == 'false' and contact.name:
- display_name = '%s %s' % (contact.name, nb[1:])
- elif contact.name:
- display_name = '%s (%s)%s' % (contact.name,
- contact.bare_jid, nb,)
- else:
- display_name = '%s%s' % (contact.bare_jid, nb,)
+ added = 2 + len(get_theme().CHAR_STATUS) + len(nb)
+
self.addstr(y, 0, ' ')
self.addstr(get_theme().CHAR_STATUS, to_curses_attr(color))
- if resource:
- self.addstr(' [+]' if contact.folded else ' [-]')
+
self.addstr(' ')
+ if resource:
+ self.addstr('[+] ' if contact.folded else '[-] ')
+ added += 4
+ if contact.ask:
+ added += 1
+
+ if config.getl('show_roster_jids', 'true') == 'false' and contact.name:
+ display_name = '%s' % contact.name
+ elif contact.name and contact.name != contact.bare_jid:
+ display_name = '%s (%s)' % (contact.name, contact.bare_jid)
+ else:
+ display_name = '%s' % (contact.bare_jid,)
+ display_name = self.truncate_name(display_name, added) + nb
+
if colored:
self.addstr(display_name, to_curses_attr(get_theme().COLOR_SELECTED_ROW))
else:
self.addstr(display_name)
- if contact.ask == 'asked':
+ if contact.ask:
self.addstr('?', to_curses_attr(get_theme().COLOR_HIGHLIGHT_NICK))
self.finish_line()
@@ -1744,9 +1758,9 @@ class RosterWin(Win):
color = RosterWin.color_show[resource.presence]()
self.addstr(y, 4, get_theme().CHAR_STATUS, to_curses_attr(color))
if colored:
- self.addstr(y, 6, str(resource.jid), to_curses_attr(get_theme().COLOR_SELECTED_ROW))
+ self.addstr(y, 6, self.truncate_name(str(resource.jid), 6), to_curses_attr(get_theme().COLOR_SELECTED_ROW))
else:
- self.addstr(y, 6, str(resource.jid))
+ self.addstr(y, 6, self.truncate_name(str(resource.jid), 6))
self.finish_line()
def get_selected_row(self):