Skip to content

Commit

Permalink
Handle views that don't support search gracefully
Browse files Browse the repository at this point in the history
This includes all key/value formatted views, e.g. the image view. We
need to support these ultimately, but no time before the next release.
  • Loading branch information
cortesi committed Jan 19, 2014
1 parent f5f46bf commit bf1399f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libmproxy/console/flowview.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import common, grideditor, contentview
from .. import utils, flow, controller


class SearchError(Exception): pass


def _mkhelp():
text = []
keys = [
Expand Down Expand Up @@ -296,7 +300,10 @@ def search(self, search_string):

# generate the body, highlight the words and get focus
headers, msg, body = self.conn_text_raw(text)
body, focus_position = self.search_highlight_text(body, search_string)
try:
body, focus_position = self.search_highlight_text(body, search_string)
except SearchError:
return "Search not supported in this view."

if focus_position == None:
# no results found.
Expand Down Expand Up @@ -347,8 +354,10 @@ def search_highlight_text(self, text_objects, search_string, looping = False):
if i != start_line:
start_index = 0

text, style = text_object.get_text()

try:
text, style = text_object.get_text()
except AttributeError:
raise SearchError()
find_index = text.find(search_string, start_index)
if find_index != -1:
before = text[:find_index]
Expand Down

0 comments on commit bf1399f

Please sign in to comment.