Fix out-of-bounds crashes and added help text for thread searching.

themes
desvox 2018-07-27 18:30:46 -05:00
parent 22b4a5d5a5
commit 6d0d10b9a7
1 changed files with 20 additions and 8 deletions

View File

@ -216,7 +216,7 @@ default_prefs = {
bars = { bars = {
"index": "[RET]Open [/]Search [C]ompose [R]efresh [O]ptions [?]Help [Q]uit", "index": "[RET]Open [/]Search [C]ompose [R]efresh [O]ptions [?]Help [Q]uit",
"thread": "[Q]Back [RET]Menu [C]ompose [^R]eply [R]efresh [0-9]Goto [B/T]End [</>]Jump[X]%d" "thread": "[Q]Back [RET]Menu [C]ompose [^R]eply [R]efresh [0-9]Goto [B/T]End [</>]Jump[X]%d [/]Search"
} }
colormap = [ colormap = [
@ -310,7 +310,12 @@ class App(object):
Sets the footer to display `string`, applying bar formatting. Sets the footer to display `string`, applying bar formatting.
Other than setting the color, `string` is shown verbatim. Other than setting the color, `string` is shown verbatim.
""" """
self.loop.widget.footer = urwid.AttrMap(urwid.Text(string), "bar") widget = urwid.AttrMap(urwid.Text(string), "bar")
self.loop.widget.footer = widget
# TODO: make this set the title line when the window is split
# if self.window_split:
# self.loop.widget.footer[0].set_text(widget)
# else:
def set_default_header(self): def set_default_header(self):
@ -333,6 +338,8 @@ class App(object):
elif self.mode == "thread": elif self.mode == "thread":
footer = bars["thread"] % self.prefs["jump_count"] footer = bars["thread"] % self.prefs["jump_count"]
if self.match_data["matches"]:
footer += " [@#] Search Control"
else: else:
footer = bars["index"] footer = bars["index"]
@ -755,13 +762,12 @@ class App(object):
def search_thread_callback(self, query): def search_thread_callback(self, query):
# TODO: Not that!! # normally i would just use self.thread["messages"] but I need the visbile text post-formatted
# fetch the thread again because we need all the messages without formatting
thread, _ = network.thread_load(self.thread["thread_id"])
query = query.lower().strip() query = query.lower().strip()
self.match_data["matches"] = [ self.match_data["matches"] = [
message for message in thread["messages"] self.thread["messages"][widget.base_widget.post_id] for widget in self.walker
if query in message["body"].lower().strip() if isinstance(widget.base_widget, MessageBody)
and query in widget.base_widget.text.lower().strip()
] ]
if self.match_data["matches"]: if self.match_data["matches"]:
self.match_data["query"] = query self.match_data["query"] = query
@ -773,6 +779,8 @@ class App(object):
def do_search_result(self, forward=True): def do_search_result(self, forward=True):
if not self.match_data["matches"]:
return
self.match_data["position"] += 1 if forward else -1 self.match_data["position"] += 1 if forward else -1
length = len(self.match_data["matches"]) length = len(self.match_data["matches"])
if forward: if forward:
@ -1425,6 +1433,9 @@ class App(object):
def temp_footer_message(self, string, duration=3): def temp_footer_message(self, string, duration=3):
self.loop.remove_alarm(self.last_alarm) self.loop.remove_alarm(self.last_alarm)
self.last_alarm = self.loop.set_alarm_in(duration, self.reset_footer) self.last_alarm = self.loop.set_alarm_in(duration, self.reset_footer)
if self.window_split:
pass
else:
self.set_footer(string) self.set_footer(string)
@ -1544,6 +1555,7 @@ class MessageBody(urwid.Text):
if message["send_raw"]: if message["send_raw"]:
return super(MessageBody, self).__init__(message["body"]) return super(MessageBody, self).__init__(message["body"])
self.post_id = message["post_id"]
text_objects = message["body"] text_objects = message["body"]
result = [] result = []
last_directive = None last_directive = None