Skip to content

Commit 6d40a51

Browse files
committed
Removed dependecy on tmlibs/common
1 parent aac7186 commit 6d40a51

File tree

4 files changed

+113
-63
lines changed

4 files changed

+113
-63
lines changed

Gopkg.lock

Lines changed: 1 addition & 44 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737
name = "github.com/stretchr/testify"
3838
version = "1.2.1"
3939

40-
[[constraint]]
41-
name = "github.com/tendermint/tmlibs"
42-
version = "0.9.0-rc1"
43-
4440
[prune]
4541
go-tests = true
4642
unused-packages = true

cmd/aminoscan.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"os"
1010

1111
"github.com/tendermint/go-amino"
12-
cmn "github.com/tendermint/tmlibs/common"
1312
)
1413

1514
func main() {
@@ -45,16 +44,16 @@ func main() {
4544
return
4645
}
4746
bz := hexDecode(flgs.Arg(0))
48-
fmt.Println(cmn.ColoredBytes(bz, cmn.Green, cmn.Blue))
47+
fmt.Println(ColoredBytes(bz, Green, Blue))
4948
return
5049
}
5150

5251
// Parse struct Amino bytes.
5352
bz := hexDecode(os.Args[1]) // Read input hex bytes.
54-
fmt.Println(cmn.Yellow("## Root Struct (assumed)"))
55-
s, n, err := scanStruct(bz, "", true) // Assume that it's struct.
56-
s += cmn.Red(fmt.Sprintf("%X", bz[n:])) // Bytes remaining are red.
57-
fmt.Println(cmn.Yellow("## Root Struct END"))
53+
fmt.Println(Yellow("## Root Struct (assumed)"))
54+
s, n, err := scanStruct(bz, "", true) // Assume that it's struct.
55+
s += Red(fmt.Sprintf("%X", bz[n:])) // Bytes remaining are red.
56+
fmt.Println(Yellow("## Root Struct END"))
5857
fmt.Println(s, n, err) // Print color-encoded bytes s.
5958
}
6059

