Beispiel #1
0
func printTable2(c *clif.Command, out clif.Output) {
	out.Printf("<headline>Generating table</headline>\n\n")
	headers := []string{"Name", "Age", "Force"}
	var table *clif.Table
	if c.Option("open").Bool() {
		table = out.Table(headers, clif.OpenTableStyleLight)
	} else {
		table = out.Table(headers)
	}
	users := [][]string{
		{
			"<important>Yoda<reset>",
			"Very, very old",
			"Like the uber guy",
		},
		{
			"<important>Luke Skywalker<reset>",
			"Not that old",
			"A bit, but not that much",
		},
		{
			"<important>Anakin Skywalker<reset>",
			"Old dude",
			"He is Lukes father! Was kind of stronger in 1-3, but still failed to" +
				" kill Jar Jar Binks. Not even tried, though. What's with that?",
		},
	}
	for _, user := range users {
		table.AddRow(user)
	}
	fmt.Println(table.Render(c.Option("render-width").Int()))
}
Beispiel #2
0
func printTable1(c *clif.Command, out clif.Output) {
	headers := []string{"H1", "H2", "H3"}
	var table *clif.Table
	if c.Option("open").Bool() {
		table = out.Table(headers, clif.OpenTableStyle)
	} else {
		table = out.Table(headers)
	}
	table.AddRows([][]string{
		[]string{"foo", "bar", "baz"},
		[]string{"yadda", "yadda", "yadda"},
		[]string{"Some crazy multi line content + Some crazy multi line content + Some crazy multi line content", "yadda", "yadda"},
		[]string{"yadda", "Some crazy multi line content + Some crazy multi line content + Some crazy multi line content", "yadda"},
		[]string{"yadda", "yadda", "Some crazy multi line content + Some crazy multi line content + Some crazy multi line content"},
		[]string{"Some <info>crazy multi line content + Some crazy multi line content + Some crazy<reset> multi line content", "yadda", "yadda"},
		[]string{"yadda", "Some <info>crazy multi line content + Some crazy multi line content + Some crazy<reset> multi line content", "yadda"},
		[]string{"yadda", "yadda", "Some <info>crazy multi line content + Some crazy multi line content + Some crazy<reset> multi line content"},
	})
	fmt.Println(table.Render(c.Option("render-width").Int()))
}
Beispiel #3
0
func cmdProgress3(c *clif.Command, out clif.Output) {
	pbs := out.ProgressBars()
	pbs.Style(clif.ProgressBarStyleAscii)
	if width := c.Option("width").Int(); width > 0 {
		pbs.Width(width)
	}
	pb, _ := pbs.Init("default", 200)
	interval := c.Option("interval").Int()
	pbs.Start()
	var wg sync.WaitGroup
	wg.Add(1)
	go func(b clif.ProgressBar) {
		defer wg.Done()
		for i := 0; i < 200; i++ {
			b.Increment()
			<-time.After(time.Millisecond * time.Duration(interval))
		}
	}(pb)
	wg.Wait()
	<-pbs.Finish()
}
Beispiel #4
0
func printProgress(c *clif.Command, count int, out clif.Output) {
	out.Printf("<headline>Progressing</headline>\n")
	var wg sync.WaitGroup
	pb := out.ProgressBars()
	if width := c.Option("width").Int(); width > 0 {
		pb.Width(width)
	}
	interval := c.Option("interval").Int()
	style := clif.ProgressBarStyleUtf8
	if c.Option("ascii-style").Bool() {
		style = clif.ProgressBarStyleAscii
	}
	style.Count = clif.PROGRESS_BAR_ADDON_APPEND
	style.Estimate = clif.PROGRESS_BAR_ADDON_PREPEND
	pb.Style(style)
	pb.Start()
	for i := 0; i < count; i++ {
		name := fmt.Sprintf("bar%d", i)
		bar, _ := pb.Init(name, 200)
		wg.Add(1)
		go func(b clif.ProgressBar, t int) {
			defer wg.Done()
			for i := 0; i < 200; i++ {
				b.Increment()
				//<-time.After(time.Millisecond * time.Duration((t+1)*3))
				<-time.After(time.Millisecond * time.Duration(interval*(t+1)))
			}
		}(bar, i)
	}
	wg.Wait()
	pb.Finish()
}
Beispiel #5
0
func cmdProgress4(c *clif.Command, out clif.Output) {
	pbs := out.ProgressBars()
	if width := c.Option("width").Int(); width > 0 {
		pbs.Width(width)
	}
	interval := c.Option("interval").Int()
	pbs.Start()
	var wg sync.WaitGroup
	amount := c.Option("amount").Int()
	for i := 0; i < amount; i++ {
		wg.Add(1)
		pb, _ := pbs.Init(fmt.Sprintf("bar-%d", i+1), 200)
		go func(b clif.ProgressBar, ii int) {
			defer wg.Done()
			for i := 0; i < 200; i++ {
				b.Increment()
				<-time.After(time.Millisecond * time.Duration(interval*ii))
			}
		}(pb, i)
	}
	wg.Wait()
	<-pbs.Finish()
}
Beispiel #6
0
func cmdProgress2(c *clif.Command, out clif.Output) {
	amount := c.Option("amount").Int()
	printProgress(c, amount, out)
}