Remove dependency on curse library

This commit is contained in:
Morten Torkildsen
2019-12-13 09:18:36 -08:00
parent e0ba78f292
commit 60e2375521
3 changed files with 49 additions and 49 deletions

View File

@@ -3,11 +3,8 @@ module sigs.k8s.io/kustomize/cmd/resource
go 1.12 go 1.12
require ( require (
github.com/kless/term v0.0.0-20161130133337-e551c64f56c0 // indirect
github.com/pkg/errors v0.8.1 github.com/pkg/errors v0.8.1
github.com/sethgrid/curse v0.0.0-20181231162520-d4ee583ebf0f
github.com/spf13/cobra v0.0.5 github.com/spf13/cobra v0.0.5
github.com/tredoe/term v0.0.0-20161130133337-e551c64f56c0 // indirect
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655 k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90 k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90

View File

@@ -155,8 +155,6 @@ github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/u
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU= github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kless/term v0.0.0-20161130133337-e551c64f56c0 h1:urSxQgTe6jlMLp7SBqS9kScNOFrkumkEPd5wkEqR4zo=
github.com/kless/term v0.0.0-20161130133337-e551c64f56c0/go.mod h1:QHlPrsvQ38EZ3avQaGw+V049LEqMXGn/Q7///G4rlPw=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
@@ -213,8 +211,6 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nL
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M= github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
github.com/sethgrid/curse v0.0.0-20181231162520-d4ee583ebf0f h1:5sRN2QRb4WELQTjDA0RxH6fDHsqU8DvmSxOVQrFE5EU=
github.com/sethgrid/curse v0.0.0-20181231162520-d4ee583ebf0f/go.mod h1:AcGQtZEPLvE/ypI3mXUA5nzST17BmzYJJy/n5HXoFTA=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
@@ -237,8 +233,6 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/tredoe/term v0.0.0-20161130133337-e551c64f56c0 h1:62GgUset6v9/OOwgp6G9G0T85xd1tSrxuJb6B32wfC0=
github.com/tredoe/term v0.0.0-20161130133337-e551c64f56c0/go.mod h1:KgcOI1tnP8CSXsT+9RJU/CYuGBjeJAXbhyG8ufn21jQ=
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI= github.com/xlab/treeprint v0.0.0-20181112141820-a009c3971eca h1:1CFlNzQhALwjS9mBAUkycX616GzgsuYUOCHA5+HSlXI=

View File

@@ -5,8 +5,6 @@ import (
"io" "io"
"time" "time"
"github.com/sethgrid/curse"
"sigs.k8s.io/kustomize/kstatus/status" "sigs.k8s.io/kustomize/kstatus/status"
"sigs.k8s.io/kustomize/kstatus/wait" "sigs.k8s.io/kustomize/kstatus/wait"
) )
@@ -17,9 +15,29 @@ const (
nameColumn = "name" nameColumn = "name"
statusColumn = "status" statusColumn = "status"
messageColumn = "message" messageColumn = "message"
ESC = 27
RED color = 31
GREEN color = 32
YELLOW color = 33
WHITE color = 37
) )
type colorFunc func(s status.Status) int type color int
func moveUp(w io.Writer, lineCount int) {
printOrDie(w, "%c[%dA", ESC, lineCount)
}
func eraseCurrentLine(w io.Writer) {
printOrDie(w, "%c[2K\r", ESC)
}
func setColor(w io.Writer, color color) {
printOrDie(w, "%c[%dm", ESC, color)
}
type colorFunc func(s status.Status) color
type contentFunc func(resource ResourceStatusData) string type contentFunc func(resource ResourceStatusData) string
type tableColumnInfo struct { type tableColumnInfo struct {
@@ -29,8 +47,8 @@ type tableColumnInfo struct {
contentFunc contentFunc contentFunc contentFunc
} }
func defaultColorFunc(_ status.Status) int { func defaultColorFunc(_ status.Status) color {
return curse.WHITE return WHITE
} }
var ( var (
@@ -112,66 +130,64 @@ func newTablePrinter(statusInfo StatusInfo, out io.Writer, err io.Writer, showAg
} }
func (s *TablePrinter) Print() { func (s *TablePrinter) Print() {
c := newCurseOrDie() s.printTable(s.statusInfo.CurrentStatus(), false)
s.printTable(c, s.statusInfo.CurrentStatus(), false)
} }
func (s *TablePrinter) PrintUntil(stop <-chan struct{}, interval time.Duration) <-chan struct{} { func (s *TablePrinter) PrintUntil(stop <-chan struct{}, interval time.Duration) <-chan struct{} {
completed := make(chan struct{}) completed := make(chan struct{})
go func() { go func() {
defer close(completed) defer close(completed)
c := newCurseOrDie() setColor(s.out, WHITE)
c.SetDefaultStyle() s.printTable(s.statusInfo.CurrentStatus(), false)
s.printTable(c, s.statusInfo.CurrentStatus(), false)
ticker := time.NewTicker(interval) ticker := time.NewTicker(interval)
for { for {
select { select {
case <-stop: case <-stop:
ticker.Stop() ticker.Stop()
s.printTable(c, s.statusInfo.CurrentStatus(), true) s.printTable(s.statusInfo.CurrentStatus(), true)
return return
case <-ticker.C: case <-ticker.C:
s.printTable(c, s.statusInfo.CurrentStatus(), true) s.printTable(s.statusInfo.CurrentStatus(), true)
} }
} }
}() }()
return completed return completed
} }
func (s *TablePrinter) printTable(c *curse.Cursor, data StatusData, moveUp bool) { func (s *TablePrinter) printTable(data StatusData, deleteUp bool) {
if moveUp { if deleteUp {
if s.showAggStatus { if s.showAggStatus {
c.MoveUp(1) moveUp(s.out, 1)
} }
c.MoveUp(1) moveUp(s.out, 1)
c.MoveUp(len(data.ResourceStatuses)) moveUp(s.out, len(data.ResourceStatuses))
} }
c.EraseCurrentLine() eraseCurrentLine(s.out)
if s.showAggStatus { if s.showAggStatus {
printOrDie(s.out, "AggregateStatus: ") printOrDie(s.out, "AggregateStatus: ")
c.SetColor(colorForStatus(data.AggregateStatus)) setColor(s.out, colorForStatus(data.AggregateStatus))
printOrDie(s.out, "%s\n", data.AggregateStatus) printOrDie(s.out, "%s\n", data.AggregateStatus)
c.SetDefaultStyle() setColor(s.out, WHITE)
} }
s.printTableRow(c, headers()) s.printTableRow(headers())
for _, resource := range data.ResourceStatuses { for _, resource := range data.ResourceStatuses {
s.printTableRow(c, row(resource)) s.printTableRow(row(resource))
} }
} }
func (s *TablePrinter) printTableRow(c *curse.Cursor, rowData []RowData) { func (s *TablePrinter) printTableRow(rowData []RowData) {
for _, row := range rowData { for _, row := range rowData {
c.SetColor(row.color) setColor(s.out, row.color)
format := fmt.Sprintf("%%-%ds ", row.width) format := fmt.Sprintf("%%-%ds ", row.width)
printOrDie(s.out, format, trimString(row.content, row.width)) printOrDie(s.out, format, trimString(row.content, row.width))
c.SetDefaultStyle() setColor(s.out, WHITE)
} }
printOrDie(s.out, "\n") printOrDie(s.out, "\n")
} }
type RowData struct { type RowData struct {
content string content string
color int color color
width int width int
} }
@@ -181,7 +197,7 @@ func headers() []RowData {
column := tableColumns[columnName] column := tableColumns[columnName]
headers = append(headers, RowData{ headers = append(headers, RowData{
content: column.header, content: column.header,
color: curse.WHITE, color: WHITE,
width: column.width, width: column.width,
}) })
} }
@@ -303,13 +319,6 @@ func (e *EventPrinter) printEvent(event wait.Event) {
printOrDie(e.out, "\n") printOrDie(e.out, "\n")
} }
func newCurseOrDie() *curse.Cursor {
// TODO: Handle the issue with creating a new Cursor. For now we
// are just ignoring the error (which mostly works).
c, _ := curse.New()
return c
}
func printOrDie(w io.Writer, format string, a ...interface{}) { func printOrDie(w io.Writer, format string, a ...interface{}) {
_, err := fmt.Fprintf(w, format, a...) _, err := fmt.Fprintf(w, format, a...)
if err != nil { if err != nil {
@@ -317,18 +326,18 @@ func printOrDie(w io.Writer, format string, a ...interface{}) {
} }
} }
func colorForStatus(s status.Status) int { func colorForStatus(s status.Status) color {
switch s { switch s {
case status.CurrentStatus: case status.CurrentStatus:
return curse.GREEN return GREEN
case status.UnknownStatus: case status.UnknownStatus:
return curse.WHITE return WHITE
case status.InProgressStatus: case status.InProgressStatus:
return curse.YELLOW return YELLOW
case status.FailedStatus: case status.FailedStatus:
return curse.RED return RED
} }
return curse.WHITE return WHITE
} }
func trimString(str string, maxLength int) string { func trimString(str string, maxLength int) string {