@@ -98,7 +97,7 @@ func scanVarint(bz []byte, indent string) (s string, n int, err error) {
9897
return
9998
}
10099
// s is the same either way.
101-
s = cmn.Cyan(fmt.Sprintf("%X", bz[:n]))
100+
s = Cyan(fmt.Sprintf("%X", bz[:n]))
102101
fmt.Printf("%s%s (", indent, s)
103102
if okI64 {
104103
fmt.Printf("i64:%v ", i64)
@@ -116,7 +115,7 @@ func scan8Byte(bz []byte, indent string) (s string, n int, err error) {
116115
return
117116
}
118117
n = 8
119-
s = cmn.Blue(fmt.Sprintf("%X", bz[:8]))
118+
s = Blue(fmt.Sprintf("%X", bz[:8]))
120119
fmt.Printf("%s%s\n", indent, s)
121120
return
122121
}
@@ -135,10 +134,10 @@ func scanByteLength(bz []byte, indent string) (s string, n int, err error) {
135134
err = errors.New("EOF while reading byte-length delimited.")
136135
return
137136
}
138-
s = cmn.Cyan(fmt.Sprintf("%X", bz[:_n]))
137+
s = Cyan(fmt.Sprintf("%X", bz[:_n]))
139138
slide(&bz, &n, _n)
140139
// Read the remaining bytes.
141-
s += cmn.Green(fmt.Sprintf("%X", bz[:length]))
140+
s += Green(fmt.Sprintf("%X", bz[:length]))
142141
slide(&bz, &n, length)
143142
fmt.Printf("%s%s (%v bytes)\n", indent, s, length)
144143
return
@@ -183,7 +182,7 @@ func scan4Byte(bz []byte, indent string) (s string, n int, err error) {
183182
return
184183
}
185184
n = 4
186-
s = cmn.Blue(fmt.Sprintf("%X", bz[:4]))
185+
s = Blue(fmt.Sprintf("%X", bz[:4]))
187186
fmt.Printf("%s%s\n", indent, s)
188187
return
189188
}
@@ -210,7 +209,7 @@ func scanList(bz []byte, indent string) (s string, n int, err error) {
210209
_n = 0
211210
err = errors.New("error decoding list length (uvarint)")
212211
}
213-
s += cmn.Cyan(fmt.Sprintf("%X", bz[:_n]))
212+
s += Cyan(fmt.Sprintf("%X", bz[:_n]))
214213
if slide(&bz, &n, _n) && err != nil {
215214
return
216215
}
@@ -257,11 +256,11 @@ func scanInterface(bz []byte, indent string) (s string, n int, err error) {
257256
}
258257
pb3 := pb
259258
if isNil {
260-
s = cmn.Magenta("0000")
259+
s = Magenta("0000")
261260
} else if hasDb {
262-
s = cmn.Magenta(fmt.Sprintf("%X%X", db.Bytes(), pb3.Bytes()))
261+
s = Magenta(fmt.Sprintf("%X%X", db.Bytes(), pb3.Bytes()))
263262
} else {
264-
s = cmn.Magenta(fmt.Sprintf("%X", pb3.Bytes()))
263+
s = Magenta(fmt.Sprintf("%X", pb3.Bytes()))
265264
}
266265
if isNil {
267266
fmt.Printf("%s%s (nil interface)\n", indent, s)

cmd/colors.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package main
2+
3+
// NOTE: This is copied over from tendermint/tendermint/libs/common/colors.go
4+
// Do not edit this file without modifying the other.
5+
6+
import (
7+
"fmt"
8+
"strings"
9+
)
10+
11+
const (
12+
ANSIReset = "\x1b[0m"
13+
ANSIBright = "\x1b[1m"
14+
ANSIDim = "\x1b[2m"
15+
ANSIUnderscore = "\x1b[4m"
16+
ANSIBlink = "\x1b[5m"
17+
ANSIReverse = "\x1b[7m"
18+
ANSIHidden = "\x1b[8m"
19+
20+
ANSIFgBlack = "\x1b[30m"
21+
ANSIFgRed = "\x1b[31m"
22+
ANSIFgGreen = "\x1b[32m"
23+
ANSIFgYellow = "\x1b[33m"
24+
ANSIFgBlue = "\x1b[34m"
25+
ANSIFgMagenta = "\x1b[35m"
26+
ANSIFgCyan = "\x1b[36m"
27+
ANSIFgWhite = "\x1b[37m"
28+
29+
ANSIBgBlack = "\x1b[40m"
30+
ANSIBgRed = "\x1b[41m"
31+
ANSIBgGreen = "\x1b[42m"
32+
ANSIBgYellow = "\x1b[43m"
33+
ANSIBgBlue = "\x1b[44m"
34+
ANSIBgMagenta = "\x1b[45m"
35+
ANSIBgCyan = "\x1b[46m"
36+
ANSIBgWhite = "\x1b[47m"
37+
)
38+
39+
// color the string s with color 'color'
40+
// unless s is already colored
41+
func treat(s string, color string) string {
42+
if len(s) > 2 && s[:2] == "\x1b[" {
43+
return s
44+
}
45+
return color + s + ANSIReset
46+
}
47+
48+
func treatAll(color string, args ...interface{}) string {
49+
var parts []string
50+
for _, arg := range args {
51+
parts = append(parts, treat(fmt.Sprintf("%v", arg), color))
52+
}
53+
return strings.Join(parts, "")
54+
}
55+
56+
func Black(args ...interface{}) string {
57+
return treatAll(ANSIFgBlack, args...)
58+
}
59+
60+
func Red(args ...interface{}) string {
61+
return treatAll(ANSIFgRed, args...)
62+
}
63+
64+
func Green(args ...interface{}) string {
65+
return treatAll(ANSIFgGreen, args...)
66+
}
67+
68+
func Yellow(args ...interface{}) string {
69+
return treatAll(ANSIFgYellow, args...)
70+
}
71+
72+
func Blue(args ...interface{}) string {
73+
return treatAll(ANSIFgBlue, args...)
74+
}
75+
76+
func Magenta(args ...interface{}) string {
77+
return treatAll(ANSIFgMagenta, args...)
78+
}
79+
80+
func Cyan(args ...interface{}) string {
81+
return treatAll(ANSIFgCyan, args...)
82+
}
83+
84+
func White(args ...interface{}) string {
85+
return treatAll(ANSIFgWhite, args...)
86+
}
87+
88+
func ColoredBytes(data []byte, textColor, bytesColor func(...interface{}) string) string {
89+
s := ""
90+
for _, b := range data {
91+
if 0x21 <= b && b < 0x7F {
92+
s += textColor(string(b))
93+
} else {
94+
s += bytesColor(fmt.Sprintf("%02X", b))
95+
}
96+
}
97+
return s
98+
}

0 commit comments

Comments
 (0)