2017-04-10 18:25:53 -05:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 09:07:44 -05:00
|
|
|
func isNumOrSpace(r rune) bool {
|
|
|
|
return ('0' <= r && r <= '9') || r == ' '
|
|
|
|
}
|
|
|
|
|
2017-04-10 18:25:53 -05:00
|
|
|
// Format Table Header
|
|
|
|
// Replace _ , . and spaces
|
|
|
|
func Title(name string) string {
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 09:07:44 -05:00
|
|
|
origLen := len(name)
|
|
|
|
rs := []rune(name)
|
|
|
|
for i, r := range rs {
|
|
|
|
switch r {
|
|
|
|
case '_':
|
|
|
|
rs[i] = ' '
|
|
|
|
case '.':
|
|
|
|
// ignore floating number 0.0
|
|
|
|
if (i != 0 && !isNumOrSpace(rs[i-1])) || (i != len(rs)-1 && !isNumOrSpace(rs[i+1])) {
|
|
|
|
rs[i] = ' '
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
name = string(rs)
|
2017-04-10 18:25:53 -05:00
|
|
|
name = strings.TrimSpace(name)
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 09:07:44 -05:00
|
|
|
if len(name) == 0 && origLen > 0 {
|
|
|
|
// Keep at least one character. This is important to preserve
|
|
|
|
// empty lines in multi-line headers/footers.
|
|
|
|
name = " "
|
|
|
|
}
|
2017-04-10 18:25:53 -05:00
|
|
|
return strings.ToUpper(name)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pad String
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 09:07:44 -05:00
|
|
|
// Attempts to place string in the center
|
2017-04-10 18:25:53 -05:00
|
|
|
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
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 09:07:44 -05:00
|
|
|
// This would place string at the left side of the screen
|
2017-04-10 18:25:53 -05:00
|
|
|
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
|
core, cmd, vendor: fixes and database inspection tool (#15)
* core, eth: some fixes for freezer
* vendor, core/rawdb, cmd/geth: add db inspector
* core, cmd/utils: check ancient store path forceily
* cmd/geth, common, core/rawdb: a few fixes
* cmd/geth: support windows file rename and fix rename error
* core: support ancient plugin
* core, cmd: streaming file copy
* cmd, consensus, core, tests: keep genesis in leveldb
* core: write txlookup during ancient init
* core: bump database version
2019-05-14 09:07:44 -05:00
|
|
|
// This would place string at the right side of the screen
|
2017-04-10 18:25:53 -05:00
|
|
|
func PadLeft(s, pad string, width int) string {
|
|
|
|
gap := width - DisplayWidth(s)
|
|
|
|
if gap > 0 {
|
|
|
|
return strings.Repeat(string(pad), gap) + s
|
|
|
|
}
|
|
|
|
return s
|
|
|
|
}
|