Skip to content

Commit 3a9d7e3

Browse files
committed
init
0 parents  commit 3a9d7e3

File tree

613 files changed

+384004
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

613 files changed

+384004
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.test

Gopkg.lock

Lines changed: 193 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[prune]
2+
go-tests = true
3+
unused-packages = true
4+
5+
[[constraint]]
6+
name = "github.com/fatih/color"
7+
version = "1.7.0"
8+
9+
[[constraint]]
10+
name = "github.com/mattn/go-isatty"
11+
version = "0.0.3"
12+
13+
[[constraint]]
14+
name = "github.com/onsi/ginkgo"
15+
version = "1.6.0"
16+
17+
[[constraint]]
18+
name = "github.com/onsi/gomega"
19+
version = "1.4.1"
20+
21+
[[constraint]]
22+
branch = "master"
23+
name = "github.com/vito/go-interact"
24+
25+
[[constraint]]
26+
name = "gopkg.in/yaml.v2"
27+
version = "2.2.1"

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2018 Dmitriy Kalinin
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## go-cli-ui
2+
3+
Originally this library was written for [BOSH CLI v2](http://bosh.io/docs/cli-v2.html). Given its generic nature, it's been extracted as a separate, easily importable library.

bin/test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
go fmt github.com/cppforlife/go-cli-ui/...
6+
7+
ginkgo -r ui/

ui/color_ui.go

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package ui
2+
3+
import (
4+
"github.com/fatih/color"
5+
6+
. "github.com/cppforlife/go-cli-ui/ui/table"
7+
)
8+
9+
type ColorUI struct {
10+
parent UI
11+
okFunc func(string, ...interface{}) string
12+
errFunc func(string, ...interface{}) string
13+
boldFunc func(string, ...interface{}) string
14+
}
15+
16+
func NewColorUI(parent UI) UI {
17+
return &ColorUI{
18+
parent: parent,
19+
okFunc: color.New(color.FgGreen).SprintfFunc(),
20+
errFunc: color.New(color.FgRed).SprintfFunc(),
21+
boldFunc: color.New(color.Bold).SprintfFunc(),
22+
}
23+
}
24+
25+
func (ui *ColorUI) ErrorLinef(pattern string, args ...interface{}) {
26+
ui.parent.ErrorLinef("%s", ui.errFunc(pattern, args...))
27+
}
28+
29+
func (ui *ColorUI) PrintLinef(pattern string, args ...interface{}) {
30+
ui.parent.PrintLinef(pattern, args...)
31+
}
32+
33+
func (ui *ColorUI) BeginLinef(pattern string, args ...interface{}) {
34+
ui.parent.BeginLinef(pattern, args...)
35+
}
36+
37+
func (ui *ColorUI) EndLinef(pattern string, args ...interface{}) {
38+
ui.parent.EndLinef(pattern, args...)
39+
}
40+
41+
func (ui *ColorUI) PrintBlock(block []byte) {
42+
ui.parent.PrintBlock(block)
43+
}
44+
45+
func (ui *ColorUI) PrintErrorBlock(block string) {
46+
ui.parent.PrintErrorBlock(ui.errFunc("%s", block))
47+
}
48+
49+
func (ui *ColorUI) PrintTable(table Table) {
50+
table.HeaderFormatFunc = ui.boldFunc
51+
52+
for k, s := range table.Sections {
53+
for i, r := range s.Rows {
54+
for j, v := range r {
55+
table.Sections[k].Rows[i][j] = ui.colorValueFmt(v)
56+
}
57+
}
58+
}
59+
60+
for i, r := range table.Rows {
61+
for j, v := range r {
62+
table.Rows[i][j] = ui.colorValueFmt(v)
63+
}
64+
}
65+
66+
ui.parent.PrintTable(table)
67+
}
68+
69+
func (ui *ColorUI) AskForText(label string) (string, error) {
70+
return ui.parent.AskForText(label)
71+
}
72+
73+
func (ui *ColorUI) AskForChoice(label string, options []string) (int, error) {
74+
return ui.parent.AskForChoice(label, options)
75+
}
76+
77+
func (ui *ColorUI) AskForPassword(label string) (string, error) {
78+
return ui.parent.AskForPassword(label)
79+
}
80+
81+
func (ui *ColorUI) AskForConfirmation() error {
82+
return ui.parent.AskForConfirmation()
83+
}
84+
85+
func (ui *ColorUI) IsInteractive() bool {
86+
return ui.parent.IsInteractive()
87+
}
88+
89+
func (ui *ColorUI) Flush() {
90+
ui.parent.Flush()
91+
}
92+
93+
func (ui *ColorUI) colorValueFmt(val Value) Value {
94+
if valFmt, ok := val.(ValueFmt); ok {
95+
if valFmt.Error {
96+
valFmt.Func = ui.errFunc
97+
} else {
98+
valFmt.Func = ui.okFunc
99+
}
100+
return valFmt
101+
}
102+
return val
103+
}

0 commit comments

Comments
 (0)