本文整理汇总了Golang中text/tabwriter.Writer.Init方法的典型用法代码示例。如果您正苦于以下问题:Golang Writer.Init方法的具体用法?Golang Writer.Init怎么用?Golang Writer.Init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类text/tabwriter.Writer
的用法示例。
在下文中一共展示了Writer.Init方法的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()
}
示例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)
}
示例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()
}
}
示例4: Print
func (a analytics) Print() {
since := time.Since(a.lastAPIReset)
callsPerSec := float64(a.apiCount) / since.Seconds()
glog.Infof("Made %d API calls since the last Reset %f calls/sec", a.apiCount, callsPerSec)
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)
fmt.Fprintf(w, "RemoveLabels\t%d\t\n", a.RemoveLabels)
fmt.Fprintf(w, "ListCollaborators\t%d\t\n", a.ListCollaborators)
fmt.Fprintf(w, "ListIssues\t%d\t\n", a.ListIssues)
fmt.Fprintf(w, "ListIssueEvents\t%d\t\n", a.ListIssueEvents)
fmt.Fprintf(w, "ListCommits\t%d\t\n", a.ListCommits)
fmt.Fprintf(w, "GetCommit\t%d\t\n", a.GetCommit)
fmt.Fprintf(w, "GetCombinedStatus\t%d\t\n", a.GetCombinedStatus)
fmt.Fprintf(w, "GetPR\t%d\t\n", a.GetPR)
fmt.Fprintf(w, "AssignPR\t%d\t\n", a.AssignPR)
fmt.Fprintf(w, "ClosePR\t%d\t\n", a.ClosePR)
fmt.Fprintf(w, "OpenPR\t%d\t\n", a.OpenPR)
fmt.Fprintf(w, "GetContents\t%d\t\n", a.GetContents)
fmt.Fprintf(w, "CreateComment\t%d\t\n", a.CreateComment)
fmt.Fprintf(w, "Merge\t%d\t\n", a.Merge)
w.Flush()
glog.V(2).Infof("\n%v", buf)
}
示例5: getTabOutWithWriter
func getTabOutWithWriter(writer io.Writer) *tabwriter.Writer {
aTabOut := new(tabwriter.Writer)
aTabOut.Init(writer, 0, 8, 1, '\t', 0)
return aTabOut
}
示例6: main
func main() {
multicall.Add("acbuild-script", func() error {
cmd := exec.Command("acbuild", append([]string{"script"}, os.Args[1:]...)...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
})
// check if acbuild is executed with a multicall command
multicall.MaybeExec()
cmdAcbuild.SetUsageFunc(func(cmd *cobra.Command) error {
tabOut := new(tabwriter.Writer)
tabOut.Init(os.Stdout, 0, 8, 1, '\t', 0)
commandUsageTemplate.Execute(tabOut, cmd)
tabOut.Flush()
return nil
})
// Make help just show the usage
cmdAcbuild.SetHelpTemplate(`{{.UsageString}}`)
err := cmdAcbuild.Execute()
if cmdExitCode == 0 && err != nil {
cmdExitCode = getErrorCode(errCobra)
}
os.Exit(cmdExitCode)
}
示例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()
}
示例8: 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
}
示例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
}
示例10: printNodesets
func (c *RollingUpdateClusterCmd) printNodesets(nodesets map[string]*kutil.Nodeset) error {
w := new(tabwriter.Writer)
var b bytes.Buffer
// Format in tab-separated columns with a tab stop of 8.
w.Init(os.Stdout, 0, 8, 0, '\t', tabwriter.StripEscape)
for _, n := range nodesets {
b.WriteByte(tabwriter.Escape)
b.WriteString(n.Name)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(n.Status)
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(fmt.Sprintf("%d", len(n.NeedUpdate)))
b.WriteByte(tabwriter.Escape)
b.WriteByte('\t')
b.WriteByte(tabwriter.Escape)
b.WriteString(fmt.Sprintf("%d", len(n.Ready)))
b.WriteByte(tabwriter.Escape)
b.WriteByte('\n')
_, err := w.Write(b.Bytes())
if err != nil {
return fmt.Errorf("error writing to output: %v", err)
}
b.Reset()
}
return w.Flush()
}
示例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()
}
示例12: 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()
}
示例13: 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
}
示例14: 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
}
示例15: outputPluginResults
func outputPluginResults(w io.Writer, byt []byte) error {
var results []struct {
ID uint64
Name string
Description sql.NullString
Path string
DownloadCount uint64
Similarity float64
}
if err := json.Unmarshal(byt, &results); err != nil {
return err
}
writer := tabwriter.Writer{}
writer.Init(w, 0, 8, 1, '\t', 0)
_, err := writer.Write([]byte("NAME\tDESCRIPTION\tDOWNLOADS\n"))
if err != nil {
return err
}
for _, result := range results {
d := result.Description
if len(d.String) >= 30 {
d.String = d.String[:27] + "..."
}
_, err = writer.Write([]byte(fmt.Sprintf("%s\t%s\t%d\n",
result.Name, d.String, result.DownloadCount)))
if err != nil {
return err
}
}
return writer.Flush()
}