mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
console: pull primary window frame management out into window.py
This commit is contained in:
parent
2f8ebfdce2
commit
c182133d64
@ -15,7 +15,7 @@ import urwid
|
||||
import weakref
|
||||
|
||||
from .. import controller, flow, script
|
||||
from . import flowlist, flowview, help, common
|
||||
from . import flowlist, flowview, help, common, window
|
||||
from . import grideditor, palettes, contentview, flowdetailview, statusbar
|
||||
|
||||
EVENTLOG_SIZE = 500
|
||||
@ -146,7 +146,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
|
||||
def __init__(self, server, options):
|
||||
flow.FlowMaster.__init__(self, server, ConsoleState())
|
||||
self.looptime = 0
|
||||
self.stream_path = None
|
||||
self.options = options
|
||||
|
||||
@ -363,149 +362,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
def set_palette(self, name):
|
||||
self.palette = palettes.palettes[name]
|
||||
|
||||
def input_filter(self, keys, raw):
|
||||
for k in keys:
|
||||
if self.prompting:
|
||||
if k == "esc":
|
||||
self.prompt_cancel()
|
||||
elif self.onekey:
|
||||
if k == "enter":
|
||||
self.prompt_cancel()
|
||||
elif k in self.onekey:
|
||||
self.prompt_execute(k)
|
||||
elif k == "enter":
|
||||
self.prompt_execute()
|
||||
else:
|
||||
if common.is_keypress(k):
|
||||
self.view.keypress(self.loop.screen_size, k)
|
||||
else:
|
||||
k = self.view.keypress(self.loop.screen_size, k)
|
||||
if k:
|
||||
self.statusbar.message("")
|
||||
if k == "?":
|
||||
self.view_help()
|
||||
elif k == "c":
|
||||
if not self.client_playback:
|
||||
self.path_prompt(
|
||||
"Client replay: ",
|
||||
self.state.last_saveload,
|
||||
self.client_playback_path
|
||||
)
|
||||
else:
|
||||
self.prompt_onekey(
|
||||
"Stop current client replay?",
|
||||
(
|
||||
("yes", "y"),
|
||||
("no", "n"),
|
||||
),
|
||||
self.stop_client_playback_prompt,
|
||||
)
|
||||
elif k == "H":
|
||||
self.view_grideditor(
|
||||
grideditor.SetHeadersEditor(
|
||||
self,
|
||||
self.setheaders.get_specs(),
|
||||
self.setheaders.set
|
||||
)
|
||||
)
|
||||
elif k == "I":
|
||||
self.view_grideditor(
|
||||
grideditor.HostPatternEditor(
|
||||
self,
|
||||
[[x] for x in self.get_ignore_filter()],
|
||||
self.edit_ignore_filter
|
||||
)
|
||||
)
|
||||
elif k == "T":
|
||||
self.view_grideditor(
|
||||
grideditor.HostPatternEditor(
|
||||
self,
|
||||
[[x] for x in self.get_tcp_filter()],
|
||||
self.edit_tcp_filter
|
||||
)
|
||||
)
|
||||
elif k == "i":
|
||||
self.prompt(
|
||||
"Intercept filter: ",
|
||||
self.state.intercept_txt,
|
||||
self.set_intercept
|
||||
)
|
||||
elif k == "Q":
|
||||
raise urwid.ExitMainLoop
|
||||
elif k == "q":
|
||||
self.prompt_onekey(
|
||||
"Quit",
|
||||
(
|
||||
("yes", "y"),
|
||||
("no", "n"),
|
||||
),
|
||||
self.quit,
|
||||
)
|
||||
elif k == "M":
|
||||
self.prompt_onekey(
|
||||
"Global default display mode",
|
||||
contentview.view_prompts,
|
||||
self.change_default_display_mode
|
||||
)
|
||||
elif k == "R":
|
||||
self.view_grideditor(
|
||||
grideditor.ReplaceEditor(
|
||||
self,
|
||||
self.replacehooks.get_specs(),
|
||||
self.replacehooks.set
|
||||
)
|
||||
)
|
||||
elif k == "s":
|
||||
self.view_grideditor(
|
||||
grideditor.ScriptEditor(
|
||||
self,
|
||||
[[i.command] for i in self.scripts],
|
||||
self.edit_scripts
|
||||
)
|
||||
)
|
||||
elif k == "S":
|
||||
if not self.server_playback:
|
||||
self.path_prompt(
|
||||
"Server replay path: ",
|
||||
self.state.last_saveload,
|
||||
self.server_playback_path
|
||||
)
|
||||
else:
|
||||
self.prompt_onekey(
|
||||
"Stop current server replay?",
|
||||
(
|
||||
("yes", "y"),
|
||||
("no", "n"),
|
||||
),
|
||||
self.stop_server_playback_prompt,
|
||||
)
|
||||
elif k == "o":
|
||||
self.prompt_onekey(
|
||||
"Options",
|
||||
(
|
||||
("anticache", "a"),
|
||||
("anticomp", "c"),
|
||||
("showhost", "h"),
|
||||
("killextra", "k"),
|
||||
("norefresh", "n"),
|
||||
("no-upstream-certs", "u"),
|
||||
),
|
||||
self._change_options
|
||||
)
|
||||
elif k == "t":
|
||||
self.prompt(
|
||||
"Sticky cookie filter: ",
|
||||
self.stickycookie_txt,
|
||||
self.set_stickycookie
|
||||
)
|
||||
elif k == "u":
|
||||
self.prompt(
|
||||
"Sticky auth filter: ",
|
||||
self.stickyauth_txt,
|
||||
self.set_stickyauth
|
||||
)
|
||||
self.statusbar.redraw()
|
||||
|
||||
def ticker(self, *userdata):
|
||||
changed = self.tick(self.masterq, timeout=0)
|
||||
if changed:
|
||||
@ -528,7 +384,6 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.loop = urwid.MainLoop(
|
||||
self.view,
|
||||
screen = self.ui,
|
||||
input_filter = self.input_filter
|
||||
)
|
||||
self.view_flowlist()
|
||||
self.statusbar.redraw()
|
||||
@ -574,12 +429,13 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
self.shutdown()
|
||||
|
||||
def make_view(self):
|
||||
self.view = urwid.Frame(
|
||||
self.view = window.Window(
|
||||
self,
|
||||
self.body,
|
||||
header = self.header,
|
||||
footer = self.statusbar
|
||||
)
|
||||
self.view.set_focus("body")
|
||||
self.statusbar.redraw()
|
||||
return self.view
|
||||
|
||||
def view_help(self):
|
||||
|
@ -34,6 +34,9 @@ class StatusBar(urwid.WidgetWrap):
|
||||
self.ib = urwid.WidgetWrap(urwid.Text(""))
|
||||
self._w = urwid.Pile([self.ib, self.ab])
|
||||
|
||||
def keypress(self, *args, **kwargs):
|
||||
return self.ab.keypress(*args, **kwargs)
|
||||
|
||||
def get_status(self):
|
||||
r = []
|
||||
|
||||
|
150
libmproxy/console/window.py
Normal file
150
libmproxy/console/window.py
Normal file
@ -0,0 +1,150 @@
|
||||
import urwid
|
||||
|
||||
class Window(urwid.Frame):
|
||||
def __init__(self, master, body, header, footer):
|
||||
urwid.Frame.__init__(self, body, header=header, footer=footer)
|
||||
self.master = master
|
||||
|
||||
def keypress(self, size, k):
|
||||
if self.master.prompting:
|
||||
if k == "esc":
|
||||
self.master.prompt_cancel()
|
||||
elif self.master.onekey:
|
||||
if k == "enter":
|
||||
self.master.prompt_cancel()
|
||||
elif k in self.master.onekey:
|
||||
self.master.prompt_execute(k)
|
||||
elif k == "enter":
|
||||
self.master.prompt_execute()
|
||||
else:
|
||||
if common.is_keypress(k):
|
||||
urwid.Frame.keypress(self, self.master.loop.screen_size, k)
|
||||
else:
|
||||
return k
|
||||
else:
|
||||
k = urwid.Frame.keypress(self, self.master.loop.screen_size, k)
|
||||
if k == "?":
|
||||
self.master.view_help()
|
||||
elif k == "c":
|
||||
if not self.master.client_playback:
|
||||
self.master.path_prompt(
|
||||
"Client replay: ",
|
||||
self.master.state.last_saveload,
|
||||
self.master.client_playback_path
|
||||
)
|
||||
else:
|
||||
self.master.prompt_onekey(
|
||||
"Stop current client replay?",
|
||||
(
|
||||
("yes", "y"),
|
||||
("no", "n"),
|
||||
),
|
||||
self.master.stop_client_playback_prompt,
|
||||
)
|
||||
elif k == "H":
|
||||
self.master.view_grideditor(
|
||||
grideditor.SetHeadersEditor(
|
||||
self.master,
|
||||
self.master.setheaders.get_specs(),
|
||||
self.master.setheaders.set
|
||||
)
|
||||
)
|
||||
elif k == "I":
|
||||
self.master.view_grideditor(
|
||||
grideditor.HostPatternEditor(
|
||||
self.master,
|
||||
[[x] for x in self.master.get_ignore_filter()],
|
||||
self.master.edit_ignore_filter
|
||||
)
|
||||
)
|
||||
elif k == "T":
|
||||
self.master.view_grideditor(
|
||||
grideditor.HostPatternEditor(
|
||||
self.master,
|
||||
[[x] for x in self.master.get_tcp_filter()],
|
||||
self.master.edit_tcp_filter
|
||||
)
|
||||
)
|
||||
elif k == "i":
|
||||
self.master.prompt(
|
||||
"Intercept filter: ",
|
||||
self.master.state.intercept_txt,
|
||||
self.master.set_intercept
|
||||
)
|
||||
elif k == "Q":
|
||||
raise urwid.ExitMainLoop
|
||||
elif k == "q":
|
||||
self.master.prompt_onekey(
|
||||
"Quit",
|
||||
(
|
||||
("yes", "y"),
|
||||
("no", "n"),
|
||||
),
|
||||
self.master.quit,
|
||||
)
|
||||
elif k == "M":
|
||||
self.master.prompt_onekey(
|
||||
"Global default display mode",
|
||||
contentview.view_prompts,
|
||||
self.master.change_default_display_mode
|
||||
)
|
||||
elif k == "R":
|
||||
self.master.view_grideditor(
|
||||
grideditor.ReplaceEditor(
|
||||
self.master,
|
||||
self.master.replacehooks.get_specs(),
|
||||
self.master.replacehooks.set
|
||||
)
|
||||
)
|
||||
elif k == "s":
|
||||
self.master.view_grideditor(
|
||||
grideditor.ScriptEditor(
|
||||
self.master,
|
||||
[[i.command] for i in self.master.scripts],
|
||||
self.master.edit_scripts
|
||||
)
|
||||
)
|
||||
elif k == "S":
|
||||
if not self.master.server_playback:
|
||||
self.master.path_prompt(
|
||||
"Server replay path: ",
|
||||
self.master.state.last_saveload,
|
||||
self.master.server_playback_path
|
||||
)
|
||||
else:
|
||||
self.master.prompt_onekey(
|
||||
"Stop current server replay?",
|
||||
(
|
||||
("yes", "y"),
|
||||
("no", "n"),
|
||||
),
|
||||
self.master.stop_server_playback_prompt,
|
||||
)
|
||||
elif k == "o":
|
||||
self.master.prompt_onekey(
|
||||
"Options",
|
||||
(
|
||||
("anticache", "a"),
|
||||
("anticomp", "c"),
|
||||
("showhost", "h"),
|
||||
("killextra", "k"),
|
||||
("norefresh", "n"),
|
||||
("no-upstream-certs", "u"),
|
||||
),
|
||||
self.master._change_options
|
||||
)
|
||||
elif k == "t":
|
||||
self.master.prompt(
|
||||
"Sticky cookie filter: ",
|
||||
self.master.stickycookie_txt,
|
||||
self.master.set_stickycookie
|
||||
)
|
||||
elif k == "u":
|
||||
self.master.prompt(
|
||||
"Sticky auth filter: ",
|
||||
self.master.stickyauth_txt,
|
||||
self.master.set_stickyauth
|
||||
)
|
||||
else:
|
||||
return k
|
||||
self.footer.redraw()
|
Loading…
Reference in New Issue
Block a user