Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
replace custom table with a library based on default tabwriter
  • Loading branch information
Massimiliano Pippi committed Aug 28, 2019
commit 7c871976910fecf612842c3af31e595f6af7ae93
48 changes: 28 additions & 20 deletions cli/board/details.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package board

import (
"context"
"fmt"
"os"

"github.com/arduino/arduino-cli/cli/errorcodes"
Expand All @@ -28,6 +27,7 @@ import (
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/cheynewallace/tabby"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -56,33 +56,41 @@ func runDetailsCommand(cmd *cobra.Command, args []string) {
}

func outputDetailsResp(details *rpc.BoardDetailsResp) {
table := output.NewTable()
table.SetColumnWidthMode(1, output.Average)
table.AddRow("Board name:", details.Name)
// Table is 5 columns wide:
// | | | | |
// Board name: Arduino Nano
//
// Required tools: arduino:avr-gcc 5.4.0-atmel3.6.1-arduino2
// arduino:avrdude 6.3.0-arduino14
// arduino:arduinoOTA 1.2.1
//
// Option: Processor cpu
// ATmega328P * cpu=atmega328
// ATmega328P (Old Bootloader) cpu=atmega328old
// ATmega168 cpu=atmega168
table := tabby.New()

table.AddLine("Board name:", details.Name, "")

for i, tool := range details.RequiredTools {
head := ""
if i == 0 {
table.AddRow()
head = "Required tools:"
table.AddLine("", "", "", "") // get some space from above
table.AddLine("Required tools:", tool.Packager+":"+tool.Name, "", tool.Version)
continue
}
table.AddRow(head, tool.Packager+":"+tool.Name, "", tool.Version)
table.AddLine("", tool.Packager+":"+tool.Name, "", tool.Version)
}

for _, option := range details.ConfigOptions {
table.AddRow()
table.AddRow("Option:",
option.OptionLabel,
"", option.Option)
table.AddLine("", "", "", "") // get some space from above
table.AddLine("Option:", option.OptionLabel, "", option.Option)
for _, value := range option.Values {
checked := ""
if value.Selected {
table.AddRow("",
output.Green(value.ValueLabel),
output.Green("✔"), output.Green(option.Option+"="+value.Value))
} else {
table.AddRow("",
value.ValueLabel,
"", option.Option+"="+value.Value)
checked = "✔"
}
table.AddLine("", value.ValueLabel, checked, option.Option+"="+value.Value)
}
}
fmt.Print(table.Render())
table.Print()
}
13 changes: 7 additions & 6 deletions cli/board/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package board

import (
"fmt"
"os"
"sort"
"time"
Expand All @@ -29,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/cheynewallace/tabby"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -81,8 +81,9 @@ func outputListResp(ports []*rpc.DetectedPort) {
return x.GetProtocol() < y.GetProtocol() ||
(x.GetProtocol() == y.GetProtocol() && x.GetAddress() < y.GetAddress())
})
table := output.NewTable()
table.SetHeader("Port", "Type", "Board Name", "FQBN")

table := tabby.New()
table.AddHeader("Port", "Type", "Board Name", "FQBN")
for _, port := range ports {
address := port.GetProtocol() + "://" + port.GetAddress()
if port.GetProtocol() == "serial" {
Expand All @@ -97,16 +98,16 @@ func outputListResp(ports []*rpc.DetectedPort) {
for _, b := range boards {
board := b.GetName()
fqbn := b.GetFQBN()
table.AddRow(address, protocol, board, fqbn)
table.AddLine(address, protocol, board, fqbn)
// show address and protocol only on the first row
address = ""
protocol = ""
}
} else {
board := "Unknown"
fqbn := ""
table.AddRow(address, protocol, board, fqbn)
table.AddLine(address, protocol, board, fqbn)
}
}
fmt.Print(table.Render())
table.Print()
}
10 changes: 5 additions & 5 deletions cli/board/listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package board

import (
"context"
"fmt"
"os"
"sort"

Expand All @@ -29,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/cheynewallace/tabby"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -68,10 +68,10 @@ func outputBoardListAll(list *rpc.BoardListAllResp) {
return list.Boards[i].GetName() < list.Boards[j].GetName()
})

table := output.NewTable()
table.SetHeader("Board Name", "FQBN")
table := tabby.New()
table.AddHeader("Board Name", "FQBN")
for _, item := range list.GetBoards() {
table.AddRow(item.GetName(), item.GetFQBN())
table.AddLine(item.GetName(), item.GetFQBN())
}
fmt.Print(table.Render())
table.Print()
}
11 changes: 6 additions & 5 deletions cli/core/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package core

import (
"fmt"
"os"
"sort"

Expand All @@ -28,6 +27,7 @@ import (
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/cheynewallace/tabby"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -69,13 +69,14 @@ func outputInstalledCores(platforms []*cores.PlatformRelease) {
return
}

table := output.NewTable()
table.AddRow("ID", "Installed", "Latest", "Name")
table := tabby.New()
table.AddHeader("ID", "Installed", "Latest", "Name")
sort.Slice(platforms, func(i, j int) bool {
return platforms[i].Platform.String() < platforms[j].Platform.String()
})
for _, p := range platforms {
table.AddRow(p.Platform.String(), p.Version.String(), p.Platform.GetLatestRelease().Version.String(), p.Platform.Name)
table.AddLine(p.Platform.String(), p.Version.String(), p.Platform.GetLatestRelease().Version.String(), p.Platform.Name)
}
fmt.Print(table.Render())

table.Print()
}
10 changes: 5 additions & 5 deletions cli/core/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package core

import (
"context"
"fmt"
"os"
"sort"
"strings"
Expand All @@ -30,6 +29,7 @@ import (
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/cheynewallace/tabby"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -73,13 +73,13 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
}

func outputSearchCores(cores []*rpc.Platform) {
table := output.NewTable()
table.AddRow("ID", "Version", "Name")
table := tabby.New()
table.AddHeader("ID", "Version", "Name")
sort.Slice(cores, func(i, j int) bool {
return cores[i].ID < cores[j].ID
})
for _, item := range cores {
table.AddRow(item.GetID(), item.GetLatest(), item.GetName())
table.AddLine(item.GetID(), item.GetLatest(), item.GetName())
}
fmt.Print(table.Render())
table.Print()
}
162 changes: 0 additions & 162 deletions cli/output/table.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/arduino/go-properties-orderedmap v0.0.0-20181003091528-89278049acd3
github.com/arduino/go-timeutils v0.0.0-20171220113728-d1dd9e313b1b
github.com/arduino/go-win32-utils v0.0.0-20180330194947-ed041402e83b
github.com/cheynewallace/tabby v1.1.0
github.com/cmaglie/pb v1.0.27
github.com/codeclysm/cc v1.2.2 // indirect
github.com/codeclysm/extract v2.2.0+incompatible
Expand Down
Loading