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


Golang spinner.New函数代码示例

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


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

示例1: runInstall

func runInstall(cmd *cobra.Command, args []string) {
	p, err := pkg.ReadCaddyJSON()
	if err != nil {
		log.Fatal(err)
		return
	}

	if len(args) >= 1 {
		name := args[0]
		fmt.Printf("\n      Installing %s...", name)
		s := spinner.New(spinner.CharSets[21], 100*time.Millisecond) // Build our new spinner
		s.Start()
		defer s.Stop()
		dep, err := pkg.Parse(name, "*")
		if err != nil {
			fmt.Printf(" [\033[0;31mERR\033[0m]\n")
			fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
			return
		}
		err = install.Download(isGlobal, &dep)
		if err != nil {
			fmt.Printf(" [\033[0;31mERR\033[0m]\n")
			fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
			return
		}
		fmt.Printf("\r[\033[0;32mOK\033[0m]")
		fmt.Printf("\n\n")
		if save {
			p.RawDependencies[dep.Name] = dep.Spec
			pkg.WriteCaddyJSON(p)
		}
	} else {
		for _, dep := range p.Dependencies {
			fmt.Printf("\n      Installing %[email protected]%s...", dep.Name, dep.Spec)
			s := spinner.New(spinner.CharSets[21], 100*time.Millisecond) // Build our new spinner
			s.Start()
			defer s.Stop()
			err := install.Download(isGlobal, &dep)
			if err != nil {
				fmt.Printf(" [\033[0;31mERR\033[0m]\n")
				fmt.Printf("\t  \033[0;31m%s\033[0m\n", err)
				continue
			}
			fmt.Printf("\r[\033[0;32mOK\033[0m]")
		}
		fmt.Printf("\n\n")
	}

}
开发者ID:ChrisMcKenzie,项目名称:caddy,代码行数:49,代码来源:install.go

示例2: main

func main() {
	s := spinner.New(spinner.CharSets[9], 100*time.Millisecond) // Build our new spinner
	s.Color("red")                                              // Set the spinner color to red
	s.FinalMSG = "Complete!\nNew line!\nAnother one!\n"         // String to be displayed after Stop() is called
	s.Start()                                                   // Start the spinner
	time.Sleep(4 * time.Second)                                 // Run for some time to simulate work
	s.Stop()                                                    // Stop the spinner
}
开发者ID:organicelement,项目名称:ipvanish,代码行数:8,代码来源:main.go

示例3: main

func main() {
	fmt.Println("I'm about to do work")
	s := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
	s.Prefix = "Doing the work... "
	s.Start()
	time.Sleep(2 * time.Second)
	s.Stop()
	fmt.Println("Done!")
}
开发者ID:yujinqiu,项目名称:spinner,代码行数:9,代码来源:2.go

示例4: main

func main() {
	s := spinner.New(spinner.CharSets[0], 100*time.Millisecond)
	s.Prefix = "Colors: "
	if err := s.Color("yellow"); err != nil {
		log.Fatalln(err)
	}
	s.Start()
	time.Sleep(4 * time.Second)
	if err := s.Color("red"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[20])
	s.Reverse()
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("blue"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[3])
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("cyan"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[28])
	s.Reverse()
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("green"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[25])
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("magenta"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[32])
	s.Restart()
	time.Sleep(4 * time.Second)
	if err := s.Color("white"); err != nil {
		log.Fatalln(err)
	}
	s.UpdateCharSet(spinner.CharSets[31])
	s.Restart()
	time.Sleep(4 * time.Second)
	s.Stop()
	println("")
}
开发者ID:yujinqiu,项目名称:spinner,代码行数:49,代码来源:app.go

示例5: init

