From 0f7bda20b8b89bf334d67da45f4fc3e4dc8117f9 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 17 May 2012 01:00:35 +0200 Subject: Add a way to review room highlights - Fixes #1673 This new features is available with M-p and M-n (previous/next). It saves the last highlight viewed, meaning that if you scroll in the buffer, M-n or M-p will take you to the next or previous hl compared to the one before you started scrolling. For convenience, going to the previous highlight of the first highlight will take you to the bottom of the buffer, and going to the next highlight of the last highlight will do *the same*. If there are several highlights in one message, only the first line will be considered a highlight. --- src/windows.py | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 77 insertions(+), 4 deletions(-) (limited to 'src/windows.py') 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) -- cgit v1.2.3 From 4c0a3fb5a2eca27133e558fa8394b3d07d0203ba Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 17 May 2012 03:34:04 +0200 Subject: Resolves separator persistence problems - Fixes #2073 Now we have to pass the textbuffer object when we want to add a line separator. --- src/windows.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index ae79fb74..ea2cb3f7 100644 --- a/src/windows.py +++ b/src/windows.py @@ -620,11 +620,17 @@ class TextWin(Win): self.pos = 0 self.built_lines = [] # Each new message is built and kept here. # on resize, we rebuild all the messages + self.lock = False self.lock_buffer = [] + + # the Lines of the highlights in that buffer self.highlights = [] + # the current HL position in that list self.hl_pos = -1 + self.separator_after = None + def toggle_lock(self): if self.lock: self.release_lock() @@ -738,13 +744,18 @@ class TextWin(Win): log.debug('remove_line_separator') if None in self.built_lines: self.built_lines.remove(None) + self.separator_after = None - def add_line_separator(self): + def add_line_separator(self, room=None): """ add a line separator at the end of messages list + room is a textbuffer that is needed to get the previous message + (in case of resize) """ if None not in self.built_lines: self.built_lines.append(None) + if room: + self.separator_after = room.messages[-1] def build_new_message(self, message, history=None, clean=True, highlight=False): """ @@ -862,6 +873,8 @@ class TextWin(Win): self.built_lines = [] for message in room.messages: self.build_new_message(message, clean=False) + if self.separator_after is message: + self.build_new_message(None) while len(self.built_lines) > self.lines_nb_limit: self.built_lines.pop(0) -- cgit v1.2.3 From 65062754e194e2c1fadf4a30677444730e73ec71 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 17 May 2012 14:11:02 +0200 Subject: Fix a crash if there are no messages in the room --- src/windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index ea2cb3f7..e5973ec9 100644 --- a/src/windows.py +++ b/src/windows.py @@ -754,7 +754,7 @@ class TextWin(Win): """ if None not in self.built_lines: self.built_lines.append(None) - if room: + if room and room.messages: self.separator_after = room.messages[-1] def build_new_message(self, message, history=None, clean=True, highlight=False): -- cgit v1.2.3 From 3411d8ca83591adf9a92b3c1c78fbd74a4612fe7 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 17 May 2012 17:15:15 +0200 Subject: Add a shortcut to go to the first unread message (separator) with M-p --- src/windows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index e5973ec9..29bf5953 100644 --- a/src/windows.py +++ b/src/windows.py @@ -731,11 +731,11 @@ class TextWin(Win): present, scroll at the top of the window """ if None in self.built_lines: - self.pos = self.built_lines.index(None) + self.pos = len(self.built_lines) - self.built_lines.index(None) - self.height + 1 + if self.pos < 0: + self.pos = 0 # Chose a proper position (not too high) self.scroll_up(0) - else: # Go at the top of the win - self.pos = len(self.built_lines) - self.height def remove_line_separator(self): """ -- cgit v1.2.3 From c77e2878b891f000ba1c3a030acd0c195c7e1948 Mon Sep 17 00:00:00 2001 From: mathieui Date: Thu, 17 May 2012 20:48:46 +0200 Subject: =?UTF-8?q?Do=20not=20add=20a=20'=E2=80=A6'=20if=20the=20nick=20ha?= =?UTF-8?q?s=20the=20exact=20same=20size=20as=20the=20limit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/windows.py') diff --git a/src/windows.py b/src/windows.py index 29bf5953..06214abb 100644 --- a/src/windows.py +++ b/src/windows.py @@ -51,7 +51,7 @@ def truncate_nick(nick, size=None): size = size or config.get('max_nick_length', 25) if size < 1: size = 1 - if nick and len(nick) >= size: + if nick and len(nick) > size: return nick[:size]+'…' return nick -- cgit v1.2.3