Move to context-dependent help model.

The all-in-one page was just getting too unwieldy.
This commit is contained in:
Aldo Cortesi 2012-02-08 21:47:39 +13:00
parent 76f2595df7
commit e3f28e1c06
5 changed files with 81 additions and 38 deletions

View File

@ -523,9 +523,11 @@ class ConsoleMaster(flow.FlowMaster):
self.statusbar = None
self.header = None
self.body = None
self.help_context = None
self.prompting = False
self.onekey = False
self.view_connlist()
if self.server:
@ -545,6 +547,15 @@ class ConsoleMaster(flow.FlowMaster):
sys.stderr.flush()
self.shutdown()
def focus_current(self):
if self.currentflow:
try:
ids = [id(i) for i in self.state.view]
idx = ids.index(id(self.currentflow))
self.conn_list_view.set_focus(idx)
except (IndexError, ValueError):
pass
def make_view(self):
self.view = urwid.Frame(
self.body,
@ -554,8 +565,10 @@ class ConsoleMaster(flow.FlowMaster):
self.view.set_focus("body")
def view_help(self):
h = help.HelpView(self, self.help_context, (self.statusbar, self.body, self.header))
self.statusbar = StatusBar(self, self.footer_text_help)
self.body = help.HelpView(self)
self.body = h
self.header = None
self.make_view()
@ -563,16 +576,9 @@ class ConsoleMaster(flow.FlowMaster):
self.statusbar = StatusBar(self, "foo")
self.body = kveditor.KVEditor(self, title, value, callback, *args, **kwargs)
self.header = None
self.make_view()
def focus_current(self):
if self.currentflow:
try:
ids = [id(i) for i in self.state.view]
idx = ids.index(id(self.currentflow))
self.conn_list_view.set_focus(idx)
except (IndexError, ValueError):
pass
self.help_context = kveditor.help_context
self.make_view()
def view_connlist(self):
if self.ui.started:
@ -585,14 +591,18 @@ class ConsoleMaster(flow.FlowMaster):
self.statusbar = StatusBar(self, self.footer_text_default)
self.header = None
self.currentflow = None
self.make_view()
self.help_context = connlist.help_context
def view_flow(self, flow):
self.statusbar = StatusBar(self, self.footer_text_connview)
self.body = connview.ConnectionView(self, self.state, flow)
self.header = connview.ConnectionViewHeader(self, flow)
self.currentflow = flow
self.make_view()
self.help_context = connview.help_context
def _write_flows(self, path, flows):
self.state.last_saveload = path

View File

@ -1,6 +1,21 @@
import urwid
import common
def _mkhelp():
text = []
keys = [
("C", "clear connection list or eventlog"),
("d", "delete connection from view"),
("v", "toggle eventlog"),
("X", "kill and delete connection, even if it's mid-intercept"),
("tab", "tab between eventlog and connection list"),
("enter", "view connection"),
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
return text
help_context = _mkhelp()
class EventListBox(urwid.ListBox):
def __init__(self, master):
self.master = master

View File

@ -2,6 +2,22 @@ import urwid
import common
from .. import utils, encoding, flow
def _mkhelp():
text = []
keys = [
("b", "save request/response body"),
("e", "edit request/response"),
("p", "previous flow"),
("v", "view body in external viewer"),
("z", "encode/decode a request/response"),
("tab", "toggle request/response view"),
("space", "next flow"),
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
return text
help_context = _mkhelp()
VIEW_CUTOFF = 1024*100
class ConnectionViewHeader(common.WWrap):

View File

@ -3,8 +3,9 @@ import common
from .. import filt
class HelpView(urwid.ListBox):
def __init__(self, master):
self.master = master
def __init__(self, master, help_context, state):
self.master, self.state = master, state
self.help_context = help_context or []
urwid.ListBox.__init__(
self,
self.helptext()
@ -13,13 +14,19 @@ class HelpView(urwid.ListBox):
def keypress(self, size, key):
key = common.shortcuts(key)
if key == "q":
self.master.pop_view()
self.master.statusbar = self.state[0]
self.master.body = self.state[1]
self.master.header = self.state[2]
self.master.make_view()
return None
return urwid.ListBox.keypress(self, size, key)
def helptext(self):
text = []
text.append(("head", "Global keys:\n"))
text.append(("head", "Keys for this view:\n"))
text.extend(self.help_context)
text.append(("head", "\n\nGlobal keys:\n"))
keys = [
("A", "accept all intercepted connections"),
("a", "accept this intercepted connection"),
@ -77,29 +84,6 @@ class HelpView(urwid.ListBox):
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
text.append(("head", "\n\nConnection list keys:\n"))
keys = [
("C", "clear connection list or eventlog"),
("d", "delete connection from view"),
("v", "toggle eventlog"),
("X", "kill and delete connection, even if it's mid-intercept"),
("tab", "tab between eventlog and connection list"),
("enter", "view connection"),
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
text.append(("head", "\n\nConnection view keys:\n"))
keys = [
("b", "save request/response body"),
("e", "edit request/response"),
("p", "previous flow"),
("v", "view body in external viewer"),
("z", "encode/decode a request/response"),
("tab", "toggle request/response view"),
("space", "next flow"),
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
text.append(("head", "\n\nFilter expressions:\n"))
f = []
for i in filt.filt_unary:

View File

@ -3,6 +3,24 @@ import urwid
import common
from .. import utils
def _mkhelp():
text = []
keys = [
("a", "add row after cursor"),
("d", "delete row"),
("e", "spawn external editor on current field"),
("i", "insert row before cursor"),
("q", "return to flow view"),
("esc", "return to flow view/exit field edit mode"),
("tab", "next field"),
("enter", "edit field"),
]
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
return text
help_context = _mkhelp()
class SText(common.WWrap):
def __init__(self, txt, focused):
w = urwid.Text(txt, wrap="any")
@ -208,7 +226,7 @@ class KVEditor(common.WWrap):
n = utils.clean_hanging_newline(n)
self.walker.set_current_value(n)
self.walker._modified()
elif key in ["enter", "e"]:
elif key in ["enter"]:
self.walker.start_edit()
else:
return self.w.keypress(size, key)