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
0f98852d
Commit
0f98852d
authored
Jun 12, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
packer: Ui error output is red
parent
2217606e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
13 deletions
+32
-13
command/build/command.go
command/build/command.go
+2
-2
packer/ui.go
packer/ui.go
+13
-7
packer/ui_test.go
packer/ui_test.go
+17
-4
No files found.
command/build/command.go
View file @
0f98852d
...
@@ -101,8 +101,8 @@ func (c Command) Run(env packer.Environment, args []string) int {
...
@@ -101,8 +101,8 @@ func (c Command) Run(env packer.Environment, args []string) int {
var
ui
packer
.
Ui
var
ui
packer
.
Ui
ui
=
&
packer
.
ColoredUi
{
ui
=
&
packer
.
ColoredUi
{
colors
[
i
%
len
(
colors
)],
Color
:
colors
[
i
%
len
(
colors
)],
env
.
Ui
(),
Ui
:
env
.
Ui
(),
}
}
ui
=
&
packer
.
PrefixedUi
{
ui
=
&
packer
.
PrefixedUi
{
...
...
packer/ui.go
View file @
0f98852d
...
@@ -28,8 +28,9 @@ type Ui interface {
...
@@ -28,8 +28,9 @@ type Ui interface {
// ColoredUi is a UI that is colored using terminal colors.
// ColoredUi is a UI that is colored using terminal colors.
type
ColoredUi
struct
{
type
ColoredUi
struct
{
Color
UiColor
Color
UiColor
Ui
Ui
ErrorColor
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
...
@@ -48,24 +49,29 @@ type ReaderWriterUi struct {
...
@@ -48,24 +49,29 @@ type ReaderWriterUi struct {
}
}
func
(
u
*
ColoredUi
)
Say
(
message
string
)
{
func
(
u
*
ColoredUi
)
Say
(
message
string
)
{
u
.
Ui
.
Say
(
u
.
colorize
(
message
,
true
))
u
.
Ui
.
Say
(
u
.
colorize
(
message
,
u
.
Color
,
true
))
}
}
func
(
u
*
ColoredUi
)
Message
(
message
string
)
{
func
(
u
*
ColoredUi
)
Message
(
message
string
)
{
u
.
Ui
.
Message
(
u
.
colorize
(
message
,
false
))
u
.
Ui
.
Message
(
u
.
colorize
(
message
,
u
.
Color
,
false
))
}
}
func
(
u
*
ColoredUi
)
Error
(
message
string
)
{
func
(
u
*
ColoredUi
)
Error
(
message
string
)
{
u
.
Ui
.
Error
(
u
.
colorize
(
message
,
false
))
color
:=
u
.
ErrorColor
if
color
==
0
{
color
=
UiColorRed
}
u
.
Ui
.
Error
(
u
.
colorize
(
message
,
color
,
true
))
}
}
func
(
u
*
ColoredUi
)
colorize
(
message
string
,
bold
bool
)
string
{
func
(
u
*
ColoredUi
)
colorize
(
message
string
,
color
UiColor
,
bold
bool
)
string
{
attr
:=
0
attr
:=
0
if
bold
{
if
bold
{
attr
=
1
attr
=
1
}
}
return
fmt
.
Sprintf
(
"
\0
33[%d;%d;40m%s
\0
33[0m"
,
attr
,
u
.
C
olor
,
message
)
return
fmt
.
Sprintf
(
"
\0
33[%d;%d;40m%s
\0
33[0m"
,
attr
,
c
olor
,
message
)
}
}
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
func
(
u
*
PrefixedUi
)
Say
(
message
string
)
{
...
...
packer/ui_test.go
View file @
0f98852d
...
@@ -14,13 +14,26 @@ func testUi() *ReaderWriterUi {
...
@@ -14,13 +14,26 @@ func testUi() *ReaderWriterUi {
}
}
func
TestColoredUi
(
t
*
testing
.
T
)
{
func
TestColoredUi
(
t
*
testing
.
T
)
{
assert
:=
asserts
.
NewTestingAsserts
(
t
,
true
)
bufferUi
:=
testUi
()
bufferUi
:=
testUi
()
ui
:=
&
ColoredUi
{
UiColorRed
,
bufferUi
}
ui
:=
&
ColoredUi
{
UiColor
Yellow
,
UiColor
Red
,
bufferUi
}
ui
.
Say
(
"foo"
)
ui
.
Say
(
"foo"
)
assert
.
Equal
(
readWriter
(
bufferUi
),
"
\0
33[1;31;40mfoo
\0
33[0m
\n
"
,
"should have color"
)
result
:=
readWriter
(
bufferUi
)
if
result
!=
"
\0
33[1;33;40mfoo
\0
33[0m
\n
"
{
t
.
Fatalf
(
"invalid output: %s"
,
result
)
}
ui
.
Message
(
"foo"
)
result
=
readWriter
(
bufferUi
)
if
result
!=
"
\0
33[0;33;40mfoo
\0
33[0m
\n
"
{
t
.
Fatalf
(
"invalid output: %s"
,
result
)
}
ui
.
Error
(
"foo"
)
result
=
readWriter
(
bufferUi
)
if
result
!=
"
\0
33[1;31;40mfoo
\0
33[0m
\n
"
{
t
.
Fatalf
(
"invalid output: %s"
,
result
)
}
}
}
func
TestPrefixedUi
(
t
*
testing
.
T
)
{
func
TestPrefixedUi
(
t
*
testing
.
T
)
{
...
...
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