Add a shortcut to header editor to add standard User-Agent strings.
This commit is contained in:
parent
71ae158d7b
commit
a33e90f081
|
@ -606,7 +606,7 @@ class ConsoleMaster(flow.FlowMaster):
|
||||||
def view_grideditor(self, ge):
|
def view_grideditor(self, ge):
|
||||||
self.body = ge
|
self.body = ge
|
||||||
self.header = None
|
self.header = None
|
||||||
self.help_context = grideditor.help_context
|
self.help_context = ge.make_help()
|
||||||
self.statusbar = StatusBar(self, grideditor.footer)
|
self.statusbar = StatusBar(self, grideditor.footer)
|
||||||
self.make_view()
|
self.make_view()
|
||||||
|
|
||||||
|
|
|
@ -17,34 +17,9 @@ import copy, re, os
|
||||||
import urwid
|
import urwid
|
||||||
import common
|
import common
|
||||||
from .. import utils, filt
|
from .. import utils, filt
|
||||||
|
from netlib import http_uastrings
|
||||||
|
|
||||||
|
|
||||||
def _mkhelp():
|
|
||||||
text = []
|
|
||||||
keys = [
|
|
||||||
("A", "insert row before cursor"),
|
|
||||||
("a", "add row after cursor"),
|
|
||||||
("d", "delete row"),
|
|
||||||
("e", "spawn external editor on current field"),
|
|
||||||
("q", "return to flow view"),
|
|
||||||
("r", "read value from file"),
|
|
||||||
("R", "read unescaped value from file"),
|
|
||||||
("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))
|
|
||||||
text.append(
|
|
||||||
urwid.Text(
|
|
||||||
[
|
|
||||||
"\n",
|
|
||||||
("text", " Values are displayed and edited as escaped Python-style strings.\n"),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return text
|
|
||||||
help_context = _mkhelp()
|
|
||||||
|
|
||||||
footer = [
|
footer = [
|
||||||
('heading_key', "enter"), ":edit ",
|
('heading_key', "enter"), ":edit ",
|
||||||
('heading_key', "q"), ":back ",
|
('heading_key', "q"), ":back ",
|
||||||
|
@ -147,6 +122,10 @@ class GridWalker(urwid.ListWalker):
|
||||||
self.editor.show_empty_msg()
|
self.editor.show_empty_msg()
|
||||||
return urwid.ListWalker._modified(self)
|
return urwid.ListWalker._modified(self)
|
||||||
|
|
||||||
|
def add_value(self, lst):
|
||||||
|
self.lst.append((lst[:], set([])))
|
||||||
|
self._modified()
|
||||||
|
|
||||||
def get_current_value(self):
|
def get_current_value(self):
|
||||||
if self.lst:
|
if self.lst:
|
||||||
return self.lst[self.focus][0][self.focus_col]
|
return self.lst[self.focus][0][self.focus_col]
|
||||||
|
@ -363,7 +342,7 @@ class GridEditor(common.WWrap):
|
||||||
self.walker._modified()
|
self.walker._modified()
|
||||||
elif key in ["enter"]:
|
elif key in ["enter"]:
|
||||||
self.walker.start_edit()
|
self.walker.start_edit()
|
||||||
else:
|
elif not self.handle_key(key):
|
||||||
return self.w.keypress(size, key)
|
return self.w.keypress(size, key)
|
||||||
|
|
||||||
def is_error(self, col, val):
|
def is_error(self, col, val):
|
||||||
|
@ -372,6 +351,35 @@ class GridEditor(common.WWrap):
|
||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def handle_key(self, key):
|
||||||
|
return False
|
||||||
|
|
||||||
|
def make_help(self):
|
||||||
|
text = []
|
||||||
|
text.append(urwid.Text([("text", "Editor control:\n")]))
|
||||||
|
keys = [
|
||||||
|
("A", "insert row before cursor"),
|
||||||
|
("a", "add row after cursor"),
|
||||||
|
("d", "delete row"),
|
||||||
|
("e", "spawn external editor on current field"),
|
||||||
|
("q", "return to flow view"),
|
||||||
|
("r", "read value from file"),
|
||||||
|
("R", "read unescaped value from file"),
|
||||||
|
("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))
|
||||||
|
text.append(
|
||||||
|
urwid.Text(
|
||||||
|
[
|
||||||
|
"\n",
|
||||||
|
("text", "Values are escaped Python-style strings.\n"),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return text
|
||||||
|
|
||||||
|
|
||||||
class QueryEditor(GridEditor):
|
class QueryEditor(GridEditor):
|
||||||
title = "Editing query"
|
title = "Editing query"
|
||||||
|
@ -383,6 +391,37 @@ class HeaderEditor(GridEditor):
|
||||||
title = "Editing headers"
|
title = "Editing headers"
|
||||||
columns = 2
|
columns = 2
|
||||||
headings = ("Key", "Value")
|
headings = ("Key", "Value")
|
||||||
|
def make_help(self):
|
||||||
|
h = GridEditor.make_help(self)
|
||||||
|
|
||||||
|
text = []
|
||||||
|
text.append(urwid.Text([("text", "Special keys:\n")]))
|
||||||
|
keys = [
|
||||||
|
("U", "add User-Agent header"),
|
||||||
|
]
|
||||||
|
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
|
||||||
|
text.append(urwid.Text([("text", "\n")]))
|
||||||
|
text.extend(h)
|
||||||
|
return text
|
||||||
|
|
||||||
|
def set_user_agent(self, k):
|
||||||
|
ua = http_uastrings.get_by_shortcut(k)
|
||||||
|
if ua:
|
||||||
|
self.walker.add_value(
|
||||||
|
[
|
||||||
|
"User-Agent",
|
||||||
|
ua[2]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
def handle_key(self, key):
|
||||||
|
if key == "U":
|
||||||
|
self.master.prompt_onekey(
|
||||||
|
"Add User-Agent header:",
|
||||||
|
[(i[0], i[1]) for i in http_uastrings.UASTRINGS],
|
||||||
|
self.set_user_agent,
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
class URLEncodedFormEditor(GridEditor):
|
class URLEncodedFormEditor(GridEditor):
|
||||||
|
|
|
@ -33,7 +33,7 @@ class HelpView(urwid.ListBox):
|
||||||
|
|
||||||
def helptext(self):
|
def helptext(self):
|
||||||
text = []
|
text = []
|
||||||
text.append(urwid.Text([("head", "Keys for this view:\n")]))
|
text.append(urwid.Text([("head", "This view:\n")]))
|
||||||
text.extend(self.help_context)
|
text.extend(self.help_context)
|
||||||
|
|
||||||
text.append(urwid.Text([("head", "\n\nMovement:\n")]))
|
text.append(urwid.Text([("head", "\n\nMovement:\n")]))
|
||||||
|
|
Loading…
Reference in New Issue