在终端应用上展示进度条的Go库:uiprogress

jopen 8年前

一个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

项目主页:http://www.open-open.com/lib/view/home/1447990758213