From 38b10f819f9b815d1938db4d749cb54d123d1737 Mon Sep 17 00:00:00 2001 From: xiaomakuaiz Date: Mon, 3 Jun 2024 17:28:47 +0800 Subject: [PATCH] feat: export result(csv) --- gui/main.go | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/gui/main.go b/gui/main.go index 9036445a..d30e23b5 100644 --- a/gui/main.go +++ b/gui/main.go @@ -1,6 +1,8 @@ package main import ( + "bytes" + "encoding/csv" "errors" "fmt" "io/fs" @@ -145,7 +147,7 @@ func main() { a := app.New() a.Settings().SetTheme(&theme.BlazeHTTPTheme{}) w := a.NewWindow("BLAZEHTTP") - w.Resize(fyne.Size{Width: 720}) + w.Resize(fyne.Size{Width: 810}) outputCh := make(chan string) resultCh := make(chan *worker.Result) @@ -423,7 +425,38 @@ func MakeTestCaseTab(w fyne.Window) fyne.CanvasObject { refreshTable(selected, fileProperty.Selected, isIntercept.Selected) } - return container.NewBorder(tableFilterForm, nil, nil, nil, table) + exportBtn := widget.NewButton("导出", nil) + + exportBtn.OnTapped = func() { + dialog.ShowFileSave(func(writer fyne.URIWriteCloser, err error) { + if writer == nil { + return + } + if err != nil { + dialog.ShowError(err, w) + return + } + defer writer.Close() + b := new(bytes.Buffer) + csvWriter := csv.NewWriter(b) + if err := csvWriter.WriteAll(tableData); err != nil { + dialog.ShowError(err, w) + return + } + if err := csvWriter.Error(); err != nil { + dialog.ShowError(err, w) + return + } + n, err := writer.Write(b.Bytes()) + if err != nil { + dialog.ShowError(err, w) + return + } + fmt.Println("Wrote", n, "bytes") + }, w) + } + + return container.NewBorder(tableFilterForm, nil, nil, exportBtn, table) } func run(target, mHost string, c, statusCode int, resultCh chan *worker.Result, stopCh chan struct{}) error {