-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
105 lines (89 loc) · 2.73 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Package utils provides utilities for interacting with the terminal and formatting output.
package main
import (
"os"
"github.com/jedib0t/go-pretty/v6/table"
"github.com/jedib0t/go-pretty/v6/text"
)
func Table(style string, title string) table.Writer {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.SetTitle(title)
t.SetStyle(getStyle(style))
return t
}
func getStyle(styleName string) table.Style {
styles := map[string]table.Style{
"DarkSimple": DarkSimple,
"LightSimple": LightSimple,
}
return styles[styleName]
}
var DarkSimple = table.Style{
Name: "DarkSimple",
Box: StyleBoxDefault,
Color: ColorOptionsCyanWhiteOnBlack,
Format: FormatOptionsDefault,
Options: OptionsNoBordersAndSeparators,
Title: TitleOptionsBlackOnCyan,
}
var LightSimple = table.Style{
Name: "LightSimple",
Box: StyleBoxDefault,
Color: ColorOptionsBlackOnCyanWhite,
Format: FormatOptionsDefault,
Options: OptionsNoBordersAndSeparators,
Title: TitleOptionsCyanOnBlack,
}
var StyleBoxDefault = table.BoxStyle{
BottomLeft: "+",
BottomRight: "+",
BottomSeparator: "+",
EmptySeparator: text.RepeatAndTrim(" ", text.RuneWidthWithoutEscSequences("+")),
Left: "|",
LeftSeparator: "+",
MiddleHorizontal: "-",
MiddleSeparator: "+",
MiddleVertical: "|",
PaddingLeft: " ",
PaddingRight: " ",
PageSeparator: "\n",
Right: "|",
RightSeparator: "+",
TopLeft: "+",
TopRight: "+",
TopSeparator: "+",
UnfinishedRow: " ~",
}
var ColorOptionsCyanWhiteOnBlack = table.ColorOptions{
Footer: text.Colors{text.FgCyan, text.BgHiBlack},
Header: text.Colors{text.FgHiCyan, text.BgHiBlack},
IndexColumn: text.Colors{text.FgHiCyan, text.BgHiBlack},
Row: text.Colors{text.FgHiWhite, text.BgBlack},
RowAlternate: text.Colors{text.FgWhite, text.BgBlack},
}
var ColorOptionsBlackOnCyanWhite = table.ColorOptions{
Footer: text.Colors{text.BgCyan, text.FgBlack},
Header: text.Colors{text.BgHiCyan, text.FgBlack},
IndexColumn: text.Colors{text.BgHiCyan, text.FgBlack},
Row: text.Colors{text.BgHiWhite, text.FgBlack},
RowAlternate: text.Colors{text.BgWhite, text.FgBlack},
}
var FormatOptionsDefault = table.FormatOptions{
Footer: text.FormatUpper,
Header: text.FormatUpper,
Row: text.FormatDefault,
}
var OptionsNoBordersAndSeparators = table.Options{
DrawBorder: false,
SeparateColumns: false,
SeparateFooter: false,
SeparateHeader: false,
SeparateRows: false,
}
var TitleOptionsBlackOnCyan = table.TitleOptions{
Colors: append(table.ColorOptionsBlackOnCyanWhite.Header, text.Bold),
}
var TitleOptionsCyanOnBlack = table.TitleOptions{
Colors: append(ColorOptionsCyanWhiteOnBlack.Header, text.Bold),
}