当前位置: 首页>>代码示例>>Golang>>正文


Golang uiprogress.AddBar函数代码示例

本文整理汇总了Golang中github.com/gosuri/uiprogress.AddBar函数的典型用法代码示例。如果您正苦于以下问题:Golang AddBar函数的具体用法?Golang AddBar怎么用?Golang AddBar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了AddBar函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	runtime.GOMAXPROCS(runtime.NumCPU()) // use all available cpu cores

	// create a new bar and prepend the task progress to the bar and fanout into 1k go routines
	count := 1000
	bar := uiprogress.AddBar(count).AppendCompleted().PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return fmt.Sprintf("Task (%d/%d)", b.Current(), count)
	})

	uiprogress.Start()
	var wg sync.WaitGroup

	// fanout into 1k go routines
	for i := 0; i < count; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			time.Sleep(time.Millisecond * time.Duration(rand.Intn(500)))
			bar.Incr()
		}()
	}
	time.Sleep(time.Second) // wait for a second for all the go routines to finish
	wg.Wait()
	uiprogress.Stop()
}
开发者ID:louisyoo,项目名称:uiprogress,代码行数:26,代码来源:incr.go

示例2: generateGIF

func generateGIF(filenames []string, outPath string) error {
	fmt.Printf("Generating GIF in %s\n", outPath)
	uiprogress.Start()
	bar := uiprogress.AddBar(len(filenames)).AppendCompleted()
	anim := gif.GIF{LoopCount: len(filenames)}
	for _, filename := range filenames {
		reader, err := os.Open(filename)
		if err != nil {
			return err
		}
		defer reader.Close()
		img, _, err := image.Decode(reader)
		if err != nil {
			return err
		}
		bounds := img.Bounds()
		drawer := draw.FloydSteinberg
		palettedImg := image.NewPaletted(bounds, palette.Plan9)
		drawer.Draw(palettedImg, bounds, img, image.ZP)
		anim.Image = append(anim.Image, palettedImg)
		anim.Delay = append(anim.Delay, *delay)
		bar.Incr()
	}
	file, err := os.Create(outPath)
	defer file.Close()
	if err != nil {
		return err
	}
	encodeErr := gif.EncodeAll(file, &anim)
	if encodeErr != nil {
		return encodeErr
	}
	return nil
}
开发者ID:castillobg,项目名称:gipher,代码行数:34,代码来源:main.go

示例3: torrentBar

func torrentBar(t *torrent.Torrent) {
	bar := uiprogress.AddBar(1)
	bar.AppendCompleted()
	bar.AppendFunc(func(*uiprogress.Bar) (ret string) {
		select {
		case <-t.GotInfo():
		default:
			return "getting info"
		}
		if t.Seeding() {
			return "seeding"
		} else if t.BytesCompleted() == t.Info().TotalLength() {
			return "completed"
		} else {
			return fmt.Sprintf("downloading (%s/%s)", humanize.Bytes(uint64(t.BytesCompleted())), humanize.Bytes(uint64(t.Info().TotalLength())))
		}
	})
	bar.PrependFunc(func(*uiprogress.Bar) string {
		return t.Name()
	})
	go func() {
		<-t.GotInfo()
		bar.Total = int(t.Info().TotalLength())
		for {
			bc := t.BytesCompleted()
			bar.Set(int(bc))
			time.Sleep(time.Second)
		}
	}()
}
开发者ID:ymonk,项目名称:torrent,代码行数:30,代码来源:main.go

示例4: downloadImage

func downloadImage(u, output string) error {
	url, err := url.Parse(u)
	if err != nil {
		return err
	}

	_, filename := filepath.Split(url.Path)
	out, err := os.Create(filepath.Join(output, filename))
	if err != nil {
		return err
	}
	defer out.Close()

	resp, err := http.Get(u)
	if err != nil {
		return err
	}
	defer resp.Body.Close()

	sum := 0

	bar := uiprogress.AddBar(int(resp.ContentLength)).AppendCompleted().PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return strutil.Resize(humanize.Bytes(uint64(sum))+"/"+humanize.Bytes(uint64(resp.ContentLength))+" "+filename+": ", 42)
	})

	for {
		written, err := io.CopyN(out, resp.Body, 4096)
		sum += int(written)
		bar.Set(sum)
		if err != nil {
			return err
		}
	}
}
开发者ID:netbrain,项目名称:gopixabay,代码行数:35,代码来源:root.go

示例5: Run

