在終端應用上展示進度條的Go庫:uiprogress
一個Go庫用于在在終端應用上展示進度條。它提供了一套強大的功能并且可以使用簡單的界面進行自定義。
Progress bars improve readability for terminal applications with long outputs by providing a concise feedback loop.
特性
- Multiple Bars: uiprogress can render multiple progress bars that can be tracked concurrently
- Dynamic Addition: Add additional progress bars any time, even after the progress tracking has started
- Prepend and Append Functions: Append or prepend completion percent and time elapsed to the progress bars
- Custom Decorator Functions: Add custom functions around the bar along with helper functions
用法
To start listening for progress bars, calluiprogress.Start()and add a progress bar usinguiprogress.AddBar(total). Update the progress usingbar.Set(n). Full source code for the below example is available at example/simple/simple.go
uiprogress.Start() // start rendering bar := uiprogress.AddBar(100) // Add a new bar // optionally, append and prepend completion and elapsed time bar.AppendCompleted() bar.PrependElapsed() for i := 1; i <= bar.Total; i++ { bar.Set(i) time.Sleep(time.Millisecond * 10) }
This will render the below in the terminal
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!