mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
Merge pull request #2689 from cortesi/grideditor.save
console.grideditor.save
This commit is contained in:
commit
33585bd2a2
@ -1,3 +1,4 @@
|
|||||||
|
import csv
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from mitmproxy import ctx
|
from mitmproxy import ctx
|
||||||
@ -417,6 +418,20 @@ class ConsoleAddon:
|
|||||||
"""
|
"""
|
||||||
self._grideditor().cmd_read_file_escaped(path)
|
self._grideditor().cmd_read_file_escaped(path)
|
||||||
|
|
||||||
|
@command.command("console.grideditor.save")
|
||||||
|
def grideditor_save(self, path: command.Path) -> None:
|
||||||
|
"""
|
||||||
|
Save data to file as a CSV.
|
||||||
|
"""
|
||||||
|
rows = self._grideditor().value
|
||||||
|
with open(path, "w", newline='', encoding="utf8") as fp:
|
||||||
|
writer = csv.writer(fp)
|
||||||
|
for row in rows:
|
||||||
|
writer.writerow(
|
||||||
|
[strutils.always_str(x) or "" for x in row] # type: ignore
|
||||||
|
)
|
||||||
|
ctx.log.alert("Saved %s rows as CSV." % (len(rows)))
|
||||||
|
|
||||||
@command.command("console.grideditor.editor")
|
@command.command("console.grideditor.editor")
|
||||||
def grideditor_editor(self) -> None:
|
def grideditor_editor(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -156,6 +156,12 @@ def map(km):
|
|||||||
"Load a Python-style escaped string into the current cell from file"
|
"Load a Python-style escaped string into the current cell from file"
|
||||||
)
|
)
|
||||||
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")
|
km.add("e", "console.grideditor.editor", ["grideditor"], "Edit in external editor")
|
||||||
|
km.add(
|
||||||
|
"w",
|
||||||
|
"console.command console.grideditor.save ",
|
||||||
|
["grideditor"],
|
||||||
|
"Save data to file as CSV"
|
||||||
|
)
|
||||||
|
|
||||||
km.add("z", "eventstore.clear", ["eventlog"], "Clear")
|
km.add("z", "eventstore.clear", ["eventlog"], "Clear")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user