diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 2b8c21ae1ceb0..504847db5a8bf 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -1,7 +1,7 @@ { "ImportPath": "github.com/gravitational/teleport", "GoVersion": "go1.6", - "GodepVersion": "v62", + "GodepVersion": "v74", "Packages": [ "./lib/...", "./tool/..." @@ -36,7 +36,7 @@ }, { "ImportPath": "github.com/buger/goterm", - "Rev": "af3f07dadc88b80c7b5a15f26033c6dd979f012f" + "Rev": "d281585cd7365cff9edfed1a5115fc624a012bdc" }, { "ImportPath": "github.com/coreos/etcd/Godeps/_workspace/src/github.com/ugorji/go/codec", diff --git a/vendor/github.com/buger/goterm/README.md b/vendor/github.com/buger/goterm/README.md index 2783d9dc5a52a..935bf6cd410b4 100644 --- a/vendor/github.com/buger/goterm/README.md +++ b/vendor/github.com/buger/goterm/README.md @@ -8,7 +8,7 @@ Full API documentation: http://godoc.org/github.com/buger/goterm ## Basic usage -Full screen console app, priting current time: +Full screen console app, printing current time: ```go import ( @@ -33,6 +33,10 @@ func main() { } ``` +This can be seen in [examples/time_example.go](examples/time_example.go). To +run it yourself, go into your `$GOPATH/src/github.com/buger/goterm` directory +and run `go run ./examples/time_example.go` + Print red bold message on white background: @@ -44,8 +48,10 @@ tm.Println(tm.Backgound(tm.Color(tm.Bold("Important header"), tm.RED), tm.WHITE) Create box and move it to center of the screen: ```go +tm.Clear() + // Create Box with 30% width of current screen, and height of 20 lines -box := tm.NewBox(30|tm.PCT, 20) +box := tm.NewBox(30|tm.PCT, 20, 0) // Add some content to the box // Note that you can add ANY content, even tables @@ -53,8 +59,11 @@ fmt.Fprint(box, "Some box content") // Move Box to approx center of the screen tm.Print(tm.MoveTo(box.String(), 40|tm.PCT, 40|tm.PCT)) + +tm.Flush() ``` +This can be found in [examples/box_example.go](examples/box_example.go). Draw table: @@ -64,8 +73,11 @@ totals := tm.NewTable(0, 10, 5, ' ', 0) fmt.Fprintf(totals, "Time\tStarted\tActive\tFinished\n") fmt.Fprintf(totals, "%s\t%d\t%d\t%d\n", "All", started, started-finished, finished) tm.Println(totals) +tm.Flush() ``` +This can be found in [examples/table_example.go](examples/table_example.go). + ## Line charts Chart example: @@ -92,6 +104,7 @@ Chart example: tm.Println(chart.Draw(data)) ``` +This can be found in [examples/chart_example.go](examples/chart_example.go). Drawing 2 separate graphs in different scales. Each graph have its own Y axe. diff --git a/vendor/github.com/buger/goterm/terminal.go b/vendor/github.com/buger/goterm/terminal.go index 811c5a33f5feb..e5c618ad68c46 100644 --- a/vendor/github.com/buger/goterm/terminal.go +++ b/vendor/github.com/buger/goterm/terminal.go @@ -14,13 +14,11 @@ package goterm import ( + "bufio" "bytes" "fmt" "os" - "runtime" "strings" - "syscall" - "unsafe" ) // Reset all custom styles @@ -29,6 +27,9 @@ const RESET = "\033[0m" // Reset to default color const RESET_COLOR = "\033[32m" +// Return curor to start of line and clean it +const RESET_LINE = "\r\033[K" + // List of possible colors const ( BLACK = iota @@ -41,6 +42,8 @@ const ( WHITE ) +var Output *bufio.Writer = bufio.NewWriter(os.Stdout) + func getColor(code int) string { return fmt.Sprintf("\033[3%dm", code) } @@ -54,7 +57,8 @@ func getBgColor(code int) string { // Check percent flag: num & PCT // // Reset percent flag: num & 0xFF -const PCT = 0x80000000 +const shift = uint(^uint(0)>>63) << 4 +const PCT = 0x8000 << shift type winsize struct { Row uint16 @@ -63,31 +67,6 @@ type winsize struct { Ypixel uint16 } -func getWinsize() (*winsize, error) { - ws := new(winsize) - - var _TIOCGWINSZ int64 - - switch runtime.GOOS { - case "linux": - _TIOCGWINSZ = 0x5413 - case "darwin": - _TIOCGWINSZ = 1074295912 - } - - r1, _, errno := syscall.Syscall(syscall.SYS_IOCTL, - uintptr(syscall.Stdin), - uintptr(_TIOCGWINSZ), - uintptr(unsafe.Pointer(ws)), - ) - - if int(r1) == -1 { - fmt.Println("Error:", os.NewSyscallError("GetWinsize", errno)) - return nil, os.NewSyscallError("GetWinsize", errno) - } - return ws, nil -} - // Global screen buffer // Its not recommented write to buffer dirrectly, use package Print,Printf,Println fucntions instead. var Screen *bytes.Buffer = new(bytes.Buffer) @@ -129,7 +108,7 @@ func applyTransform(str string, transform sf) (out string) { // Clear screen func Clear() { - fmt.Print("\033[2J") + Output.WriteString("\033[2J") } // Move cursor to given position @@ -146,6 +125,13 @@ func MoveTo(str string, x int, y int) (out string) { }) } +// Return carrier to start of line +func ResetLine(str string) (out string) { + return applyTransform(str, func(idx int, line string) string { + return fmt.Sprintf(RESET_LINE, line) + }) +} + // Make bold func Bold(str string) string { return applyTransform(str, func(idx int, line string) string { @@ -163,6 +149,15 @@ func Color(str string, color int) string { }) } +func Highlight(str, substr string, color int) string { + hiSubstr := Color(substr, color) + return strings.Replace(str, substr, hiSubstr, -1) +} + +func HighlightRegion(str string, from, to, color int) string { + return str[:from] + Color(str[from:to], color) + str[to:] +} + // Change background color of string: // // tm.Background("string", tm.RED) @@ -205,9 +200,10 @@ func Flush() { return } - fmt.Println(str) + Output.WriteString(str + "\n") } + Output.Flush() Screen.Reset() } @@ -222,3 +218,21 @@ func Println(a ...interface{}) { func Printf(format string, a ...interface{}) { fmt.Fprintf(Screen, format, a...) } + +func Context(data string, idx, max int) string { + var start, end int + + if len(data[:idx]) < (max / 2) { + start = 0 + } else { + start = idx - max/2 + } + + if len(data)-idx < (max / 2) { + end = len(data) - 1 + } else { + end = idx + max/2 + } + + return data[start:end] +} diff --git a/vendor/github.com/buger/goterm/terminal_nosysioctl.go b/vendor/github.com/buger/goterm/terminal_nosysioctl.go new file mode 100644 index 0000000000000..690615008f62f --- /dev/null +++ b/vendor/github.com/buger/goterm/terminal_nosysioctl.go @@ -0,0 +1,12 @@ +// +build windows plan9 solaris + +package goterm + +func getWinsize() (*winsize, error) { + ws := new(winsize) + + ws.Col = 80 + ws.Row = 24 + + return ws, nil +} diff --git a/vendor/github.com/buger/goterm/terminal_sysioctl.go b/vendor/github.com/buger/goterm/terminal_sysioctl.go new file mode 100644 index 0000000000000..e98430fb92950 --- /dev/null +++ b/vendor/github.com/buger/goterm/terminal_sysioctl.go @@ -0,0 +1,36 @@ +// +build !windows,!plan9,!solaris + +package goterm + +import ( + "fmt" + "os" + "runtime" + "syscall" + "unsafe" +) + +func getWinsize() (*winsize, error) { + ws := new(winsize) + + var _TIOCGWINSZ int64 + + switch runtime.GOOS { + case "linux": + _TIOCGWINSZ = 0x5413 + case "darwin": + _TIOCGWINSZ = 1074295912 + } + + r1, _, errno := syscall.Syscall(syscall.SYS_IOCTL, + uintptr(syscall.Stdin), + uintptr(_TIOCGWINSZ), + uintptr(unsafe.Pointer(ws)), + ) + + if int(r1) == -1 { + fmt.Println("Error:", os.NewSyscallError("GetWinsize", errno)) + return nil, os.NewSyscallError("GetWinsize", errno) + } + return ws, nil +}