func (p *Pomodoro) Run(duration int) bool {
	tick := time.NewTicker(time.Second / 10)
	p.running = true
	p.bar = uiprogress.AddBar(10 * duration).AppendCompleted().PrependElapsed()
	/*.PrependFunc(func(b *uiprogress.Bar) string {
		return p.msg + ": "
	})*/

	defer func() {
		tick.Stop()
		p.running = false
		p.done = make(chan struct{}, 0)
	}()

	for {
		select {
		case <-tick.C:
			p.bar.Set(p.bar.Current() + 1)
			if p.bar.Current() >= 10*duration {
				p.running = false
				close(p.done)
				return true
			}
		case <-p.done:
			return false
		}
	}
}
开发者ID:VojtechVitek,项目名称:pomodoro,代码行数:28,代码来源:main.go

示例6: newBar

func newBar(name string, steps int) *BuildBar {
	buildBar := BuildBar{name: name}
	bar := uiprogress.AddBar(steps).AppendCompleted()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return strutil.Resize(buildBar.name+": "+buildBar.currentStep, 20)
	})
	buildBar.bar = bar
	return &buildBar
}
开发者ID:Mrmaxmeier,项目名称:love-release-go,代码行数:9,代码来源:bar.go

示例7: Save

// Save method persist (save or update) the chain on the disk
func (c *Chain) Save() {
	var cn = c.collection
	if c.collection == "" {
		cn = timeName()
		c.collection = cn
	}

	sess, coll := model.Connect(cn)
	defer sess.Close()

	ks := c.Keys()
	sort.Strings(ks)

	var wg sync.WaitGroup
	var workForce = 5
	ch := make(chan model.NewNodeInfo, workForce)

	for i := 0; i < workForce; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			var ni model.NewNodeInfo
			var more bool

			for {
				ni, more = <-ch
				if more {
					model.NewNode(ni).Save(coll)
				} else {
					return
				}
			}
		}()
	}

	count := len(ks)
	bar := uiprogress.AddBar(count)
	bar.AppendCompleted()
	bar.PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return fmt.Sprintf("Node (%d/%d)", b.Current(), count)
	})

	uiprogress.Start()
	for _, x := range ks {
		ch <- model.NewNodeInfo{x, c.chain[x]}

		bar.Incr()
	}

	uiprogress.Stop()
	close(ch)
	wg.Wait()
}
开发者ID:zeroed,项目名称:markovianomatic,代码行数:55,代码来源:markovianomatic.go

示例8: ExampleProgress_AddBar

func ExampleProgress_AddBar() {
	waitTime := time.Millisecond * 100
	uiprogress.Start()

	var wg sync.WaitGroup

	bar1 := uiprogress.AddBar(20).AppendCompleted().PrependElapsed()
	wg.Add(1)
	// update the progress bars concurrently using a go routine
	go func() {
		defer wg.Done()
		for i := 1; i <= bar1.Total; i++ {
			bar1.Set(i)
			time.Sleep(waitTime)
		}
	}()

	bar2 := uiprogress.AddBar(100).AppendCompleted().PrependElapsed()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for i := 1; i <= bar2.Total; i++ {
			bar2.Set(i)
			time.Sleep(waitTime)
		}
	}()

	time.Sleep(time.Second)
	bar3 := uiprogress.AddBar(20).PrependElapsed().AppendCompleted()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for i := 1; i <= bar3.Total; i++ {
			bar3.Set(i)
			time.Sleep(waitTime)
		}
	}()

	// wait for a collection of goroutines to finish
	wg.Wait()
}
开发者ID:pranavcode,项目名称:uiprogress,代码行数:41,代码来源:example_test.go

示例9: Example

func Example() {
	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 bar.Incr() {
		time.Sleep(time.Millisecond * 20)
	}
}
开发者ID:hjortron,项目名称:uiprogress,代码行数:12,代码来源:example_test.go

示例10: Generate

func Generate() {
	cfg := Conf{}
	var fId, mail, pass, name, hueser string
	var speed time.Duration

	reader := bufio.NewReader(os.Stdin)

	fmt.Println("Your facebook id:")
	fmt.Scanln(&fId)
	cfg.UserId = fId

	fmt.Println("Your facebook mail:")
	fmt.Scanln(&mail)
	cfg.Mail = mail

	fmt.Println("Your facebook password:")
	pass, err := reader.ReadString('\n')
	checkErr(err)
	cfg.Pass = pass[:len(pass)-2]

	bridges, err := hue.FindBridges()
	checkErr(err)
	bridge := bridges[0]

	fmt.Println("Please authorize this program, by linking it on your bridge now; you've got 15 seconds.")

	uiprogress.Start()
	bar := uiprogress.AddBar(15000 / 100).AppendCompleted().PrependElapsed()
	for bar.Incr() {
		time.Sleep(100 * time.Millisecond)
	}

	hueser, err = bridge.CreateUser(mail)
	checkErr(err)
	cfg.Hueser = hueser

	fmt.Println("Name of your light:")
	name, err = reader.ReadString('\n')
	checkErr(err)
	cfg.Name = name[:len(name)-2]

	fmt.Println("Blink speed of the light:")
	fmt.Scanln(&speed)
	cfg.Speed = speed

	byteArr, _ := json.Marshal(cfg)
	file, err := os.Create("config.json")
	checkErr(err)

	_, err = file.Write(byteArr)
	checkErr(err)
}
开发者ID:Mobilpadde,项目名称:FaceUp,代码行数:52,代码来源:conf.go

