diff --git a/gui/drawer.go b/gui/drawer.go index 388bfb7..ac51963 100644 --- a/gui/drawer.go +++ b/gui/drawer.go @@ -14,7 +14,7 @@ import ( type drawer struct { widgets *widgets chartCh chan *attacker.Result - donutCh chan bool + gaugeCh chan bool reportCh chan string // aims to avoid to perform multiple `redrawChart`. @@ -34,10 +34,10 @@ L: break L case res := <-d.chartCh: if res.End { - d.donutCh <- true + d.gaugeCh <- true break L } - d.donutCh <- false + d.gaugeCh <- false values = append(values, float64(res.Latency/time.Millisecond)) d.widgets.latencyChart.Series("latency", values, linechart.SeriesCellOpts(cell.FgColor(cell.ColorNumber(87))), @@ -50,20 +50,20 @@ L: d.chartDrawing = false } -func (d *drawer) redrawDonut(ctx context.Context, maxSize int) { +func (d *drawer) redrawGauge(ctx context.Context, maxSize int) { var count float64 size := float64(maxSize) - d.widgets.progressDonut.Percent(0) + d.widgets.progressGauge.Percent(0) for { select { case <-ctx.Done(): return - case end := <-d.donutCh: + case end := <-d.gaugeCh: if end { return } count++ - d.widgets.progressDonut.Percent(int(count / size * 100)) + d.widgets.progressGauge.Percent(int(count / size * 100)) } } } diff --git a/gui/gui.go b/gui/gui.go index 7b5d510..bf0f3e8 100644 --- a/gui/gui.go +++ b/gui/gui.go @@ -51,7 +51,7 @@ func Run() error { d := &drawer{ widgets: w, chartCh: make(chan *attacker.Result), - donutCh: make(chan bool), + gaugeCh: make(chan bool), reportCh: make(chan string), } go d.redrawReport(ctx) @@ -66,18 +66,18 @@ func gridLayout(w *widgets) ([]container.Option, error) { grid.ColWidthPerc(99, grid.Widget(w.latencyChart, container.Border(linestyle.Light), container.BorderTitle("Latency (ms)"))), ) raw2 := grid.RowHeightPerc(36, - grid.ColWidthPerc(30, - grid.RowHeightPerc(33, grid.Widget(w.urlInput, container.Border(linestyle.None))), - grid.RowHeightPerc(33, + grid.ColWidthPerc(64, + grid.RowHeightPerc(31, grid.Widget(w.urlInput, container.Border(linestyle.None))), + grid.RowHeightPerc(31, grid.ColWidthPerc(50, grid.Widget(w.rateLimitInput, container.Border(linestyle.None))), grid.ColWidthPerc(49, grid.Widget(w.durationInput, container.Border(linestyle.None))), ), - grid.RowHeightPerc(32, + grid.RowHeightPerc(31, grid.ColWidthPerc(50, grid.Widget(w.methodInput, container.Border(linestyle.None))), grid.ColWidthPerc(49, grid.Widget(w.bodyInput, container.Border(linestyle.None))), ), + grid.RowHeightPerc(6, grid.Widget(w.progressGauge, container.Border(linestyle.None))), ), - grid.ColWidthPerc(34, grid.Widget(w.progressDonut, container.Border(linestyle.Light), container.BorderTitle("Progress"))), grid.ColWidthPerc(35, grid.Widget(w.reportText, container.Border(linestyle.Light), container.BorderTitle("Report"))), ) raw3 := grid.RowHeightFixed(1, @@ -151,7 +151,7 @@ func attack(ctx context.Context, dr *drawer) { // To pre-allocate, run redrawChart on a per-attack basis. go dr.redrawChart(ctx, requestNum) - go dr.redrawDonut(ctx, requestNum) + go dr.redrawGauge(ctx, requestNum) go func(ctx context.Context, d *drawer, t string, r int, du time.Duration) { metrics := attacker.Attack(ctx, t, d.chartCh, attacker.Options{Rate: r, Duration: du, Method: method, Body: []byte(body)}) d.reportCh <- metrics.String() diff --git a/gui/widgets.go b/gui/widgets.go index 30d7f19..8c7b5f8 100644 --- a/gui/widgets.go +++ b/gui/widgets.go @@ -4,7 +4,8 @@ import ( "time" "github.com/mum4k/termdash/cell" - "github.com/mum4k/termdash/widgets/donut" + "github.com/mum4k/termdash/linestyle" + "github.com/mum4k/termdash/widgets/gauge" "github.com/mum4k/termdash/widgets/linechart" "github.com/mum4k/termdash/widgets/text" "github.com/mum4k/termdash/widgets/textinput" @@ -23,7 +24,7 @@ type widgets struct { bodyInput *textinput.TextInput latencyChart *linechart.LineChart reportText *text.Text - progressDonut *donut.Donut + progressGauge *gauge.Gauge navi *text.Text } @@ -60,7 +61,7 @@ func newWidgets() (*widgets, error) { if err != nil { return nil, err } - progressDonut, err := newDonut() + progressDonut, err := newGauge() if err != nil { return nil, err } @@ -72,7 +73,7 @@ func newWidgets() (*widgets, error) { bodyInput: bodyInput, latencyChart: latencyChart, reportText: reportText, - progressDonut: progressDonut, + progressGauge: progressDonut, navi: navi, }, nil } @@ -104,8 +105,10 @@ func newTextInput(label, placeHolder string, cells int) (*textinput.TextInput, e ) } -func newDonut() (*donut.Donut, error) { - return donut.New( - donut.CellOpts(cell.FgColor(cell.ColorGreen)), +func newGauge() (*gauge.Gauge, error) { + return gauge.New( + gauge.Height(1), + gauge.Border(linestyle.Light), + gauge.BorderTitle("Progress"), ) }