2 回答

TA貢獻1805條經驗 獲得超9個贊
根據您最初的問題,這是不在行中顯示微調器的解決方案:
引入一個變量
pauseItForAMoment := false這將有助于忽略在你的一個 goroutine 中是否暫停。
func main() {
pauseItForAMoment := false
goroutine 看起來像這樣:
// tried moving this into the worker goroutine also, but same effect
for range spinnerCh {
current += 1
if !pauseItForAMoment {
if err := s.Pause(); err != nil {
panic(err)
}
s.Message(fmt.Sprintf("%d/%d", current, total))
if err := s.Unpause(); err != nil {
panic(err)
}
}
}
}(spinner)
打印時停止和啟動微調器d
pauseItForAMoment = true
spinner.Prefix(d)
spinner.Stop()
// fmt.Println(d)
spinner.Start()
pauseItForAMoment = false
將幾個微調器配置值更改為:
StopCharacter: " ",
// StopMessage: "done",
請注意,您的 goroutine 并不完全正確地按照您已經知道的順序打印它們,希望您能解決這個問題。
輸出如下所示:
如果不清楚,這里是代碼https://go.dev/play/p/0lOza3aapf2
我更喜歡在下面顯示這樣的輸出 & 代碼是https://go.dev/play/p/W8Y1kwNqphl(只是我的 2cents ;-) 如果你不需要它,請忽略它)

TA貢獻1775條經驗 獲得超11個贊
圖書館的作者在這里。根據您在打開的 GitHub 問題中分享的片段,我認為您只需要將StopCharacter
值設置為空字符串而不是" "
. 它讓它為我呈現這樣......
這是Go Playground 上的代碼,因為我太笨了,不知道如何在不丟失格式的情況下復制和粘貼它。
我希望這有幫助!
- 2 回答
- 0 關注
- 90 瀏覽
添加回答
舉報