func init() {
	Binary = filepath.Base(os.Args[0])
	Exiter = os.Exit
	Querier = queryExecCommand
	Runner = runExecCommand
	Spinner = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
	Tagger = tagTimeUnix
	Writer = ioutil.WriteFile

	cli.AppHelpTemplate = `{{.Name}}: {{.Usage}}

Usage:
  {{.Name}} <command> [args...]

Subcommands: ({{.Name}} help <subcommand>)
  {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
  {{end}}{{if .VisibleFlags}}
Options:
  {{range .VisibleFlags}}{{.}}
  {{end}}{{end}}
`

	cli.CommandHelpTemplate = fmt.Sprintf(`%s {{.FullName}}: {{.Description}}

Usage:
  %s {{.FullName}} {{.Usage}}
{{if .Subcommands}}
Subcommands: (%s {{.FullName}} help <subcommand>)
  {{range .Subcommands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
  {{end}}{{end}}{{if .VisibleFlags}}
Options:
   {{range .VisibleFlags}}{{.}}
   {{end}}{{ end }}
`, Binary, Binary, Binary)

	cli.SubcommandHelpTemplate = `{{.Name}}: {{.Usage}}

Usage:
  {{.Name}} <command> [args...]

Subcommands: ({{.Name}} help <subcommand>)
  {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Description}}
  {{end}}{{if .VisibleFlags}}
Options:
  {{range .VisibleFlags}}{{.}}
  {{end}}{{end}}
`
}
开发者ID:gmelika,项目名称:rack,代码行数:48,代码来源:stdcli.go

示例6: Spin

func Spin(fm Steps) error {
	for _, fn := range fm {
		s := spinner.New(spinner.CharSets[9], time.Millisecond*100)
		s.Prefix = fmt.Sprintf("%s: ", fn.Prefix)
		s.Start()
		err := fn.Action()
		s.Stop()
		if err != nil {
			fmt.Printf("\r%s: ERROR!\n", fn.Prefix)
			return err
		} else {
			fmt.Printf("\r%s: done\n", fn.Prefix)
		}
	}

	return nil
}
开发者ID:djui,项目名称:dlite,代码行数:17,代码来源:spinner.go

示例7: Spin

func Spin(fm FunctionMap) error {
	for prefix, fn := range fm {
		s := spinner.New(spinner.CharSets[9], time.Millisecond*100)
		s.Prefix = fmt.Sprintf("%s: ", prefix)
		s.Start()
		err := fn()
		s.Stop()
		if err != nil {
			fmt.Printf("\r%s: ERROR - %s\n", prefix, err)
			return err
		} else {
			fmt.Printf("\r%s: done\n", prefix)
		}
	}

	return nil
}
开发者ID:Enproduktion,项目名称:dlite,代码行数:17,代码来源:spinner.go

示例8: installPackage

func installPackage(repo string) error {
	wd, err := os.Getwd()
	if err != nil {
		return errors.Trace(err)
	}

	gopath := os.Getenv("GOPATH")
	packageDir := path.Join(gopath, "src", getRealRepoPath(repo))

	defer func() {
		_ = os.Chdir(wd)
	}()

	err = os.Chdir(packageDir)
	if err != nil {
		return errors.Trace(err)
	}

	var s *spinner.Spinner

	if Verbose {
		s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
		s.Prefix = fmt.Sprintf("  - installing package %s ", repo)
		s.Color("green")
		s.Start()
	}

	goInstallCommand := []string{"go", "install", repo}
	goInstallOutput, err := exec.Command(goInstallCommand[0], goInstallCommand[1:]...).CombinedOutput()

	if Verbose {
		s.Stop()
		fmt.Printf("\r  - installing package %s ... %s\n", repo, color.GreenString("done"))
	}

	if err != nil {
		return errors.Annotatef(err, "failed installing package %s, error: %s, output: %s", repo, goInstallOutput)
	}

	return nil
}
开发者ID:abutre,项目名称:bunch,代码行数:41,代码来源:packages.go

示例9: spin

func spin(prefix string, f func() error) *cli.ExitError {
	spin := spinner.New(spinner.CharSets[9], time.Millisecond*100)
	spin.Prefix = fmt.Sprintf("%s: ", prefix)
	spin.Start()
	err := f()
	spin.Stop()
	if err != nil {
		cliError, ok := err.(*cli.ExitError)
		if ok {
			if cliError.ExitCode() != 0 {
				fmt.Printf("\r%s: ERROR!\n", prefix)
				return cliError
			}

			fmt.Printf("\r%s: done\n", prefix)
			return cli.NewExitError("", 0)
		}
		fmt.Printf("\r%s: ERROR!\n", prefix)
		return cli.NewExitError(err.Error(), 1)
	}

	fmt.Printf("\r%s: done\n", prefix)
	return cli.NewExitError("", 0)
}
开发者ID:nlf,项目名称:dlite,代码行数:24,代码来源:ui.go

