示例#1
0
func (ld *loader) updateProgress(bar *pb.ProgressBar) {
	bar.Set64(ld.r.BytesRead())
}
示例#2
0
func install(l, version string) error {
	var currentStep lang.Step
	var bar *pb.ProgressBar
	var process *Process
	fmt.Printf("Installing %s@%s\n", l, version)
	err := service.Install(l, version, binaryFlag, func(step lang.Step, progress, total int64) {

		if currentStep != step {
			if bar != nil {
				bar.NotPrint = true
				bar.Finish()
				fmt.Printf(ascii2.EraseLine)
				bar = nil
			}

			if process != nil {
				process.Done("")
				process = nil
			}

			if total > 0 {
				bar = pb.New64(total).Prefix("  " + stepToMsg(step) + "\t\t")
				bar.SetWidth(40)
				bar.ShowCounters = false
				//fmt.Printf("%s\n", step)
				//bar.NotPrint = true
				bar.Start()
				currentStep = step

			} else {
				process := &Process{Msg: stepToMsg(step) + "\t\t"}
				process.Start()
			}

		}
		if bar != nil {
			bar.Set64(progress)
		}

	})

	if bar != nil {
		bar.NotPrint = true
		bar.Finish()

		fmt.Printf(ascii2.EraseLines(2) + ascii2.EraseLine + fmt.Sprintf("  %s installed", l))
	}

	if process != nil {
		process.Done("\n")
	}
	//fmt.Printf(ascii2.EraseLine + ascii2.CursorUp(1) + ascii2.EraseLine)

	if err != nil {
		fmt.Printf("Could not install %s@%s: \n  %s\n", l, version, err.Error())
	} else {
		fmt.Printf("  %s@%s installed!\n\n", l, version)
	}

	return err
}
示例#3
0
文件: update.go 项目: kildevaeld/lang
	Short: "A brief description of your command",
	Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
	Run: func(cmd *cobra.Command, args []string) {
		// TODO: Work your own magic here
		var bar *pb.ProgressBar

		err := service.Update(func(step lang.Step, p, t int64) {
			if bar == nil {
				bar = createBar("Updating manifests", t)
			}
			bar.Set64(p)
		})

		if bar != nil {
			bar.Finish()
		}

		if err != nil {
			printError(err)
		}

	},
}

func init() {
	RootCmd.AddCommand(updateCmd)
示例#4
0
func (d *dumper) updateProgress(bar *pb.ProgressBar) {
	bar.Set64(d.f.Stats().BytesRead)
}
示例#5
0
func (d *deleter) updateProgress(bar *pb.ProgressBar) {
	bar.Set64(d.del.Completed())
}
示例#6
0
文件: test.go 项目: kildevaeld/lang
					bar.SetWidth(40)
					bar.ShowCounters = false
					//fmt.Printf("%s\n", step)
					//bar.NotPrint = true
					bar.Start()
					currentStep = step

				} else {
					process := &Process{Msg: "  " + stepToMsg(step) + "\t\t"}
					process.Start()
				}

			}

			if bar != nil {
				bar.Set64(progress)
			}

		})

		if bar != nil {
			bar.NotPrint = true
			bar.Finish()
			fmt.Printf(ascii2.EraseLines(2) + ascii2.EraseLine + "\r  installed")
		}
		/*if bar != nil {
			bar.NotPrint = true
			bar.FinishPrint(ascii2.EraseLine + ascii2.CursorUp(1) + ascii2.EraseLine + "  " + stepToMsg(currentStep) + "\t\tDone")

		}
		if process != nil {
示例#7
0
func finishProgressBar(pb *pb.ProgressBar) {
	pb.Set64(pb.Total)
	pb.Finish()
}