summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core.py30
-rw-r--r--src/tabs.py46
-rw-r--r--src/theming.py10
-rw-r--r--src/windows.py51
4 files changed, 110 insertions, 27 deletions
diff --git a/src/core.py b/src/core.py
index ce675f04..120438ed 100644
--- a/src/core.py
+++ b/src/core.py
@@ -193,12 +193,7 @@ class Core(object):
"""
self.stdscr = curses.initscr()
self.init_curses(self.stdscr)
- # Init the tab's size.
- tabs.Tab.resize(self.stdscr)
- # resize the information_win to its initial size
- self.resize_global_information_win()
- # resize the global_info_bar to its initial size
- self.resize_global_info_bar()
+ self.call_for_resize()
default_tab = tabs.RosterInfoTab()
default_tab.on_gain_focus()
self.tabs.append(default_tab)
@@ -226,6 +221,12 @@ class Core(object):
"""
with g_lock:
self.tab_win.resize(1, tabs.Tab.width, tabs.Tab.height - 2, 0)
+ if config.get('enable_left_tab_list', 'false') == 'true':
+ height, width = self.stdscr.getmaxyx()
+ truncated_win = self.stdscr.subwin(height, config.get('vertical_tab_list_size', 20), 0, 0)
+ self.left_tab_win = windows.VerticalGlobalInfoBar(truncated_win)
+ else:
+ self.left_tab_win = None
def on_exception(self, typ, value, trace):
"""
@@ -749,16 +750,25 @@ class Core(object):
"""
Called when we want to resize the screen
"""
- tabs.Tab.resize(self.stdscr)
- self.resize_global_information_win()
+ # If we have the tabs list on the left, we just give a truncated
+ # window to each Tab class, so the draw themself in the portion
+ # of the screen that the can occupy, and we draw the tab list
+ # on the left remaining space
+ if config.get('enable_left_tab_list', 'false') == 'true':
+ scr = self.stdscr.subwin(0, config.get('vertical_tab_list_size', 20))
+ else:
+ scr = self.stdscr
+ tabs.Tab.resize(scr)
self.resize_global_info_bar()
+ self.resize_global_information_win()
with g_lock:
for tab in self.tabs:
if config.get('lazy_resize', 'true') == 'true':
tab.need_resize = True
else:
tab.resize()
- self.full_screen_redraw()
+ if self.tabs:
+ self.full_screen_redraw()
def read_keyboard(self):
"""
@@ -878,7 +888,7 @@ class Core(object):
self.doupdate()
def refresh_tab_win(self):
- self.current_tab().tab_win.refresh()
+ self.current_tab().refresh_tab_win()
if self.current_tab().input:
self.current_tab().input.refresh()
self.doupdate()
diff --git a/src/tabs.py b/src/tabs.py
index ef4f9803..4ed8a335 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -69,6 +69,17 @@ STATE_COLORS = {
# 'attention': lambda: get_theme().COLOR_TAB_ATTENTION,
}
+VERTICAL_STATE_COLORS = {
+ 'disconnected': lambda: get_theme().COLOR_VERTICAL_TAB_DISCONNECTED,
+ 'message': lambda: get_theme().COLOR_VERTICAL_TAB_NEW_MESSAGE,
+ 'highlight': lambda: get_theme().COLOR_VERTICAL_TAB_HIGHLIGHT,
+ 'private': lambda: get_theme().COLOR_VERTICAL_TAB_PRIVATE,
+ 'normal': lambda: get_theme().COLOR_VERTICAL_TAB_NORMAL,
+ 'current': lambda: get_theme().COLOR_VERTICAL_TAB_CURRENT,
+# 'attention': lambda: get_theme().COLOR_VERTICAL_TAB_ATTENTION,
+ }
+
+
STATE_PRIORITY = {
'normal': -1,
'current': -1,
@@ -107,6 +118,13 @@ class Tab(object):
return Tab.tab_core.tab_win
@property
+ def left_tab_win(self):
+ if not Tab.tab_core:
+ Tab.tab_core = singleton.Singleton(core.Core)
+ return Tab.tab_core.left_tab_win
+
+
+ @property
def info_win(self):
return self.core.information_win
@@ -115,6 +133,10 @@ class Tab(object):
return STATE_COLORS[self._state]()
@property
+ def vertical_color(self):
+ return VERTICAL_STATE_COLORS[self._state]()
+
+ @property
def state(self):
return self._state
@@ -135,6 +157,7 @@ class Tab(object):
Tab.visible = False
else:
Tab.visible = True
+ windows.Win._tab_win = scr
def complete_commands(self, the_input):
"""
@@ -202,6 +225,11 @@ class Tab(object):
else:
return False
+ def refresh_tab_win(self):
+ self.tab_win.refresh()
+ if self.left_tab_win:
+ self.left_tab_win.refresh()
+
def refresh(self):
"""
Called on each screen refresh (when something has changed)
@@ -892,7 +920,7 @@ class MucTab(ChatTab):
self.v_separator.refresh()
self.user_win.refresh(self.users)
self.info_header.refresh(self, self.text_win)
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.info_win.refresh()
self.input.refresh()
@@ -1064,7 +1092,7 @@ class MucTab(ChatTab):
if from_nick == self.own_nick: # we are banned
self.disconnect()
self.core.disable_private_tabs(self.name)
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.core.doupdate()
if by:
kick_msg = _('\x191}%(spec)s \x193}You\x195} have been banned by \x194}%(by)s') % {'spec': get_theme().CHAR_KICK, 'by':by}
@@ -1091,7 +1119,7 @@ class MucTab(ChatTab):
if from_nick == self.own_nick: # we are kicked
self.disconnect()
self.core.disable_private_tabs(self.name)
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.core.doupdate()
if by:
kick_msg = _('\x191}%(spec)s \x193}You\x195} have been kicked by \x193}%(by)s') % {'spec': get_theme().CHAR_KICK, 'by':by}
@@ -1119,7 +1147,7 @@ class MucTab(ChatTab):
# We are now out of the room. Happens with some buggy (? not sure) servers
self.disconnect()
self.core.disable_private_tabs(from_room)
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.core.doupdate()
hide_exit_join = config.get('hide_exit_join', -1) if config.get('hide_exit_join', -1) >= -1 else -1
if hide_exit_join == -1 or user.has_talked_since(hide_exit_join):
@@ -1377,7 +1405,7 @@ class PrivateTab(ChatTab):
self.text_win.refresh()
self.info_header.refresh(self.name, self.text_win, self.chatstate)
self.info_win.refresh()
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.input.refresh()
def refresh_info_header(self):
@@ -1853,7 +1881,7 @@ class RosterInfoTab(Tab):
self.roster_win.refresh(roster)
self.contact_info_win.refresh(self.roster_win.get_selected_row())
self.information_win.refresh()
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.input.refresh()
def get_name(self):
@@ -2118,7 +2146,7 @@ class ConversationTab(ChatTab):
self.upper_bar.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()))
self.info_header.refresh(self.get_name(), roster.get_contact_by_jid(self.get_name()), self.text_win, self.chatstate, ConversationTab.additional_informations)
self.info_win.refresh()
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.input.refresh()
def refresh_info_header(self):
@@ -2231,7 +2259,7 @@ class MucListTab(Tab):
self.upper_message.refresh()
self.list_header.refresh()
self.listview.refresh()
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.input.refresh()
self.update_commands()
@@ -2379,7 +2407,7 @@ class SimpleTextTab(Tab):
self.resize()
log.debug(' TAB Refresh: %s'%self.__class__.__name__)
self.text_win.refresh()
- self.tab_win.refresh()
+ self.refresh_tab_win()
self.input.refresh()
def on_lose_focus(self):
diff --git a/src/theming.py b/src/theming.py
index 0a7ab22d..0fe45d59 100644
--- a/src/theming.py
+++ b/src/theming.py
@@ -114,6 +114,13 @@ class Theme(object):
COLOR_TAB_PRIVATE = (7, 2)
COLOR_TAB_DISCONNECTED = (7, 8)
+ COLOR_VERTICAL_TAB_NORMAL = (4, -1)
+ COLOR_VERTICAL_TAB_CURRENT = (7, 4)
+ COLOR_VERTICAL_TAB_NEW_MESSAGE = (5, -1)
+ COLOR_VERTICAL_TAB_HIGHLIGHT = (1, -1)
+ COLOR_VERTICAL_TAB_PRIVATE = (2, -1)
+ COLOR_VERTICAL_TAB_DISCONNECTED = (8, -1)
+
# Nickname colors
# A list of colors randomly attributed to nicks in MUCs
# Setting more colors makes it harder to have two nicks with the same color,
@@ -151,6 +158,9 @@ class Theme(object):
COLOR_QUIT_CHAR = (1, -1)
COLOR_KICK_CHAR = (1, -1)
+ # Vertical tab list color
+ COLOR_VERTICAL_TAB_NUMBER = (34, -1)
+
# This is the default theme object, used if no theme is defined in the conf
theme = Theme()
diff --git a/src/windows.py b/src/windows.py
index 3e283320..c31954d9 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -55,6 +55,7 @@ def truncate_nick(nick, size=25):
class Win(object):
_win_core = None
+ _tab_win = None
def __init__(self):
self._win = None
@@ -63,14 +64,12 @@ class Win(object):
self.height, self.width = height, width
return
self.height, self.width, self.x, self.y = height, width, x, y
- if not self._win:
- self._win = curses.newwin(height, width, y, x)
- else:
- try:
- self._win.resize(height, width)
- self._win.mvwin(y, x)
- except:
- log.debug('DEBUG: mvwin returned ERR. Please investigate')
+ # try:
+ self._win = Win._tab_win.derwin(height, width, y, x)
+ # except:
+ # log.debug('DEBUG: mvwin returned ERR. Please investigate')
+
+ # If this ever fail, uncomment that ^
def resize(self, height, width, y, x):
"""
@@ -315,6 +314,42 @@ class GlobalInfoBar(Win):
to_curses_attr(get_theme().COLOR_INFORMATION_BAR))
self._refresh()
+class VerticalGlobalInfoBar(Win):
+ def __init__(self, scr):
+ Win.__init__(self)
+ self._win = scr
+
+ def refresh(self):
+ def compare_room(a):
+ return a.nb
+ comp = lambda x: x.nb
+ with g_lock:
+ height, width = self._win.getmaxyx()
+ self._win.erase()
+ sorted_tabs = sorted(self.core.tabs, key=comp)
+ if config.get('show_inactive_tabs', 'true') == 'false':
+ sorted_tabs = [tab for tab in sorted_tabs if\
+ tab.vertical_color != get_theme().COLOR_VERTICAL_TAB_NORMAL]
+ nb_tabs = len(sorted_tabs)
+ if nb_tabs >= height:
+ for y, tab in enumerate(sorted_tabs):
+ if tab.vertical_color == get_theme().COLOR_VERTICAL_TAB_CURRENT:
+ pos = y
+ break
+ # center the current tab as much as possible
+ if pos < height//2:
+ sorted_tabs = sorted_tabs[:height]
+ elif nb_tabs - pos <= height//2:
+ sorted_tabs = sorted_tabs[-height:]
+ else:
+ sorted_tabs = sorted_tabs[pos-height//2 : pos+height//2]
+ for y, tab in enumerate(sorted_tabs):
+ color = tab.vertical_color
+ self.addstr(y, 0, "%2d" % tab.nb, to_curses_attr(get_theme().COLOR_VERTICAL_TAB_NUMBER))
+ self.addstr('.')
+ self._win.addnstr("%s" % tab.get_name(), width - 4, to_curses_attr(color))
+ self._refresh()
+
class InfoWin(Win):
"""
Base class for all the *InfoWin, used in various tabs. For example