{"id":13410205,"url":"https://github.com/gosuri/uiprogress","last_synced_at":"2025-05-14T04:05:01.563Z","repository":{"id":38628652,"uuid":"46313630","full_name":"gosuri/uiprogress","owner":"gosuri","description":"A go library to render progress bars in terminal applications","archived":false,"fork":false,"pushed_at":"2024-02-29T11:06:26.000Z","size":1649,"stargazers_count":2125,"open_issues_count":27,"forks_count":126,"subscribers_count":34,"default_branch":"master","last_synced_at":"2025-05-12T11:01:09.456Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gosuri.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-17T00:59:24.000Z","updated_at":"2025-05-12T09:20:35.000Z","dependencies_parsed_at":"2024-06-18T11:11:54.191Z","dependency_job_id":"94c0fbe9-7502-4b5d-bb17-29c7dafd8b1d","html_url":"https://github.com/gosuri/uiprogress","commit_stats":{"total_commits":37,"total_committers":11,"mean_commits":"3.3636363636363638","dds":0.4054054054054054,"last_synced_commit":"484b9f69ea000422e1873db136dbb80e30b5de3c"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gosuri%2Fuiprogress","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gosuri%2Fuiprogress/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gosuri%2Fuiprogress/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gosuri%2Fuiprogress/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gosuri","download_url":"https://codeload.github.com/gosuri/uiprogress/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254067256,"owners_count":22009120,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T20:01:05.524Z","updated_at":"2025-05-14T04:05:01.384Z","avatar_url":"https://github.com/gosuri.png","language":"Go","funding_links":[],"categories":["高级控制台UI`用于构建控制台应用程序和控制台用户界面的库.`","Go","Command Line","命令行","Build Automation","高级控制台UI","lib","\u003cspan id=\"命令行-command-line\"\u003e命令行 Command Line\u003c/span\u003e"],"sub_categories":["Advanced Console UIs","高级控制台用户界面","标准 CLI","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e"],"readme":"# uiprogress [![GoDoc](https://godoc.org/github.com/gosuri/uiprogress?status.svg)](https://godoc.org/github.com/gosuri/uiprogress) [![Build Status](https://travis-ci.org/gosuri/uiprogress.svg?branch=master)](https://travis-ci.org/gosuri/uiprogress)\n\nA Go library to render progress bars in terminal applications. It provides a set of flexible features with a customizable API.\n\n![example](doc/example_full.gif)\n\nProgress bars improve readability for terminal applications with long outputs by providing a concise feedback loop.\n\n## Features\n\n* __Multiple Bars__: uiprogress can render multiple progress bars that can be tracked concurrently\n* __Dynamic Addition__:  Add additional progress bars any time, even after the progress tracking has started\n* __Prepend and Append Functions__: Append or prepend completion percent and time elapsed to the progress bars\n* __Custom Decorator Functions__: Add custom functions around the bar along with helper functions\n\n## Usage\n\nTo start listening for progress bars, call `uiprogress.Start()` and add a progress bar using `uiprogress.AddBar(total int)`. Update the progress using `bar.Incr()` or `bar.Set(n int)`. Full source code for the below example is available at [example/simple/simple.go](example/simple/simple.go) \n\n```go\nuiprogress.Start()            // start rendering\nbar := uiprogress.AddBar(100) // Add a new bar\n\n// optionally, append and prepend completion and elapsed time\nbar.AppendCompleted()\nbar.PrependElapsed()\n\nfor bar.Incr() {\n  time.Sleep(time.Millisecond * 20)\n}\n```\n\nThis will render the below in the terminal\n\n![example](doc/example_simple.gif)\n\n### Using Custom Decorators\n\nYou can also add a custom decorator function in addition to default `bar.AppendCompleted()` and `bar.PrependElapsed()` decorators. The below example tracks the current step for an application deploy progress. Source code for the below example is available at [example/full/full.go](example/full/full.go) \n\n```go\nvar steps = []string{\"downloading source\", \"installing deps\", \"compiling\", \"packaging\", \"seeding database\", \"deploying\", \"staring servers\"}\nbar := uiprogress.AddBar(len(steps))\n\n// prepend the current step to the bar\nbar.PrependFunc(func(b *uiprogress.Bar) string {\n  return \"app: \" + steps[b.Current()-1]\n})\n\nfor bar.Incr() {\n  time.Sleep(time.Millisecond * 10)\n}\n```\n\n### Rendering Multiple bars\n\nYou can add multiple bars using `uiprogress.AddBar(n)`. The below example demonstrates updating multiple bars concurrently and adding a new bar later in the pipeline. Source for this example is available at [example/multi/multi.go](example/multi/multi.go) \n\n```go\nwaitTime := time.Millisecond * 100\nuiprogress.Start()\n\n// start the progress bars in go routines\nvar wg sync.WaitGroup\n\nbar1 := uiprogress.AddBar(20).AppendCompleted().PrependElapsed()\nwg.Add(1)\ngo func() {\n  defer wg.Done()\n  for bar1.Incr() {\n    time.Sleep(waitTime)\n  }\n}()\n\nbar2 := uiprogress.AddBar(40).AppendCompleted().PrependElapsed()\nwg.Add(1)\ngo func() {\n  defer wg.Done()\n  for bar2.Incr() {\n    time.Sleep(waitTime)\n  }\n}()\n\ntime.Sleep(time.Second)\nbar3 := uiprogress.AddBar(20).PrependElapsed().AppendCompleted()\nwg.Add(1)\ngo func() {\n  defer wg.Done()\n  for i := 1; i \u003c= bar3.Total; i++ {\n    bar3.Set(i)\n    time.Sleep(waitTime)\n  }\n}()\n\n// wait for all the go routines to finish\nwg.Wait()\n```\n\nThis will produce\n\n![example](doc/example_multi.gif)\n\n### `Incr` counter\n\n[Bar.Incr()](https://godoc.org/github.com/gosuri/uiprogress#Bar.Incr) is an atomic counter and can be used as a general tracker, making it ideal for tracking progress of work fanned out to a lots of go routines. The source code for the below example is available at [example/incr/incr.go](example/incr/incr.go)\n\n```go\nruntime.GOMAXPROCS(runtime.NumCPU()) // use all available cpu cores\n\n// create a new bar and prepend the task progress to the bar and fanout into 1k go routines\ncount := 1000\nbar := uiprogress.AddBar(count).AppendCompleted().PrependElapsed()\nbar.PrependFunc(func(b *uiprogress.Bar) string {\n  return fmt.Sprintf(\"Task (%d/%d)\", b.Current(), count)\n})\n\nuiprogress.Start()\nvar wg sync.WaitGroup\n\n// fanout into go routines\nfor i := 0; i \u003c count; i++ {\n  wg.Add(1)\n  go func() {\n    defer wg.Done()\n    time.Sleep(time.Millisecond * time.Duration(rand.Intn(500)))\n    bar.Incr()\n  }()\n}\ntime.Sleep(time.Second) // wait for a second for all the go routines to finish\nwg.Wait()\nuiprogress.Stop()\n```\n\n## Installation\n\n```sh\n$ go get -v github.com/gosuri/uiprogress\n```\n## Todos\n\n- [ ] Resize bars and decorators by auto detecting window's dimensions\n- [ ] Handle more progress bars than vertical screen allows\n\n## License\n\nuiprogress is released under the MIT License. See [LICENSE](https://github.com/gosuri/uiprogress/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgosuri%2Fuiprogress","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgosuri%2Fuiprogress","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgosuri%2Fuiprogress/lists"}