// UpdateFiles sends all files that should be updated to the server
// the limit is 3 concurrent files at once
UpdateFiles sends all files that should be updated to the server
the limit is 3 concurrent files at once
// UpdateFiles sends all files that should be updated to the server // the limit is 3 concurrent files at once
func (up *Updater) UpdateFiles(files map[string]*file.File) error {
	updatable, err := up.Updatable(files)
	if err != nil {
		return err
	}
	if !updatable {
		return nil
	}
	height := 3
	err = termui.Init()
	if err != nil {
		panic(err)
	}
	defer termui.Close()
	p := termui.NewPar("PRESS ANY KEY TO QUIT")
	p.Height = height
	p.Width = 50
	p.TextFgColor = termui.ColorWhite
	up.ui = append(up.ui, p)
	doneTotal := 0
	total := len(up.ToUpdate)
	jobs := make(chan *job, total)
	done := make(chan bool, total)
	if up.Workers <= 0 {
		up.Workers = 1
	}
	go func() {
		termui.Loop()
	}()
	termui.Handle("/sys/kbd", func(termui.Event) {
		termui.StopLoop()
		os.Exit(1)
	})
	go func(upp *Updater, d *int) {
		for {
			if *d >= total {
				break
			}
			termui.Render(upp.ui...)
		}
	}(up, &doneTotal)
	for i := 0; i < up.Workers; i++ {
		g := termui.NewGauge()
		g.Width = termui.TermWidth()
		g.Height = height
		g.BarColor = termui.ColorBlue
		g.Y = len(up.ui) * height
		up.ui = append(up.ui, g)
		go up.worker(jobs, done, g)
	}
	for i, name := range up.ToUpdate {
		jobs <- &job{
			current: i + 1,
			files:   files[name],
			total:   total,
		}
	}
	close(jobs)
	for i := 0; i < total; i++ {
		<-done
		doneTotal++
	}
	return nil
}
func ( up * Updater ) UpdateFiles ( files map [ string ] * file . File ) error { updatable , err := up . Updatable ( files ) if err != nil { return err } if ! updatable { return nil } height := 3 err = termui . Init ( ) if err != nil { panic ( err ) } defer termui . Close ( ) p := termui . NewPar ( " " ) p . Height = height p . Width = 50 p . TextFgColor = termui . ColorWhite up . ui = append ( up . ui , p ) doneTotal := 0 total := len ( up . ToUpdate ) jobs := make ( chan * job , total ) done := make ( chan bool , total ) if up . Workers <= 0 { up . Workers = 1 } go func ( ) { termui . Loop ( ) } ( ) termui . Handle ( " " , func ( termui . Event ) { termui . StopLoop ( ) os . Exit ( 1 ) } ) go func ( upp * Updater , d * int ) { for { if * d >= total { break } termui . Render ( upp . ui ... ) } } ( up , & doneTotal ) for i := 0 ; i < up . Workers ; i ++ { g := termui . NewGauge ( ) g . Width = termui . TermWidth ( ) g . Height = height g . BarColor = termui . ColorBlue g . Y = len ( up . ui ) * height up . ui = append ( up . ui , g ) go up . worker ( jobs , done , g ) } for i , name := range up . ToUpdate { jobs <- & job { current : i + 1 , files : files [ name ] , total : total , } } close ( jobs ) for i := 0 ; i < total ; i ++ { <- done doneTotal ++ } return nil }
UpdateFiles sends all files that should be updated to the server
the limit is 3 concurrent files at once
UpdateFiles sends all files that should be updated to the server the limit is 3 concurrent files at once
// everything's height // info text // just so it can listen to events // cancel with any key // stops rendering when total is reached // creates a progress bar