aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/olekukonko/tablewriter/util.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2017-04-11 07:25:53 +0800
committerFelix Lange <fjl@users.noreply.github.com>2017-04-11 07:25:53 +0800
commit706a1e552c96bf75c60844c1dc28fc83778795fc (patch)
treebabbc6193bbdbde23f063a26544c630434047793 /vendor/github.com/olekukonko/tablewriter/util.go
parent18bbe124259a852b349e8238ffe394639e29d803 (diff)
downloadgo-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.tar
go-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.tar.gz
go-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.tar.bz2
go-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.tar.lz
go-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.tar.xz
go-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.tar.zst
go-tangerine-706a1e552c96bf75c60844c1dc28fc83778795fc.zip
cmd/puppeth: your Ethereum private network manager (#13854)
Diffstat (limited to 'vendor/github.com/olekukonko/tablewriter/util.go')
-rw-r--r--vendor/github.com/olekukonko/tablewriter/util.go72
1 files changed, 72 insertions, 0 deletions
diff --git a/vendor/github.com/olekukonko/tablewriter/util.go b/vendor/github.com/olekukonko/tablewriter/util.go
new file mode 100644
index 000000000..2deefbc52
--- /dev/null
+++ b/vendor/github.com/olekukonko/tablewriter/util.go
@@ -0,0 +1,72 @@
+// Copyright 2014 Oleku Konko All rights reserved.
+// Use of this source code is governed by a MIT
+// license that can be found in the LICENSE file.
+
+// This module is a Table Writer API for the Go Programming Language.
+// The protocols were written in pure Go and works on windows and unix systems
+
+package tablewriter
+
+import (
+ "math"
+ "regexp"
+ "strings"
+
+ "github.com/mattn/go-runewidth"
+)
+
+var ansi = regexp.MustCompile("\033\\[(?:[0-9]{1,3}(?:;[0-9]{1,3})*)?[m|K]")
+
+func DisplayWidth(str string) int {
+ return runewidth.StringWidth(ansi.ReplaceAllLiteralString(str, ""))
+}
+
+// Simple Condition for string
+// Returns value based on condition
+func ConditionString(cond bool, valid, inValid string) string {
+ if cond {
+ return valid
+ }
+ return inValid
+}
+
+// Format Table Header
+// Replace _ , . and spaces
+func Title(name string) string {
+ name = strings.Replace(name, "_", " ", -1)
+ name = strings.Replace(name, ".", " ", -1)
+ name = strings.TrimSpace(name)
+ return strings.ToUpper(name)
+}
+
+// Pad String
+// Attempts to play string in the center
+func Pad(s, pad string, width int) string {
+ gap := width - DisplayWidth(s)
+ if gap > 0 {
+ gapLeft := int(math.Ceil(float64(gap / 2)))
+ gapRight := gap - gapLeft
+ return strings.Repeat(string(pad), gapLeft) + s + strings.Repeat(string(pad), gapRight)
+ }
+ return s
+}
+
+// Pad String Right position
+// This would pace string at the left side fo the screen
+func PadRight(s, pad string, width int) string {
+ gap := width - DisplayWidth(s)
+ if gap > 0 {
+ return s + strings.Repeat(string(pad), gap)
+ }
+ return s
+}
+
+// Pad String Left position
+// This would pace string at the right side fo the screen
+func PadLeft(s, pad string, width int) string {
+ gap := width - DisplayWidth(s)
+ if gap > 0 {
+ return strings.Repeat(string(pad), gap) + s
+ }
+ return s
+}