summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/en/keys.txt4
-rw-r--r--src/tabs.py20
-rw-r--r--src/text_buffer.py4
-rw-r--r--src/windows.py81
4 files changed, 102 insertions, 7 deletions
diff --git a/doc/en/keys.txt b/doc/en/keys.txt
index c1b9b7fd..07fd7d17 100644
--- a/doc/en/keys.txt
+++ b/doc/en/keys.txt
@@ -105,6 +105,10 @@ These keys work only in the MultiUserChat tab.
*Alt-y*:: Scroll the user list up.
+*Alt-p*:: Scroll to the previous highlight.
+
+*Alt-n*:: Scroll to the next highlight.
+
*tabulation*:: Complete a nick.
*Ctrl-c*:: Insert xhtml formatting. You have to press Ctrl-c then a character
diff --git a/src/tabs.py b/src/tabs.py
index 39b81df7..f97c7f03 100644
--- a/src/tabs.py
+++ b/src/tabs.py
@@ -600,6 +600,8 @@ class MucTab(ChatTab):
self.key_func['^I'] = self.completion
self.key_func['M-u'] = self.scroll_user_list_down
self.key_func['M-y'] = self.scroll_user_list_up
+ self.key_func['M-n'] = self.go_to_next_hl
+ self.key_func['M-p'] = self.go_to_prev_hl
# commands
self.commands['ignore'] = (self.command_ignore, _("Usage: /ignore <nickname> \nIgnore: Ignore a specified nickname."), self.completion_ignore)
self.commands['unignore'] = (self.command_unignore, _("Usage: /unignore <nickname>\nUnignore: Remove the specified nickname from the ignore list."), self.completion_unignore)
@@ -630,6 +632,22 @@ class MucTab(ChatTab):
def general_jid(self):
return self.get_name()
+ def go_to_next_hl(self):
+ """
+ Go to the next HL in the room, or the last
+ """
+ self.text_win.next_highlight()
+ self.refresh()
+ self.core.doupdate()
+
+ def go_to_prev_hl(self):
+ """
+ Go to the previous HL in the room, or the first
+ """
+ self.text_win.previous_highlight()
+ self.refresh()
+ self.core.doupdate()
+
def completion_version(self, the_input):
"""Completion for /version"""
compare_users = lambda x: x.last_talked
@@ -1502,7 +1520,7 @@ class MucTab(ChatTab):
if highlight:
nick_color = highlight
time = time or datetime.now()
- self._text_buffer.add_message(txt, time, nickname, nick_color, history, user)
+ self._text_buffer.add_message(txt, time, nickname, nick_color, history, user, highlight=highlight)
return highlight
class PrivateTab(ChatTab):
diff --git a/src/text_buffer.py b/src/text_buffer.py
index 9b717882..2d83ab7e 100644
--- a/src/text_buffer.py
+++ b/src/text_buffer.py
@@ -35,7 +35,7 @@ class TextBuffer(object):
def add_window(self, win):
self.windows.append(win)
- def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None):
+ def add_message(self, txt, time=None, nickname=None, nick_color=None, history=None, user=None, highlight=False):
time = time or datetime.now()
if txt.startswith('/me '):
if nick_color:
@@ -57,7 +57,7 @@ class TextBuffer(object):
ret_val = None
for window in self.windows: # make the associated windows
# build the lines from the new message
- nb = window.build_new_message(msg, history=history)
+ nb = window.build_new_message(msg, history=history, highlight=highlight)
if ret_val is None:
ret_val = nb
if window.pos != 0:
diff --git a/src/windows.py b/src/windows.py
index 7185346e..ae79fb74 100644
--- a/src/windows.py
+++ b/src/windows.py
@@ -622,6 +622,8 @@ class TextWin(Win):
# on resize, we rebuild all the messages
self.lock = False
self.lock_buffer = []
+ self.highlights = []
+ self.hl_pos = -1
def toggle_lock(self):
if self.lock:
@@ -637,6 +639,74 @@ class TextWin(Win):
self.built_lines.append(line)
self.lock = False
+ def next_highlight(self):
+ """
+ Go to the next highlight in the buffer.
+ (depending on which highlight was selected before)
+ if the buffer is already positionned on the last, of if there are no
+ highlights, scroll to the end of the buffer.
+ """
+ log.debug('Going to the next highlight…')
+ if not self.highlights or self.hl_pos == -1 or \
+ self.hl_pos == len(self.highlights)-1:
+ self.hl_pos = -1
+ self.pos = 0
+ return
+ hl_size = len(self.highlights) - 1
+ if self.hl_pos < hl_size:
+ self.hl_pos += 1
+ else:
+ self.hl_pos = hl_size
+
+ hl = self.highlights[self.hl_pos]
+ pos = None
+ while not pos:
+ try:
+ pos = self.built_lines.index(hl)
+ except ValueError:
+ self.highlights = self.highlights[self.hl_pos+1:]
+ if not self.highlights:
+ self.hl_pos = -1
+ self.pos = 0
+ return
+ hl = self.highlights[0]
+ self.pos = len(self.built_lines) - pos - self.height
+ if self.pos < 0 or self.pos >= len(self.built_lines):
+ self.pos = 0
+
+ def previous_highlight(self):
+ """
+ Go to the previous highlight in the buffer.
+ (depending on which highlight was selected before)
+ if the buffer is already positionned on the first, or if there are no
+ highlights, scroll to the end of the buffer.
+ """
+ log.debug('Going to the previous highlight…')
+ if not self.highlights or self.hl_pos == 0:
+ self.hl_pos = -1
+ self.pos = 0
+ return
+ if self.hl_pos < 0:
+ self.hl_pos = len(self.highlights) - 1
+ elif self.hl_pos > 0:
+ self.hl_pos -= 1
+
+ hl = self.highlights[self.hl_pos]
+ pos = None
+ while not pos:
+ try:
+ pos = self.built_lines.index(hl)
+ except ValueError:
+ self.highlights = self.highlights[self.hl_pos+1:]
+ if not self.highlights:
+ self.hl_pos = -1
+ self.pos = 0
+ return
+ hl = self.highlights[0]
+ self.pos = len(self.built_lines) - pos - self.height
+ if self.pos < 0 or self.pos >= len(self.built_lines):
+ self.pos = 0
+
def scroll_up(self, dist=14):
self.pos += dist
if self.pos + self.height > len(self.built_lines):
@@ -676,7 +746,7 @@ class TextWin(Win):
if None not in self.built_lines:
self.built_lines.append(None)
- def build_new_message(self, message, history=None, clean=True):
+ def build_new_message(self, message, history=None, clean=True, highlight=False):
"""
Take one message, build it and add it to the list
Return the number of lines that are built for the given
@@ -703,10 +773,13 @@ class TextWin(Win):
start_pos=line[0],
end_pos=line[1]))
else:
+
for line in lines:
- self.built_lines.append(Line(msg=message,
- start_pos=line[0],
- end_pos=line[1]))
+ saved_line = Line(msg=message,start_pos=line[0],end_pos=line[1])
+ self.built_lines.append(saved_line)
+ if highlight:
+ highlight = False
+ self.highlights.append(saved_line)
if clean:
while len(self.built_lines) > self.lines_nb_limit:
self.built_lines.pop(0)