summaryrefslogtreecommitdiff
path: root/src/windows.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-05-17 01:00:35 +0200
committermathieui <mathieui@mathieui.net>2012-05-17 01:00:35 +0200
commit0f7bda20b8b89bf334d67da45f4fc3e4dc8117f9 (patch)
tree7ed6d0e0b6b80544ff40eeb57daad0d7d8c0eac1 /src/windows.py
parentda30c8c79f5950ef85296ba8f749b929b1bbbd57 (diff)
downloadpoezio-0f7bda20b8b89bf334d67da45f4fc3e4dc8117f9.tar.gz
poezio-0f7bda20b8b89bf334d67da45f4fc3e4dc8117f9.tar.bz2
poezio-0f7bda20b8b89bf334d67da45f4fc3e4dc8117f9.tar.xz
poezio-0f7bda20b8b89bf334d67da45f4fc3e4dc8117f9.zip
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.
Diffstat (limited to 'src/windows.py')
-rw-r--r--src/windows.py81
1 files changed, 77 insertions, 4 deletions
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)