Codebase list golang-github-gosuri-uitable / da3de18
New upstream release. Debian Janitor 4 years ago
6 changed file(s) with 55 addition(s) and 14 deletion(s). Raw diff Collapse all Expand all
22 install:
33 - go get ./...
44 go:
5 - 1.4
6 - 1.5.2
75 - tip
0 golang-github-gosuri-uitable (0.0.3-1) UNRELEASED; urgency=medium
1
2 * New upstream release.
3
4 -- Debian Janitor <janitor@jelmer.uk> Sun, 23 Jun 2019 03:42:24 +0000
5
06 golang-github-gosuri-uitable (0.0~git20170830.36ee7e94-2) unstable; urgency=medium
17
28 [ Alexandre Viau ]
22 import (
33 "fmt"
44
5 "github.com/fatih/color"
56 "github.com/gosuri/uitable"
67 )
78
3637 table.AddRow("") // blank
3738 }
3839 fmt.Println(table)
40
41 fmt.Print("\n==> Multicolor Support\n")
42 table = uitable.New()
43 table.MaxColWidth = 80
44 table.Wrap = true
45 for _, hacker := range hackers {
46 table.AddRow(color.RedString("Name:"), color.WhiteString(hacker.Name))
47 table.AddRow(color.BlueString("Birthday:"), hacker.Birthday)
48 table.AddRow(color.GreenString("Bio:"), hacker.Bio)
49 table.AddRow("") // blank
50 }
51 fmt.Println(table)
3952 }
55 "strings"
66 "sync"
77
8 "github.com/fatih/color"
89 "github.com/gosuri/uitable/util/strutil"
910 "github.com/gosuri/uitable/util/wordwrap"
10 "github.com/mattn/go-runewidth"
1111 )
1212
1313 // Separator is the default column seperator
155155 }
156156 lines[x] = strutil.Join(line, r.Separator)
157157 }
158 return strutil.Join(lines, "\n")
158 return strings.Join(lines, "\n")
159159 }
160160
161161 // Cell represents a column in a row
177177 func (c *Cell) LineWidth() uint {
178178 width := 0
179179 for _, s := range strings.Split(c.String(), "\n") {
180 w := runewidth.StringWidth(s)
180 w := strutil.StringWidth(s)
181181 if w > width {
182182 width = w
183183 }
190190 if c.Data == nil {
191191 return strutil.PadLeft(" ", int(c.Width), ' ')
192192 }
193 s := fmt.Sprintf("%v", c.Data)
193 col := color.New(color.FgBlack)
194 col.DisableColor()
195 s := fmt.Sprintf("%v", col.Sprint(c.Data))
194196 if c.Width > 0 {
195197 if c.Wrap && uint(len(s)) > c.Width {
196198 return wordwrap.WrapString(s, c.Width)
22
33 import (
44 "bytes"
5 "regexp"
6
57 "github.com/mattn/go-runewidth"
68 )
79
10 const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"
11
12 var re = regexp.MustCompile(ansi)
13
814 // PadRight returns a new string of a specified length in which the end of the current string is padded with spaces or with a specified Unicode character.
915 func PadRight(str string, length int, pad byte) string {
10 slen := runewidth.StringWidth(str)
16 slen := StringWidth(str)
1117 if slen >= length {
1218 return str
1319 }
2026
2127 // PadLeft returns a new string of a specified length in which the beginning of the current string is padded with spaces or with a specified Unicode character.
2228 func PadLeft(str string, length int, pad byte) string {
23 slen := runewidth.StringWidth(str)
29 slen := StringWidth(str)
2430 if slen >= length {
2531 return str
2632 }
3541 // Resize resizes the string with the given length. It ellipses with '...' when the string's length exceeds
3642 // the desired length or pads spaces to the right of the string when length is smaller than desired
3743 func Resize(s string, length uint, rightAlign bool) string {
38 slen := runewidth.StringWidth(s)
44 slen := StringWidth(s)
3945 n := int(length)
4046 if slen == n {
4147 return s
5258 w := 0
5359 for _, r := range rs {
5460 buf.WriteRune(r)
55 rw := runewidth.RuneWidth(r)
61 rw := RuneWidth(r)
5662 if w+rw >= n-3 {
5763 break
5864 }
7379 buf.WriteString(list[len(list)-1])
7480 return buf.String()
7581 }
82
83 // Strip strips the string of all colors
84 func Strip(s string) string {
85 return re.ReplaceAllString(s, "")
86 }
87
88 // StringWidth returns the actual width of the string without colors
89 func StringWidth(s string) int {
90 return runewidth.StringWidth(Strip(s))
91 }
92
93 // RuneWidth returns the actual width of the rune
94 func RuneWidth(s rune) int {
95 return runewidth.RuneWidth(s)
96 }
22
33 import (
44 "bytes"
5 "github.com/mattn/go-runewidth"
65 "unicode"
6
7 "github.com/gosuri/uitable/util/strutil"
78 )
89
910 // WrapString wraps the given string within lim width in characters.
2930 } else {
3031 current += uint(spaceWidth)
3132 spaceBuf.WriteTo(buf)
32 spaceWidth += runewidth.StringWidth(buf.String())
33 spaceWidth += strutil.StringWidth(buf.String())
3334 }
3435 spaceBuf.Reset()
3536 spaceWidth = 0
5657 }
5758
5859 spaceBuf.WriteRune(char)
59 spaceWidth += runewidth.RuneWidth(char)
60 spaceWidth += strutil.RuneWidth(char)
6061 } else {
6162 wordBuf.WriteRune(char)
62 wordWidth += runewidth.RuneWidth(char)
63 wordWidth += strutil.RuneWidth(char)
6364
6465 if current+uint(spaceWidth+wordWidth) > lim && uint(wordWidth) < lim {
6566 buf.WriteRune('\n')