示例10: fetchPackage

func fetchPackage(repo string) error {
	wd, err := os.Getwd()
	if err != nil {
		return errors.Trace(err)
	}

	gopath := os.Getenv("GOPATH")
	packageDir := path.Join(gopath, "src", getRealRepoPath(repo))

	if _, err := os.Stat(packageDir); err != nil {
		if os.IsNotExist(err) {
			var s *spinner.Spinner
			if Verbose {
				s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
				s.Prefix = fmt.Sprintf("fetching %s ", repo)
				s.Color("green")
				s.Start()
			}

			goGetCommand := []string{"go", "get", "-d", repo}
			goGetCmd := exec.Command(goGetCommand[0], goGetCommand[1:]...)
			err := goGetCmd.Run()

			if Verbose {
				s.Stop()
			}

			if err != nil {
				return errors.Annotatef(err, "failed cloning repo for package %s", repo)
			} else {
				if Verbose {
					fmt.Printf("\rfetching %s ... %s\n", repo, color.GreenString("done"))
				}
			}

			return nil
		}
	}

	defer func() {
		_ = os.Chdir(wd)
	}()

	packageDir, err = getPackageRootDir(getRealRepoPath(repo))
	if err != nil {
		return errors.Trace(err)
	}

	err = os.Chdir(packageDir)
	if err != nil {
		return errors.Trace(err)
	}

	var s *spinner.Spinner
	if Verbose {
		s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
		s.Prefix = fmt.Sprintf("refreshing %s ", repo)
		s.Color("green")
		s.Start()
	}

	var refreshCommand []string

	if exists, _ := pathExists(path.Join(packageDir, ".git")); exists {
		refreshCommand = []string{"git", "fetch", "--all"}
	} else if exists, _ := pathExists(path.Join(packageDir, ".hg")); exists {
		refreshCommand = []string{"hg", "pull"}
	} else if exists, _ := pathExists(path.Join(packageDir, ".bzr")); exists {
		refreshCommand = []string{"bzr", "pull"}
	} else if exists, _ := pathExists(path.Join(packageDir, ".svn")); exists {
		refreshCommand = []string{"svn", "up"}
	}

	if len(refreshCommand) > 0 {
		refreshOutput, err := exec.Command(refreshCommand[0], refreshCommand[1:]...).CombinedOutput()

		if Verbose {
			s.Stop()
			fmt.Printf("\rrefreshing %s ... %s\n", repo, color.GreenString("done"))
		}

		if err != nil {
			return errors.Annotatef(err, "failed updating repo for package %s, output: %s", repo, refreshOutput)
		}
	} else {
		if Verbose {
			s.Stop()
			fmt.Printf("\rrefreshing %s ... %s\n", repo, color.YellowString("skipped"))
		}
	}

	return nil
}
开发者ID:abutre,项目名称:bunch,代码行数:93,代码来源:packages.go

示例11: setPackageVersion

func setPackageVersion(repo string, version string, humanVersion string) error {
	if version == "" {
		return nil
	}

	wd, err := os.Getwd()
	if err != nil {
		return errors.Trace(err)
	}

	packageDir, err := getPackageRootDir(getRealRepoPath(repo))
	if err != nil {
		return errors.Trace(err)
	}

	defer func() {
		_ = os.Chdir(wd)
	}()

	err = os.Chdir(packageDir)
	if err != nil {
		return errors.Trace(err)
	}

	var checkoutCommand []string
	if exists, _ := pathExists(".git"); exists {
		checkoutCommand = []string{"git", "checkout", version}
	} else if exists, _ := pathExists(".hg"); exists {
		checkoutCommand = []string{"hg", "update", "-c", version}
	} else if exists, _ := pathExists(".bzr"); exists {
		if version != "" {
			checkoutCommand = []string{"bzr", "update", "-r", version}
		} else {
			checkoutCommand = []string{"bzr", "update"}
		}
	} else {
		if Verbose {
			fmt.Printf("  - setting version of %s to %s (resolved as %s) ... %s\n", repo, humanVersion, version, color.GreenString("skipped, unknown repo type"))
		}
		return nil
	}

	var s *spinner.Spinner

	if Verbose {
		s = spinner.New(spinner.CharSets[SpinnerCharSet], SpinnerInterval)
		s.Prefix = fmt.Sprintf("  - setting version of %s to %s (resolved as %s) ", repo, humanVersion, version)
		s.Color("green")
		s.Start()
	}

	checkoutOutput, err := exec.Command(checkoutCommand[0], checkoutCommand[1:]...).CombinedOutput()

	if Verbose {
		s.Stop()
		fmt.Printf("\r  - setting version of %s to %s (resolved as %s) ... %s\n", repo, humanVersion, version, color.GreenString("done"))
	}

	if err != nil {
		return errors.Annotatef(err, "failed setting version of package %s, error: %s, output: %s", repo, checkoutOutput)
	}

	return nil
}
开发者ID:abutre,项目名称:bunch,代码行数:64,代码来源:packages.go

示例12:

	"os/signal"
	"strconv"
	"syscall"
	"time"
)

//func init() {
//	listCmd.AddCommand(listDraftsCmd)
//}

type response struct {
	addr *net.IPAddr
	rtt  time.Duration
}

var spin = spinner.New(spinner.CharSets[34], 100*time.Millisecond)

var pingCmd = &cobra.Command{
	Use:   "ping",
	Short: "List top 5 servers (by latency)",
	Long:  `List all of the drafts in your content directory.`,
	PreRun: func(cmd *cobra.Command, args []string) {
		spin.Prefix = "Scanning: "
		spin.FinalMSG = "Finished..."
		spin.Color("green")
		spin.Start()
	},
	PostRun: func(cmd *cobra.Command, args []string) {
		spin.Stop()
	},
	Run: func(cmd *cobra.Command, args []string) {
开发者ID:organicelement,项目名称:ipvanish,代码行数:31,代码来源:ping.go

示例13: main

func main() {
	// Create spinner
	spinner := spinner.New(spinner.CharSets[14], 100*time.Millisecond)
	spinner.Color("cyan")
	spinner.Start()

	// First read arguments
	args, argError := util.ParseArguments()
	if argError != nil {
		spinner.Stop()
		fmt.Println(argError.Error())
		return
	}

	// Then read configuration
	config, configError := util.ParseConfiguration(*args.ConfigPath)
	if configError != nil {
		spinner.Stop()
		fmt.Println(configError.Error())
		return
	}

	// Create vmrun wrapper
	var vmrun vmware.VmrunWrapper
	vmrun = vmware.NewCLIVmrun(config.Vmrun)

	// Create output buffer
	buffer := new(bytes.Buffer)

	// Switch commands
	switch args.Command {
	case util.VerifyCommand:
		err := controller.Verify(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Println(err.Error())
			return
		}
	case util.StatusCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Status(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Println(err.Error())
			return
		}
	case util.UseCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Use(buffer, vmrun, config, args.CommandIntParameter)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	case util.StartCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Start(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	case util.StopCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Stop(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
			return
		}
	case util.SnapshotCommand:
		if controller.Verify(nil, vmrun, config) != nil {
			spinner.Stop()
			fmt.Println("Failed to verify settings. Please run 'verify' to get more details")
			return
		}
		err := controller.Snapshot(buffer, vmrun, config)
		if err != nil {
			spinner.Stop()
			fmt.Print(buffer.String())
			fmt.Println(err.Error())
//.........这里部分代码省略.........
开发者ID:ankoh,项目名称:vmlcm,代码行数:101,代码来源:main.go

示例14: NewTechCrunch

func NewTechCrunch() *TechCrunch {
	return &TechCrunch{page: 1, debug: debug.Debug(name), spinner: spinner.New(spinner.CharSets[14], 100*time.Millisecond)}
}
开发者ID:umayr,项目名称:goof,代码行数:3,代码来源:techcrunch.go


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