Skip to content

Commit

Permalink
Merge pull request #3619 from pachyderm/tabcolor
Browse files Browse the repository at this point in the history
TabWriter with color
  • Loading branch information
adelelopez committed Apr 1, 2019
2 parents 5d4bdb2 + 1418b4f commit f78745c
Show file tree
Hide file tree
Showing 24 changed files with 2,072 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/server/cmd/pachctl/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import (
"os"
"os/signal"
"strings"
"text/tabwriter"
"time"

etcd "github.com/coreos/etcd/clientv3"
"github.com/fatih/color"
"github.com/gogo/protobuf/jsonpb"
"github.com/gogo/protobuf/types"
"github.com/juju/ansiterm"
"github.com/pachyderm/pachyderm/src/client"
"github.com/pachyderm/pachyderm/src/client/version"
"github.com/pachyderm/pachyderm/src/client/version/versionpb"
Expand Down Expand Up @@ -244,7 +244,7 @@ Environment variables:
}

// Print header + client version
writer := tabwriter.NewWriter(os.Stdout, 20, 1, 3, ' ', 0)
writer := ansiterm.NewTabWriter(os.Stdout, 20, 1, 3, ' ', 0)
if raw {
if err := marshaller.Marshal(os.Stdout, version.Version); err != nil {
return err
Expand Down Expand Up @@ -280,7 +280,7 @@ Environment variables:

if err != nil {
buf := bytes.NewBufferString("")
errWriter := tabwriter.NewWriter(buf, 20, 1, 3, ' ', 0)
errWriter := ansiterm.NewTabWriter(buf, 20, 1, 3, ' ', 0)
fmt.Fprintf(errWriter, "pachd\t(version unknown) : error connecting to pachd server at address (%v): %v\n\nplease make sure pachd is up (`kubectl get all`) and portforwarding is enabled\n", pachClient.GetAddress(), grpc.ErrorDesc(err))
errWriter.Flush()
return errors.New(buf.String())
Expand Down
7 changes: 4 additions & 3 deletions src/server/pkg/tabwriter/tabwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package tabwriter
import (
"bytes"
"io"
"text/tabwriter"

"github.com/juju/ansiterm"
)

const (
Expand All @@ -15,7 +16,7 @@ const (
// large numbers of items because it periodically flushes its contents and
// reprints a header when it does.
type Writer struct {
w *tabwriter.Writer
w *ansiterm.TabWriter
lines int
header []byte
}
Expand All @@ -28,7 +29,7 @@ func NewWriter(w io.Writer, header string) *Writer {
if header[len(header)-1] != '\n' {
panic("header must end in a new line")
}
tabwriter := tabwriter.NewWriter(w, 0, 1, 1, ' ', 0)
tabwriter := ansiterm.NewTabWriter(w, 0, 1, 1, ' ', 0)
tabwriter.Write([]byte(header))
return &Writer{
w: tabwriter,
Expand Down
44 changes: 22 additions & 22 deletions src/server/pps/cmds/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,28 +737,28 @@ you can increase the amount of memory used for the bloom filters with the
}
garbageCollect.Flags().StringVarP(&memory, "memory", "m", "0", "The amount of memory to use during garbage collection. Default is 10MB.")

jobCommands := []*cobra.Command{
inspectJob,
listJob,
flushJob,
deleteJob,
stopJob,
}

pipelineCommands := []*cobra.Command{
createPipeline,
updatePipeline,
inspectPipeline,
extractPipeline,
editPipeline,
listPipeline,
deletePipeline,
startPipeline,
stopPipeline,
}

cmdutil.SetDocsUsage(job, jobCommands)
cmdutil.SetDocsUsage(pipeline, pipelineCommands)
jobCommands := []*cobra.Command{
inspectJob,
listJob,
flushJob,
deleteJob,
stopJob,
}

pipelineCommands := []*cobra.Command{
createPipeline,
updatePipeline,
inspectPipeline,
extractPipeline,
editPipeline,
listPipeline,
deletePipeline,
startPipeline,
stopPipeline,
}

cmdutil.SetDocsUsage(job, jobCommands)
cmdutil.SetDocsUsage(pipeline, pipelineCommands)

var result []*cobra.Command
result = append(result, job)
Expand Down
12 changes: 4 additions & 8 deletions src/server/pps/pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import (
"io"
"os"
"strings"
"text/tabwriter"
"text/template"

"github.com/docker/go-units"
"github.com/fatih/color"
"github.com/gogo/protobuf/types"
"github.com/juju/ansiterm"
"github.com/pachyderm/pachyderm/src/client"
pfsclient "github.com/pachyderm/pachyderm/src/client/pfs"
ppsclient "github.com/pachyderm/pachyderm/src/client/pps"
Expand All @@ -32,8 +32,6 @@ const (

// PrintJobHeader prints a job header.
func PrintJobHeader(w io.Writer) {
// because STATE is a colorful field it has to be at the end of the line,
// otherwise the terminal escape characters will trip up the tabwriter
fmt.Fprint(w, JobHeader)
}

Expand Down Expand Up @@ -71,8 +69,6 @@ func PrintJobInfo(w io.Writer, jobInfo *ppsclient.JobInfo, fullTimestamps bool)

// PrintPipelineHeader prints a pipeline header.
func PrintPipelineHeader(w io.Writer) {
// because STATE is a colorful field it has to be at the end of the line,
// otherwise the terminal escape characters will trip up the tabwriter
fmt.Fprint(w, PipelineHeader)
}

Expand Down Expand Up @@ -286,12 +282,12 @@ func PrintDetailedDatumInfo(w io.Writer, datumInfo *ppsclient.DatumInfo) {
fmt.Fprintf(w, "Upload Time\t%s\n", uploadTime)

fmt.Fprintf(w, "PFS State:\n")
tw := tabwriter.NewWriter(w, 10, 1, 3, ' ', 0)
tw := ansiterm.NewTabWriter(w, 10, 1, 3, ' ', 0)
PrintFileHeader(tw)
PrintFile(tw, datumInfo.PfsState)
tw.Flush()
fmt.Fprintf(w, "Inputs:\n")
tw = tabwriter.NewWriter(w, 10, 1, 3, ' ', 0)
tw = ansiterm.NewTabWriter(w, 10, 1, 3, ' ', 0)
PrintFileHeader(tw)
for _, d := range datumInfo.Data {
PrintFile(tw, d.File)
Expand Down Expand Up @@ -370,7 +366,7 @@ func jobInput(jobInfo PrintableJobInfo) string {

func workerStatus(jobInfo PrintableJobInfo) string {
var buffer bytes.Buffer
writer := tabwriter.NewWriter(&buffer, 20, 1, 3, ' ', 0)
writer := ansiterm.NewTabWriter(&buffer, 20, 1, 3, ' ', 0)
PrintWorkerStatusHeader(writer)
for _, workerStatus := range jobInfo.WorkerStatus {
PrintWorkerStatus(writer, workerStatus, jobInfo.FullTimestamps)
Expand Down
191 changes: 191 additions & 0 deletions src/server/vendor/github.com/juju/ansiterm/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions src/server/vendor/github.com/juju/ansiterm/Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f78745c

Please sign in to comment.