Skip to content

Commit

Permalink
perf: use spinner for waiting
Browse files Browse the repository at this point in the history
  • Loading branch information
LeeEirc committed Jan 2, 2025
1 parent c30c07e commit 0c268a2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/proxy/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@ func (p *Parser) waitCommandConfirm() {
titleMsg := lang.T("Need ticket confirm to execute command, already send email to the reviewers")
reviewersMsg := fmt.Sprintf(lang.T("Ticket Reviewers: %s"), strings.Join(reviewers, ", "))
detailURLMsg := fmt.Sprintf(lang.T("Could copy website URL to notify reviewers: %s"), detailURL)
spinner := []string{"|", "/", "-", "\\"}
var tipString strings.Builder
tipString.WriteString(utils.CharNewLine)
tipString.WriteString(titleMsg)
Expand All @@ -594,6 +595,8 @@ func (p *Parser) waitCommandConfirm() {
tipString.WriteString(utils.CharNewLine)
tipString.WriteString(detailURLMsg)
tipString.WriteString(utils.CharNewLine)
tipString.WriteString(waitMsg)
tipString.WriteString(utils.CharNewLine)
p.srvOutputChan <- []byte(utils.WrapperString(tipString.String(), utils.Green))
for {
select {
Expand All @@ -603,7 +606,8 @@ func (p *Parser) waitCommandConfirm() {
return
default:
delayS := fmt.Sprintf("%ds", delay)
data := strings.Repeat("\x08", len(delayS)+len(waitMsg)) + waitMsg + delayS
currentSpinner := spinner[delay%len(spinner)]
data := strings.Repeat("\x08", len(delayS)+len(currentSpinner)) + currentSpinner + delayS
p.srvOutputChan <- []byte(data)
time.Sleep(time.Second)
delay += 1
Expand Down

0 comments on commit 0c268a2

Please sign in to comment.