示例11: main

func main() {
	waitTime := time.Millisecond * 100
	uiprogress.Start()

	var wg sync.WaitGroup

	bar1 := uiprogress.AddBar(20).AppendCompleted().PrependElapsed()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for i := 1; i <= bar1.Total; i++ {
			bar1.Set(i)
			time.Sleep(waitTime)
		}
	}()

	bar2 := uiprogress.AddBar(40).AppendCompleted().PrependElapsed()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for i := 1; i <= bar2.Total; i++ {
			bar2.Set(i)
			time.Sleep(waitTime)
		}
	}()

	time.Sleep(time.Second)
	bar3 := uiprogress.AddBar(20).PrependElapsed().AppendCompleted()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for i := 1; i <= bar3.Total; i++ {
			bar3.Set(i)
			time.Sleep(waitTime)
		}
	}()

	wg.Wait()
}
开发者ID:pranavcode,项目名称:uiprogress,代码行数:39,代码来源:multi.go

示例12: ExampleDecoratorFunc

func ExampleDecoratorFunc() {
	var steps = []string{"downloading source", "installing deps", "compiling", "packaging", "seeding database", "deploying", "staring servers"}
	bar := uiprogress.AddBar(len(steps))

	// prepend the current step to the bar
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return "app: " + steps[b.Current()-1]
	})

	for bar.Incr() {
		time.Sleep(time.Millisecond)
	}
}
开发者ID:hjortron,项目名称:uiprogress,代码行数:13,代码来源:example_test.go

示例13: main

func main() {
	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)
	}
}
开发者ID:pranavcode,项目名称:uiprogress,代码行数:14,代码来源:simple.go

示例14: performDeploy

func performDeploy(args []string) error {
	if len(args) != 1 {
		return errors.New("deploy takes only 1 argument - Marathon's application definition file")
	}
	path := args[0]
	renderedConfig, err := appconfig.Render(environment, path)
	if dryRun {
		fmt.Println("Rendered app specification")
		fmt.Println(renderedConfig)
		return err
	}

	var configMap map[string]interface{}
	util.JsonDecode(renderedConfig, &configMap)
	appName := configMap["id"].(string)

	fmt.Println("Deploying " + appName + " from " + path)
	deployment, err := marathon.Deploy(appName, renderedConfig, force)
	if err != nil {
		return err
	}

	// Do fancy UI updates on the screen
	uiprogress.Start()
	defer uiprogress.Stop()
	bar := uiprogress.AddBar(timeoutInSeconds + 1)
	bar.AppendCompleted()
	bar.PrependElapsed()
	bar.PrependFunc(func(b *uiprogress.Bar) string {
		return appName + " deploying"
	})

	for bar.Incr() {
		time.Sleep(time.Millisecond * 1000)
		if bar.Current()%15 == 0 { // check the deployment stauts only every 15 seconds
			stillDeploying, err := marathon.IsStillDeploying(deployment)
			if err != nil {
				return err
			}
			if !stillDeploying {
				bar.Set(timeoutInSeconds)
				time.Sleep(time.Millisecond * 20) // wait for a few ms to refresh the output
				fmt.Println("Deployment completed")
				return nil
			}
		}
	}

	return errors.New("[ERROR] App deployment timed out. Check Marathon UI for more details")
}
开发者ID:ashwanthkumar,项目名称:marathonctl,代码行数:50,代码来源:deploy.go

示例15: ExampleProgress_AddBar

func ExampleProgress_AddBar() {
	waitTime := time.Millisecond * 100
	uiprogress.Start()
	// start the progress bars in go routines
	var wg sync.WaitGroup

	bar1 := uiprogress.AddBar(20).AppendCompleted().PrependElapsed()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for bar1.Incr() {
			time.Sleep(waitTime)
		}
	}()

	bar2 := uiprogress.AddBar(40).AppendCompleted().PrependElapsed()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for bar2.Incr() {
			time.Sleep(waitTime)
		}
	}()

	time.Sleep(time.Second)
	bar3 := uiprogress.AddBar(20).PrependElapsed().AppendCompleted()
	wg.Add(1)
	go func() {
		defer wg.Done()
		for i := 1; i <= bar3.Total; i++ {
			bar3.Set(i)
			time.Sleep(waitTime)
		}
	}()
	// wait for all the go routines to finish
	wg.Wait()
}
开发者ID:hjortron,项目名称:uiprogress,代码行数:37,代码来源:example_test.go


注:本文中的github.com/gosuri/uiprogress.AddBar函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。