Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
f041ebb2
Commit
f041ebb2
authored
Jun 03, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: ColoredUi
parent
c5d539ef
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
packer/ui.go
packer/ui.go
+33
-0
packer/ui_test.go
packer/ui_test.go
+18
-0
No files found.
packer/ui.go
View file @
f041ebb2
...
@@ -6,6 +6,17 @@ import (
...
@@ -6,6 +6,17 @@ import (
"log"
"log"
)
)
type
UiColor
uint
const
(
UiColorRed
UiColor
=
31
UiColorGreen
=
32
UiColorYellow
=
33
UiColorBlue
=
34
UiColorMagenta
=
35
UiColorCyan
=
36
)
// The Ui interface handles all communication for Packer with the outside
// The Ui interface handles all communication for Packer with the outside
// world. This sort of control allows us to strictly control how output
// world. This sort of control allows us to strictly control how output
// is formatted and various levels of output.
// is formatted and various levels of output.
...
@@ -15,6 +26,12 @@ type Ui interface {
...
@@ -15,6 +26,12 @@ type Ui interface {
Error
(
string
)
Error
(
string
)
}
}
// ColoredUi is a UI that is colored using terminal colors.
type
ColoredUi
struct
{
Color
UiColor
Ui
Ui
}
// PrefixedUi is a UI that wraps another UI implementation and adds a
// PrefixedUi is a UI that wraps another UI implementation and adds a
// prefix to all the messages going out.
// prefix to all the messages going out.
type
PrefixedUi
struct
{
type
PrefixedUi
struct
{
...
@@ -30,6 +47,22 @@ type ReaderWriterUi struct {
...
@@ -30,6 +47,22 @@ type ReaderWriterUi struct {
Writer
io
.
Writer
Writer
io
.
Writer
}
}
func
(
u
*
ColoredUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
u
.
colorize
(
message
))
}
func
(
u
*
ColoredUi
)
Message
(
message
string
)
{
u
.
Ui
.
Message
(
u
.
colorize
(
message
))
}
func
(
u
*
ColoredUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
u
.
colorize
(
message
))
}
func
(
u
*
ColoredUi
)
colorize
(
message
string
)
string
{
return
fmt
.
Sprintf
(
"
\0
33[0;%d;40m%s
\0
33[0m"
,
u
.
Color
,
message
)
}
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
SayPrefix
,
message
))
u
.
Ui
.
Say
(
fmt
.
Sprintf
(
"%s: %s"
,
u
.
SayPrefix
,
message
))
}
}
...
...
packer/ui_test.go
View file @
f041ebb2
...
@@ -13,6 +13,16 @@ func testUi() *ReaderWriterUi {
...
@@ -13,6 +13,16 @@ func testUi() *ReaderWriterUi {
}
}
}
}
func
TestColoredUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
ui
:=
&
ColoredUi
{
UiColorRed
,
bufferUi
}
ui
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
\0
33[0;31;40mfoo
\0
33[0m
\n
"
,
"should have color"
)
}
func
TestPrefixedUi
(
t
*
testing
.
T
)
{
func
TestPrefixedUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
...
@@ -29,6 +39,14 @@ func TestPrefixedUi(t *testing.T) {
...
@@ -29,6 +39,14 @@ func TestPrefixedUi(t *testing.T) {
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"mitchell: bar
\n
"
,
"should have prefix"
)
}
}
func
TestColoredUi_ImplUi
(
t
*
testing
.
T
)
{
var
raw
interface
{}
raw
=
&
ColoredUi
{}
if
_
,
ok
:=
raw
.
(
Ui
);
!
ok
{
t
.
Fatalf
(
"ColoredUi must implement Ui"
)
}
}
func
TestPrefixedUi_ImplUi
(
t
*
testing
.
T
)
{
func
TestPrefixedUi_ImplUi
(
t
*
testing
.
T
)
{
var
raw
interface
{}
var
raw
interface
{}
raw
=
&
PrefixedUi
{}
raw
=
&
PrefixedUi
{}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment