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


Golang tabwriter.Writer类代码示例

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


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

示例1: Tablify

func Tablify(writer io.Writer, headings []string, rowfunc func() []string) {
	w := new(tabwriter.Writer)
	w.Init(writer, 5, 0, 3, ' ', 0)

	dorow := func(cells []string) {
		fmt.Fprintln(w, strings.Join(cells, "\t"))
	}

	if headings != nil {
		dorow(headings)
		seps := make([]string, len(headings), len(headings))
		for i, h := range headings {
			seps[i] = strings.Repeat("=", len(h)+1)
		}
		dorow(seps)
	}

	for {
		row := rowfunc()
		if row == nil {
			break
		}
		dorow(row)
	}

	w.Flush()
}
开发者ID:paul-pearce,项目名称:client-beta,代码行数:27,代码来源:tablify.go

示例2: print

func (a analytics) print() {
	glog.Infof("Made %d API calls since the last Reset %f calls/sec", a.apiCount, a.apiPerSec)

	buf := new(bytes.Buffer)
	w := new(tabwriter.Writer)
	w.Init(buf, 0, 0, 1, ' ', tabwriter.AlignRight)
	fmt.Fprintf(w, "AddLabels\t%d\t\n", a.AddLabels.Count)
	fmt.Fprintf(w, "RemoveLabels\t%d\t\n", a.RemoveLabels.Count)
	fmt.Fprintf(w, "ListCollaborators\t%d\t\n", a.ListCollaborators.Count)
	fmt.Fprintf(w, "GetIssue\t%d\t\n", a.GetIssue.Count)
	fmt.Fprintf(w, "ListIssues\t%d\t\n", a.ListIssues.Count)
	fmt.Fprintf(w, "ListIssueEvents\t%d\t\n", a.ListIssueEvents.Count)
	fmt.Fprintf(w, "ListCommits\t%d\t\n", a.ListCommits.Count)
	fmt.Fprintf(w, "GetCommit\t%d\t\n", a.GetCommit.Count)
	fmt.Fprintf(w, "GetCombinedStatus\t%d\t\n", a.GetCombinedStatus.Count)
	fmt.Fprintf(w, "SetStatus\t%d\t\n", a.SetStatus.Count)
	fmt.Fprintf(w, "GetPR\t%d\t\n", a.GetPR.Count)
	fmt.Fprintf(w, "AssignPR\t%d\t\n", a.AssignPR.Count)
	fmt.Fprintf(w, "ClosePR\t%d\t\n", a.ClosePR.Count)
	fmt.Fprintf(w, "OpenPR\t%d\t\n", a.OpenPR.Count)
	fmt.Fprintf(w, "GetContents\t%d\t\n", a.GetContents.Count)
	fmt.Fprintf(w, "ListComments\t%d\t\n", a.ListComments.Count)
	fmt.Fprintf(w, "CreateComment\t%d\t\n", a.CreateComment.Count)
	fmt.Fprintf(w, "DeleteComment\t%d\t\n", a.DeleteComment.Count)
	fmt.Fprintf(w, "Merge\t%d\t\n", a.Merge.Count)
	fmt.Fprintf(w, "GetUser\t%d\t\n", a.GetUser.Count)
	fmt.Fprintf(w, "SetMilestone\t%d\t\n", a.SetMilestone.Count)
	fmt.Fprintf(w, "ListMilestones\t%d\t\n", a.ListMilestones.Count)
	w.Flush()
	glog.V(2).Infof("\n%v", buf)
}
开发者ID:timstclair,项目名称:kube-contrib,代码行数:31,代码来源:github.go

示例3: enumerate

func (c *clusterClient) enumerate(context *cli.Context) {
	c.clusterOptions(context)
	jsonOut := context.GlobalBool("json")
	outFd := os.Stdout
	fn := "enumerate"

	cluster, err := c.manager.Enumerate()
	if err != nil {
		cmdError(context, fn, err)
		return
	}

	if jsonOut {
		fmtOutput(context, &Format{Cluster: &cluster})
	} else {
		w := new(tabwriter.Writer)
		w.Init(outFd, 12, 12, 1, ' ', 0)

		fmt.Fprintln(w, "ID\t IMAGE\t STATUS\t NAMES\t NODE")
		for _, n := range cluster.Nodes {
			for _, c := range n.Containers {
				fmt.Fprintln(w, c.ID, "\t", c.Image, "\t", c.Status, "\t",
					c.Names, "\t", n.Ip)
			}
		}

		fmt.Fprintln(w)
		w.Flush()
	}
}
开发者ID:mike6350,项目名称:openstorage,代码行数:30,代码来源:cluster.go

示例4: printCommandPrefixHelp

func printCommandPrefixHelp(ctx cli.Context, prefix ...string) {
	handler := getHandler(ctx.Handlers(), prefix)

	if handler == nil {
		ExitF("Command not found")
	}

	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 0, 3, ' ', 0)

	fmt.Fprintf(w, "%s\n", handler.Description)
	fmt.Fprintf(w, "%s %s\n", Name, handler.Pattern)
	for _, group := range handler.FlagGroups {
		fmt.Fprintf(w, "\n%s:\n", group.Name)
		for _, flag := range group.Flags {
			boolFlag, isBool := flag.(cli.BoolFlag)
			if isBool && boolFlag.OmitValue {
				fmt.Fprintf(w, "  %s\t%s\n", strings.Join(flag.GetPatterns(), ", "), flag.GetDescription())
			} else {
				fmt.Fprintf(w, "  %s <%s>\t%s\n", strings.Join(flag.GetPatterns(), ", "), flag.GetName(), flag.GetDescription())
			}
		}
	}

	w.Flush()
}
开发者ID:RandomArray,项目名称:gdrive,代码行数:26,代码来源:handlers_meta.go

示例5: Execute

func (lt *ListTasksCommand) Execute(args []string) error {
	ac, _, err := getAPIClient(lt.GlobalOpts)
	if err != nil {
		return err
	}
	notifyUserUpdate(ac)
	var tasks []model.ProjectTask
	if lt.Project != "" {
		tasks, err = ac.ListTasks(lt.Project)
		if err != nil {
			return err
		}
	} else if lt.File != "" {
		project, err := loadLocalConfig(lt.File)
		if err != nil {
			return err
		}
		tasks = project.Tasks
	} else {
		return fmt.Errorf("must specify a project with -p/--project or a path to a config file with -f/--file")
	}
	fmt.Println(len(tasks), "tasks:")
	w := new(tabwriter.Writer)
	w.Init(os.Stdout, 0, 8, 0, '\t', 0)
	for _, t := range tasks {
		line := fmt.Sprintf("\t%v\t", t.Name)
		fmt.Fprintln(w, line)
	}
	w.Flush()
	return nil

}
开发者ID:pritten,项目名称:evergreen,代码行数:32,代码来源:patch.go

示例6: DescribeParameters

// DescribeParameters prints out information about the parameters of a template
func (d *TemplateDescriber) DescribeParameters(params []templateapi.Parameter, out *tabwriter.Writer) {
	formatString(out, "Parameters", " ")
	indent := "    "
	for _, p := range params {
		formatString(out, indent+"Name", p.Name)
		if len(p.DisplayName) > 0 {
			formatString(out, indent+"Display Name", p.DisplayName)
		}
		if len(p.Description) > 0 {
			formatString(out, indent+"Description", p.Description)
		}
		formatString(out, indent+"Required", p.Required)
		if len(p.Generate) == 0 {
			formatString(out, indent+"Value", p.Value)
			continue
		}
		if len(p.Value) > 0 {
			formatString(out, indent+"Value", p.Value)
			formatString(out, indent+"Generated (ignored)", p.Generate)
			formatString(out, indent+"From", p.From)
		} else {
			formatString(out, indent+"Generated", p.Generate)
			formatString(out, indent+"From", p.From)
		}
		out.Write([]byte("\n"))
	}
}
开发者ID:rhamilto,项目名称:origin,代码行数:28,代码来源:describer.go

示例7: help

func help() {
	w := new(tabwriter.Writer)
	w.Init(os.Stderr, 4, 0, 2, ' ', 0)
	av0 := path.Base(os.Args[0])

	fmt.Fprintf(w, "Linux Tao Host\n")
	fmt.Fprintf(w, "Usage:\n")
	fmt.Fprintf(w, "  %s init [options]\t Initialize a new host\n", av0)
	fmt.Fprintf(w, "  %s show [options]\t Show host principal name\n", av0)
	fmt.Fprintf(w, "  %s start [options]\t Start the host\n", av0)
	fmt.Fprintf(w, "  %s stop [options]\t Request the host stop\n", av0)
	fmt.Fprintf(w, "\n")

	categories := []options.Category{
		{"all", "Basic options for most commands"},
		{"init", "Options for 'init' command"},
		{"start", "Options for 'start' command"},
		{"root", "Options for root hosts"},
		{"stacked", "Options for stacked hosts"},
		{"kvm", "Options for hosting QEMU/KVM CoreOS"},
		{"logging", "Options to control log output"},
	}
	options.ShowRelevant(w, categories...)

	w.Flush()
}
开发者ID:kevinawalsh,项目名称:cloudproxy,代码行数:26,代码来源:host.go

示例8: runLogins

func runLogins(cmd *Command, args []string) {
	active, _ := ActiveLogin()
	accounts, _ := Config.List("accounts")
	if len(accounts) == 0 {
		fmt.Println("no logins")
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 1, 0, 1, ' ', 0)

		for _, account := range accounts {
			if !strings.HasPrefix(account, ".") {
				var creds ForceCredentials
				data, err := Config.Load("accounts", account)
				json.Unmarshal([]byte(data), &creds)

				if err != nil {
					return
				}

				var banner = fmt.Sprintf("\t%s", creds.InstanceUrl)
				if account == active {
					account = fmt.Sprintf("\x1b[31;1m%s (active)\x1b[0m", account)
				} else {
					account = fmt.Sprintf("%s \x1b[31;1m\x1b[0m", account)
				}
				fmt.Fprintln(w, fmt.Sprintf("%s%s", account, banner))
			}
		}
		fmt.Fprintln(w)
		w.Flush()
	}

}
开发者ID:adamlincoln,项目名称:force,代码行数:33,代码来源:logins.go

示例9: printTaskList

// Prints out the output of tasks
func printTaskList(taskList []photon.Task, c *cli.Context) error {
	if c.GlobalIsSet("non-interactive") {
		for _, task := range taskList {
			fmt.Printf("%s\t%s\t%s\t%d\t%d\n", task.ID, task.State, task.Operation, task.StartedTime, task.EndTime-task.StartedTime)
		}
	} else if utils.NeedsFormatting(c) {
		utils.FormatObjects(taskList, os.Stdout, c)
	} else {
		w := new(tabwriter.Writer)
		w.Init(os.Stdout, 4, 4, 2, ' ', 0)
		fmt.Fprintf(w, "\nTask\tStart Time\tDuration\n")

		for _, task := range taskList {
			var duration int64
			startTime := timestampToString(task.StartedTime)
			if task.EndTime-task.StartedTime > 0 {
				duration = (task.EndTime - task.StartedTime) / 1000
			} else {
				duration = 0
			}
			fmt.Fprintf(w, "%s\t%s\t%.2d:%.2d:%.2d\n", task.ID, startTime, duration/3600, (duration/60)%60, duration%60)
			err := w.Flush()
			if err != nil {
				return err
			}
			fmt.Printf("%s, %s\n", task.Operation, task.State)
		}
		if len(taskList) > 0 {
			fmt.Printf("\nYou can run 'photon task show <id>' for more information\n")
		}
		fmt.Printf("Total: %d\n", len(taskList))
	}

	return nil
}
开发者ID:vmware,项目名称:photon-controller-cli,代码行数:36,代码来源:iohelpers.go

示例10: formatOutput

func formatOutput(s Stock) {
	w := new(tabwriter.Writer)

	w.Init(os.Stdout, 0, 8, 1, '\t', 0)

	fmt.Print("\033[2J\033[H")

	fmt.Fprintln(w, time.Now().Round(time.Second).String())

	var d Data
	v := reflect.ValueOf(d) // reflect lets us iterate on the struct

	var value, separator, header string

	for i := 0; i < v.NumField(); i++ {
		value = v.Type().Field(i).Name
		if i < (v.NumField() - 1) {
			separator = "\t"
		} else {
			separator = ""
		}

		// Print the header labels underlined
		header += fmt.Sprintf("\033[4m%s\033[0m%s", value, separator)
	}

	fmt.Fprintln(w, header)

	// run the stock through String()
	for _, stock := range s.Data {
		fmt.Fprintln(w, stock)
	}

	w.Flush()
}
开发者ID:investislife,项目名称:gostock-1,代码行数:35,代码来源:gostock.go

示例11: formatDNSRecords

// formatDNSRecords takes a list of DNS records and formats them as a table.
func formatDNSRecords(records []dnsimple.Record, domainName string) string {
	buf := new(bytes.Buffer)

	// initialize the tabwriter
	w := new(tabwriter.Writer)
	minWidth := 0
	tabWidth := 8
	padding := 3
	w.Init(buf, minWidth, tabWidth, padding, ' ', 0)

	for index, record := range records {

		// assemble the subdomain / domain name
		domainName := domainName
		if !isEmpty(record.Name) {
			domainName = record.Name + "." + domainName
		}

		fmt.Fprintf(w, "%s\t%s\t%s", domainName, record.RecordType, record.Content)

		// append newline if we are not
		// formatting the last record
		if index < len(records)-1 {
			fmt.Fprintf(w, "\n")
		}

	}

	w.Flush()

	return buf.String()
}
开发者ID:andreaskoch,项目名称:dee-cli,代码行数:33,代码来源:actionlist.go

