mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-30 03:14:22 +00:00
Add an "r" shortcut in grid editors to read value from file.
This commit is contained in:
parent
3787f8befb
commit
82893ffae2
@ -13,7 +13,7 @@
|
|||||||
# You should have received a copy of the GNU General Public License
|
# You should have received a copy of the GNU General Public License
|
||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
import copy, re
|
import copy, re, os
|
||||||
import urwid
|
import urwid
|
||||||
import common
|
import common
|
||||||
from .. import utils, filt
|
from .. import utils, filt
|
||||||
@ -27,6 +27,7 @@ def _mkhelp():
|
|||||||
("d", "delete row"),
|
("d", "delete row"),
|
||||||
("e", "spawn external editor on current field"),
|
("e", "spawn external editor on current field"),
|
||||||
("q", "return to flow view"),
|
("q", "return to flow view"),
|
||||||
|
("r", "read value from file"),
|
||||||
("esc", "return to flow view/exit field edit mode"),
|
("esc", "return to flow view/exit field edit mode"),
|
||||||
("tab", "next field"),
|
("tab", "next field"),
|
||||||
("enter", "edit field"),
|
("enter", "edit field"),
|
||||||
@ -113,6 +114,8 @@ class GridRow(common.WWrap):
|
|||||||
vals.append(v)
|
vals.append(v)
|
||||||
if self.editor.is_error(i, v):
|
if self.editor.is_error(i, v):
|
||||||
errors.add(i)
|
errors.add(i)
|
||||||
|
elif self.editor.encode(v) is None:
|
||||||
|
errors.add(i)
|
||||||
return [vals, errors]
|
return [vals, errors]
|
||||||
|
|
||||||
def keypress(self, s, k):
|
def keypress(self, s, k):
|
||||||
@ -286,6 +289,20 @@ class GridEditor(common.WWrap):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def encode(self, s):
|
||||||
|
if not self.encoding:
|
||||||
|
return s
|
||||||
|
try:
|
||||||
|
return s.encode(self.encoding)
|
||||||
|
except ValueError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def read_file(self, p):
|
||||||
|
p = os.path.expanduser(p)
|
||||||
|
d = file(p, "r").read()
|
||||||
|
self.walker.set_current_value(d)
|
||||||
|
self.walker._modified()
|
||||||
|
|
||||||
def keypress(self, size, key):
|
def keypress(self, size, key):
|
||||||
if self.walker.editing:
|
if self.walker.editing:
|
||||||
if key in ["esc"]:
|
if key in ["esc"]:
|
||||||
@ -303,10 +320,10 @@ class GridEditor(common.WWrap):
|
|||||||
if key in ["q", "esc"]:
|
if key in ["q", "esc"]:
|
||||||
res = []
|
res = []
|
||||||
for i in self.walker.lst:
|
for i in self.walker.lst:
|
||||||
if any([x.strip() for x in i[0]]):
|
if not i[1] and any([x.strip() for x in i[0]]):
|
||||||
v = i[0]
|
v = i[0]
|
||||||
if self.encoding:
|
if self.encoding:
|
||||||
v = [x.encode(self.encoding) for x in v]
|
v = [self.encode(x) for x in v]
|
||||||
res.append(v)
|
res.append(v)
|
||||||
self.callback(res, *self.cb_args, **self.cb_kwargs)
|
self.callback(res, *self.cb_args, **self.cb_kwargs)
|
||||||
self.master.pop_view()
|
self.master.pop_view()
|
||||||
@ -322,6 +339,8 @@ class GridEditor(common.WWrap):
|
|||||||
self.walker.insert()
|
self.walker.insert()
|
||||||
elif key == "d":
|
elif key == "d":
|
||||||
self.walker.delete_focus()
|
self.walker.delete_focus()
|
||||||
|
elif key == "r":
|
||||||
|
self.master.path_prompt("Read file: ", "", self.read_file)
|
||||||
elif key == "e":
|
elif key == "e":
|
||||||
o = self.walker.get_current_value()
|
o = self.walker.get_current_value()
|
||||||
if o is not None:
|
if o is not None:
|
||||||
|
@ -253,7 +253,7 @@ def clean_hanging_newline(t):
|
|||||||
problem at the risk of removing a hanging newline in the rare cases
|
problem at the risk of removing a hanging newline in the rare cases
|
||||||
where the user actually intends it.
|
where the user actually intends it.
|
||||||
"""
|
"""
|
||||||
if t[-1] == "\n":
|
if t and t[-1] == "\n":
|
||||||
return t[:-1]
|
return t[:-1]
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user