More work on pretty view forcing.

- Make this setting apply only to the currently viewed flow. I think it's more
likely that this is the behaviour the user will want, rather than globally
setting the pretty type.
- Update help.
This commit is contained in:
Aldo Cortesi 2012-03-20 11:11:53 +13:00
parent 2153835545
commit 1441fade90
2 changed files with 23 additions and 23 deletions

View File

@ -232,7 +232,6 @@ class ConsoleState(flow.State):
flow.State.__init__(self) flow.State.__init__(self)
self.focus = None self.focus = None
self.view_body_mode = common.VIEW_BODY_PRETTY self.view_body_mode = common.VIEW_BODY_PRETTY
self.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_AUTO
self.view_flow_mode = common.VIEW_FLOW_REQUEST self.view_flow_mode = common.VIEW_FLOW_REQUEST
self.last_script = "" self.last_script = ""
self.last_saveload = "" self.last_saveload = ""
@ -571,8 +570,8 @@ class ConsoleMaster(flow.FlowMaster):
self.help_context = flowlist.help_context self.help_context = flowlist.help_context
def view_flow(self, flow): def view_flow(self, flow):
self.body = flowview.ConnectionView(self, self.state, flow) self.body = flowview.FlowView(self, self.state, flow)
self.header = flowview.ConnectionViewHeader(self, flow) self.header = flowview.FlowViewHeader(self, flow)
self.statusbar = StatusBar(self, self.footer_text_flowview) self.statusbar = StatusBar(self, self.footer_text_flowview)
self.currentflow = flow self.currentflow = flow
@ -698,17 +697,6 @@ class ConsoleMaster(flow.FlowMaster):
self.state.view_body_mode = common.VIEW_BODY_PRETTY self.state.view_body_mode = common.VIEW_BODY_PRETTY
self.refresh_flow(self.currentflow) self.refresh_flow(self.currentflow)
def change_pretty_type(self, t):
if t == "a":
self.state.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_AUTO
elif t == "j":
self.state.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_JSON
elif t == "u":
self.state.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_URLENCODED
elif t == "x":
self.state.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_XML
self.refresh_flow(self.currentflow)
def drawscreen(self): def drawscreen(self):
size = self.ui.get_cols_rows() size = self.ui.get_cols_rows()
canvas = self.view.render(size, focus=1) canvas = self.view.render(size, focus=1)

View File

@ -47,14 +47,14 @@ def _mkhelp():
common.highlight_key("automatic", "a") + common.highlight_key("automatic", "a") +
[("text", ": automatic detection")] [("text", ": automatic detection")]
), ),
(None,
common.highlight_key("html", "h") +
[("text", ": format as HTML")]
),
(None, (None,
common.highlight_key("json", "j") + common.highlight_key("json", "j") +
[("text", ": format as JSON")] [("text", ": format as JSON")]
), ),
(None,
common.highlight_key("urlencoded", "u") +
[("text", ": format as URL-encoded data")]
),
(None, (None,
common.highlight_key("xml", "x") + common.highlight_key("xml", "x") +
[("text", ": format as XML")] [("text", ": format as XML")]
@ -75,7 +75,7 @@ help_context = _mkhelp()
VIEW_CUTOFF = 1024*100 VIEW_CUTOFF = 1024*100
class ConnectionViewHeader(common.WWrap): class FlowViewHeader(common.WWrap):
def __init__(self, master, f): def __init__(self, master, f):
self.master, self.flow = master, f self.master, self.flow = master, f
self.w = common.format_flow(f, False, extended=True, padding=0) self.w = common.format_flow(f, False, extended=True, padding=0)
@ -92,7 +92,7 @@ class CallbackCache:
cache = CallbackCache() cache = CallbackCache()
class ConnectionView(common.WWrap): class FlowView(common.WWrap):
REQ = 0 REQ = 0
RESP = 1 RESP = 1
method_options = [ method_options = [
@ -107,6 +107,7 @@ class ConnectionView(common.WWrap):
] ]
def __init__(self, master, state, flow): def __init__(self, master, state, flow):
self.master, self.state, self.flow = master, state, flow self.master, self.state, self.flow = master, state, flow
self.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_AUTO
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and flow.response: if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and flow.response:
self.view_response() self.view_response()
else: else:
@ -327,7 +328,7 @@ class ConnectionView(common.WWrap):
body = self._conn_text( body = self._conn_text(
self.flow.request, self.flow.request,
self.state.view_body_mode, self.state.view_body_mode,
self.state.view_body_pretty_type self.view_body_pretty_type
) )
self.w = self.wrap_body(common.VIEW_FLOW_REQUEST, body) self.w = self.wrap_body(common.VIEW_FLOW_REQUEST, body)
self.master.statusbar.redraw() self.master.statusbar.redraw()
@ -338,7 +339,7 @@ class ConnectionView(common.WWrap):
body = self._conn_text( body = self._conn_text(
self.flow.response, self.flow.response,
self.state.view_body_mode, self.state.view_body_mode,
self.state.view_body_pretty_type self.view_body_pretty_type
) )
else: else:
body = urwid.ListBox( body = urwid.ListBox(
@ -491,6 +492,17 @@ class ConnectionView(common.WWrap):
def view_prev_flow(self, flow): def view_prev_flow(self, flow):
return self._view_nextprev_flow("prev", flow) return self._view_nextprev_flow("prev", flow)
def change_pretty_type(self, t):
if t == "a":
self.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_AUTO
elif t == "j":
self.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_JSON
elif t == "u":
self.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_URLENCODED
elif t == "x":
self.view_body_pretty_type = common.VIEW_BODY_PRETTY_TYPE_XML
self.master.refresh_flow(self.flow)
def keypress(self, size, key): def keypress(self, size, key):
if key == " ": if key == " ":
self.view_next_flow(self.flow) self.view_next_flow(self.flow)
@ -587,7 +599,7 @@ class ConnectionView(common.WWrap):
("urlencoded", "u"), ("urlencoded", "u"),
("xmlish", "x"), ("xmlish", "x"),
), ),
self.master.change_pretty_type self.change_pretty_type
) )
key = None key = None
elif key == "V": elif key == "V":