Rationalise prompt calling conventions

This commit is contained in:
Aldo Cortesi 2015-03-22 13:59:34 +13:00
parent 3bf4feb213
commit 572000aa03
7 changed files with 46 additions and 52 deletions

View File

@ -203,7 +203,7 @@ def save_data(path, data, master, state):
def ask_save_path(prompt, data, master, state): def ask_save_path(prompt, data, master, state):
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = prompt, prompt = prompt,
text = state.last_saveload, text = state.last_saveload,
callback = save_data, callback = save_data,
@ -260,7 +260,7 @@ def copy_flow(part, scope, flow, master, state):
except RuntimeError: except RuntimeError:
def save(k): def save(k):
if k == "y": if k == "y":
ask_save_path("Save data: ", data, master, state) ask_save_path("Save data", data, master, state)
signals.status_prompt_onekey.send( signals.status_prompt_onekey.send(
prompt = "Cannot copy binary data to clipboard. Save as file?", prompt = "Cannot copy binary data to clipboard. Save as file?",
keys = ( keys = (
@ -316,14 +316,14 @@ def ask_save_body(part, master, state, flow):
elif part == "q" and request_has_content: elif part == "q" and request_has_content:
ask_save_path( ask_save_path(
"Save request content: ", "Save request content",
flow.request.get_decoded_content(), flow.request.get_decoded_content(),
master, master,
state state
) )
elif part == "s" and response_has_content: elif part == "s" and response_has_content:
ask_save_path( ask_save_path(
"Save response content: ", "Save response content",
flow.response.get_decoded_content(), flow.response.get_decoded_content(),
master, master,
state state

View File

@ -111,14 +111,14 @@ class ConnectionItem(urwid.WidgetWrap):
def save_flows_prompt(self, k): def save_flows_prompt(self, k):
if k == "a": if k == "a":
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = "Save all flows to: ", prompt = "Save all flows to",
text = self.state.last_saveload, text = self.state.last_saveload,
callback = self.master.save_flows callback = self.master.save_flows
) )
else: else:
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = "Save this flow to: ", prompt = "Save this flow to",
text = self.state.last_saveload, text = self.state.last_saveload,
callback = self.master.save_one_flow, callback = self.master.save_one_flow,
args = (self.flow,) args = (self.flow,)
@ -150,8 +150,8 @@ class ConnectionItem(urwid.WidgetWrap):
self.master.options.replay_ignore_host self.master.options.replay_ignore_host
) )
else: else:
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = "Server replay path: ", prompt = "Server replay path",
text = self.state.last_saveload, text = self.state.last_saveload,
callback = self.master.server_playback_path callback = self.master.server_playback_path
) )
@ -216,8 +216,8 @@ class ConnectionItem(urwid.WidgetWrap):
if self.flow.request: if self.flow.request:
self.master.view_flow(self.flow) self.master.view_flow(self.flow)
elif key == "|": elif key == "|":
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = "Send flow to script: ", prompt = "Send flow to script",
text = self.state.last_script, text = self.state.last_script,
callback = self.master.run_script_once, callback = self.master.run_script_once,
args = (self.flow,) args = (self.flow,)
@ -269,7 +269,7 @@ class FlowListBox(urwid.ListBox):
if k == "e": if k == "e":
signals.status_prompt.send( signals.status_prompt.send(
self, self,
prompt = "Method:", prompt = "Method",
text = "", text = "",
callback = self.get_method_raw callback = self.get_method_raw
) )
@ -282,7 +282,7 @@ class FlowListBox(urwid.ListBox):
def get_url(self, method): def get_url(self, method):
signals.status_prompt.send( signals.status_prompt.send(
prompt = "URL:", prompt = "URL",
text = "http://www.example.com/", text = "http://www.example.com/",
callback = self.new_request, callback = self.new_request,
args = (method,) args = (method,)
@ -308,14 +308,14 @@ class FlowListBox(urwid.ListBox):
self.master.toggle_eventlog() self.master.toggle_eventlog()
elif key == "l": elif key == "l":
signals.status_prompt.send( signals.status_prompt.send(
prompt = "Limit: ", prompt = "Limit",
text = self.master.state.limit_txt, text = self.master.state.limit_txt,
callback = self.master.set_limit callback = self.master.set_limit
) )
elif key == "L": elif key == "L":
signals.status_path_prompt.send( signals.status_prompt_path.send(
self, self,
prompt = "Load flows: ", prompt = "Load flows",
text = self.master.state.last_saveload, text = self.master.state.last_saveload,
callback = self.master.load_flows_callback callback = self.master.load_flows_callback
) )
@ -331,9 +331,9 @@ class FlowListBox(urwid.ListBox):
if self.master.stream: if self.master.stream:
self.master.stop_stream() self.master.stop_stream()
else: else:
signals.status_path_prompt.send( signals.status_prompt_path.send(
self, self,
prompt = "Stream flows to: ", prompt = "Stream flows to",
text = self.master.state.last_saveload, text = self.master.state.last_saveload,
callback = self.master.start_stream_to_path callback = self.master.start_stream_to_path
) )

View File

@ -493,7 +493,7 @@ class FlowView(urwid.WidgetWrap):
def edit_method(self, m): def edit_method(self, m):
if m == "e": if m == "e":
signals.status_prompt.send( signals.status_prompt.send(
prompt = "Method: ", prompt = "Method",
text = self.flow.request.method, text = self.flow.request.method,
callback = self.set_method_raw callback = self.set_method_raw
) )
@ -592,7 +592,7 @@ class FlowView(urwid.WidgetWrap):
self.master.view_grideditor(grideditor.QueryEditor(self.master, message.get_query().lst, self.set_query, message)) self.master.view_grideditor(grideditor.QueryEditor(self.master, message.get_query().lst, self.set_query, message))
elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST: elif part == "u" and self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
signals.status_prompt.send( signals.status_prompt.send(
prompt = "URL: ", prompt = "URL",
text = message.url, text = message.url,
callback = self.set_url callback = self.set_url
) )
@ -604,13 +604,13 @@ class FlowView(urwid.WidgetWrap):
) )
elif part == "c" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE: elif part == "c" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
signals.status_prompt.send( signals.status_prompt.send(
prompt = "Code: ", prompt = "Code",
text = str(message.code), text = str(message.code),
callback = self.set_resp_code callback = self.set_resp_code
) )
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE: elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
signals.status_prompt.send( signals.status_prompt.send(
prompt = "Message: ", prompt = "Message",
text = message.msg, text = message.msg,
callback = self.set_resp_msg callback = self.set_resp_msg
) )
@ -769,8 +769,8 @@ class FlowView(urwid.WidgetWrap):
self.master.refresh_flow(self.flow) self.master.refresh_flow(self.flow)
signals.status_message.send(message="Reverted.") signals.status_message.send(message="Reverted.")
elif key == "W": elif key == "W":
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = "Save this flow: ", prompt = "Save this flow",
text = self.state.last_saveload, text = self.state.last_saveload,
callback = self.master.save_one_flow, callback = self.master.save_one_flow,
args = (self.flow,) args = (self.flow,)
@ -784,8 +784,8 @@ class FlowView(urwid.WidgetWrap):
else: else:
signals.status_message.send(message="Error! Set $EDITOR or $PAGER.") signals.status_message.send(message="Error! Set $EDITOR or $PAGER.")
elif key == "|": elif key == "|":
signals.status_path_prompt.send( signals.status_prompt_path.send(
prompt = "Send flow to script: ", prompt = "Send flow to script",
text = self.state.last_script, text = self.state.last_script,
callback = self.master.run_script_once, callback = self.master.run_script_once,
args = (self.flow,) args = (self.flow,)
@ -822,7 +822,7 @@ class FlowView(urwid.WidgetWrap):
self.master.refresh_flow(self.flow) self.master.refresh_flow(self.flow)
elif key == "/": elif key == "/":
last_search_string = self.state.get_flow_setting(self.flow, "last_search_string") last_search_string = self.state.get_flow_setting(self.flow, "last_search_string")
search_prompt = "Search body ["+last_search_string+"]: " if last_search_string else "Search body: " search_prompt = "Search body ["+last_search_string+"]" if last_search_string else "Search body"
signals.status_prompt.send( signals.status_prompt.send(
prompt = search_prompt, prompt = search_prompt,
text = "", text = "",

View File

@ -338,17 +338,17 @@ class GridEditor(urwid.WidgetWrap):
self.walker.delete_focus() self.walker.delete_focus()
elif key == "r": elif key == "r":
if self.walker.get_current_value() is not None: if self.walker.get_current_value() is not None:
signals.status_path_prompt.send( signals.status_prompt_path.send(
self, self,
prompt = "Read file: ", prompt = "Read file",
text = "", text = "",
callback = self.read_file callback = self.read_file
) )
elif key == "R": elif key == "R":
if self.walker.get_current_value() is not None: if self.walker.get_current_value() is not None:
signals.status_path_prompt.send( signals.status_prompt_path.send(
self, self,
prompt = "Read unescaped file: ", prompt = "Read unescaped file",
text = "", text = "",
callback = self.read_file, callback = self.read_file,
args = (True,) args = (True,)

View File

@ -7,7 +7,7 @@ status_message = blinker.Signal()
status_prompt = blinker.Signal() status_prompt = blinker.Signal()
# Prompt for a path # Prompt for a path
status_path_prompt = blinker.Signal() status_prompt_path = blinker.Signal()
# Prompt for a single keystroke # Prompt for a single keystroke
status_prompt_onekey = blinker.Signal() status_prompt_onekey = blinker.Signal()

View File

@ -12,7 +12,7 @@ class ActionBar(urwid.WidgetWrap):
self.clear() self.clear()
signals.status_message.connect(self.sig_message) signals.status_message.connect(self.sig_message)
signals.status_prompt.connect(self.sig_prompt) signals.status_prompt.connect(self.sig_prompt)
signals.status_path_prompt.connect(self.sig_path_prompt) signals.status_prompt_path.connect(self.sig_path_prompt)
signals.status_prompt_onekey.connect(self.sig_prompt_onekey) signals.status_prompt_onekey.connect(self.sig_prompt_onekey)
self.prompting = False self.prompting = False
@ -27,14 +27,17 @@ class ActionBar(urwid.WidgetWrap):
self.clear() self.clear()
signals.call_in.send(seconds=expire, callback=cb) signals.call_in.send(seconds=expire, callback=cb)
def prep_prompt(self, p):
return p.strip() + ": "
def sig_prompt(self, sender, prompt, text, callback, args=()): def sig_prompt(self, sender, prompt, text, callback, args=()):
signals.focus.send(self, section="footer") signals.focus.send(self, section="footer")
self._w = urwid.Edit(prompt, text or "") self._w = urwid.Edit(self.prep_prompt(prompt), text or "")
self.prompting = (callback, args) self.prompting = (callback, args)
def sig_path_prompt(self, sender, prompt, text, callback, args=()): def sig_path_prompt(self, sender, prompt, text, callback, args=()):
signals.focus.send(self, section="footer") signals.focus.send(self, section="footer")
self._w = pathedit.PathEdit(prompt, text) self._w = pathedit.PathEdit(self.prep_prompt(prompt), text)
self.prompting = (callback, args) self.prompting = (callback, args)
def sig_prompt_onekey(self, sender, prompt, keys, callback, args=()): def sig_prompt_onekey(self, sender, prompt, keys, callback, args=()):
@ -230,12 +233,3 @@ class StatusBar(urwid.WidgetWrap):
def selectable(self): def selectable(self):
return True return True
def get_edit_text(self):
return self.ab._w.get_edit_text()
def path_prompt(self, prompt, text):
return self.ab.path_prompt(prompt, text)
def prompt(self, prompt, text = ""):
self.ab.prompt(prompt, text)

View File

@ -16,9 +16,9 @@ class Window(urwid.Frame):
self.master.view_help() self.master.view_help()
elif k == "c": elif k == "c":
if not self.master.client_playback: if not self.master.client_playback:
signals.status_path_prompt.send( signals.status_prompt_path.send(
self, self,
prompt = "Client replay: ", prompt = "Client replay",
text = self.master.state.last_saveload, text = self.master.state.last_saveload,
callback = self.master.client_playback_path callback = self.master.client_playback_path
) )
@ -59,7 +59,7 @@ class Window(urwid.Frame):
elif k == "i": elif k == "i":
signals.status_prompt.send( signals.status_prompt.send(
self, self,
prompt = "Intercept filter: ", prompt = "Intercept filter",
text = self.master.state.intercept_txt, text = self.master.state.intercept_txt,
callback = self.master.set_intercept callback = self.master.set_intercept
) )
@ -99,9 +99,9 @@ class Window(urwid.Frame):
) )
elif k == "S": elif k == "S":
if not self.master.server_playback: if not self.master.server_playback:
signals.status_path_prompt.send( signals.status_prompt_path.send(
self, self,
prompt = "Server replay path: ", prompt = "Server replay path",
text = self.master.state.last_saveload, text = self.master.state.last_saveload,
callback = self.master.server_playback_path callback = self.master.server_playback_path
) )
@ -130,13 +130,13 @@ class Window(urwid.Frame):
) )
elif k == "t": elif k == "t":
signals.status_prompt.send( signals.status_prompt.send(
prompt = "Sticky cookie filter: ", prompt = "Sticky cookie filter",
text = self.master.stickycookie_txt, text = self.master.stickycookie_txt,
callback = self.master.set_stickycookie callback = self.master.set_stickycookie
) )
elif k == "u": elif k == "u":
signals.status_prompt.send( signals.status_prompt.send(
prompt = "Sticky auth filter: ", prompt = "Sticky auth filter",
text = self.master.stickyauth_txt, text = self.master.stickyauth_txt,
callback = self.master.set_stickyauth callback = self.master.set_stickyauth
) )