示例12: selectHerokuApp

func selectHerokuApp(apps nameIDs, e *parsecli.Env) (*nameID, error) {
	fmt.Fprintf(e.Out, "Please select from the following Heroku apps: (Enter a number between 1 and %d)\n", len(apps))
	for i, app := range apps {
		w := new(tabwriter.Writer)
		w.Init(e.Out, 0, 8, 0, '\t', 0)
		fmt.Fprintf(w, "%d: %s\t\t(%s)\n", i+1, app.name, app.id)
		if err := w.Flush(); err != nil {
			return nil, stackerr.Wrap(err)
		}
	}
	fmt.Fprintf(e.Out, "Selection: ")
	var selection string
	fmt.Fscanf(e.In, "%s\n", &selection)

	n, err := strconv.Atoi(selection)
	if err != nil {
		return nil, err
	}

	lapps := len(apps)
	if n <= 0 || n > lapps {
		return nil, stackerr.Newf("Invalid selection: can only be in range 1..%d", lapps)
	}
	return &apps[n-1], nil
}
开发者ID:jinkawin,项目名称:parse-cli,代码行数:25,代码来源:add.go

示例13: GenerateReport

//Given a Certificates list, create a tabular report of
//the relevant information in string format
func GenerateReport(certs CertificateInfoList, warningsOnly bool) string {
	sort.Sort(certs)
	pReader, pWriter := io.Pipe()
	var buff bytes.Buffer
	reportWriter := new(tabwriter.Writer)
	reportWriter.Init(pWriter, 0, 8, 0, '\t', 0)
	fmt.Fprintln(reportWriter, "Site\tCommon Name\tStatus\t   \tDays Left\tExpire Date")
	expiredCount := 0
	for _, cert := range certs {
		if cert != nil {
			eDate := cert.cert.NotAfter
			var expired string
			if IsExpired(eDate) {
				expired = "Expired"
				expiredCount++
			} else {
				expired = "Valid"
			}
			daysToExpire := GetExpireDays(eDate)
			cn := cert.cert.Subject.CommonName
			if (warningsOnly && IsExpired(eDate)) || !warningsOnly {
				fmt.Fprintf(reportWriter, "%s\t%s\t%s\t   \t%d\t%s\n", cert.name, cn, expired, daysToExpire, eDate.Local())
			}
		}
	}
	if expiredCount == 0 && warningsOnly {
		return ""
	}
	go buff.ReadFrom(pReader)
	reportWriter.Flush()
	pWriter.Close()
	pReader.Close()
	return buff.String()
}
开发者ID:rossdylan,项目名称:sslcheck,代码行数:36,代码来源:sslcheck.go

示例14: run

func (r *releasesCmd) run(e *env, c *client) error {
	u := &url.URL{
		Path: "releases",
	}
	var releasesList []releasesResponse
	if _, err := e.Client.Get(u, &releasesList); err != nil {
		return stackerr.Wrap(err)
	}

	if r.version != "" {
		return r.printFiles(r.version, releasesList, e)
	}

	w := new(tabwriter.Writer)
	w.Init(e.Out, 32, 8, 0, ' ', 0)
	fmt.Fprintln(w, "Name\tDescription\tDate")
	for _, release := range releasesList {
		description := "No release notes given"
		if release.Description != "" {
			description = release.Description
		}
		fmt.Fprintf(w, "%s\t%s\t%s\n", release.Version, description, release.Timestamp)
	}
	w.Flush()
	return nil
}
开发者ID:WilliamRen,项目名称:parse-cli,代码行数:26,代码来源:releases_cmd.go

示例15: printOther

func printOther(w *tabwriter.Writer, comps map[string]*Component) {
	var keys sort.StringSlice

	for refdes := range comps {
		keys = append(keys, refdes)
	}

	if len(keys) > 0 {
		sort.Sort(keys)

		fmt.Fprintf(w, "##### Other #####\n\n")
		w.Flush()

		fmt.Fprintf(w, "REFDES\tDEVICE\tFOOTPRINT\tAPPLICATION DESCRIPTION\n")

		for _, refdes := range keys {
			comp := comps[refdes]
			//comp.loadSymAttrs()

			fmt.Fprintf(w, "%s\t%s\t%s\t%s\n", refdes, comp.attrs["device"], comp.attrs["footprint"], comp.attrs["x-appdesc"])

			//delete(comps, refdes)
		}

		fmt.Fprintf(w, "\n\n")
		w.Flush()
	}
}
开发者ID:kierdavis,项目名称:k12,代码行数:28,代码来源:partlist.go


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