Skip to content

Commit 6ca2650

Browse files
author
Enda
authored
fix(iostreams): make coloured output work on Windows (#625)
1 parent 797c937 commit 6ca2650

File tree

5 files changed

+14
-5
lines changed

5 files changed

+14
-5
lines changed

mas-mock/_data_/consumer-groups.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[
22
{
3-
"id": "consumer_group_1",
3+
"groupId": "consumer_group_1",
44
"consumers": [
55
{
66
"groupId": "consumer_group_1",
@@ -23,7 +23,7 @@
2323
]
2424
},
2525
{
26-
"id": "consumer_group_2",
26+
"groupId": "consumer_group_2",
2727
"consumers": [
2828
{
2929
"groupId": "consumer_group_2",

mas-mock/src/handlers/kafka-admin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module.exports = {
139139
};
140140

141141
function getConsumerGroup(id) {
142-
return consumerGroups.find(c => c.id === id);
142+
return consumerGroups.find(c => c.groupId === id);
143143
}
144144

145145
function getTopic(name) {

pkg/cmd/kafka/consumergroup/describe/describe.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func mapConsumerGroupDescribeToTableFormat(consumers []strimziadminclient.Consum
197197
return rows
198198
}
199199

200+
// print the consumer grooup details
200201
func printConsumerGroupDetails(w io.Writer, consumerGroupData strimziadminclient.ConsumerGroup) {
201202
fmt.Fprintln(w, "")
202203
consumers := consumerGroupData.GetConsumers()

pkg/color/color.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package color
33

44
import (
55
"fmt"
6+
"runtime"
67

78
"github.com/fatih/color"
89
)
@@ -27,6 +28,12 @@ func Error(format string) string {
2728
return color.HiRedString(format)
2829
}
2930

31+
// Bold makes a string bold
3032
func Bold(s string) string {
33+
// do not bold the string if the current OS is Windows
34+
// Command Prompt does not support ANSI escape characters
35+
if runtime.GOOS == "windows" {
36+
return s
37+
}
3138
return fmt.Sprintf("\033[1m%v\033[0m", s)
3239
}

pkg/iostreams/iostreams.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"io"
55
"os"
66

7+
"github.com/fatih/color"
78
"github.com/mattn/go-isatty"
89
)
910

@@ -92,8 +93,8 @@ func System() *IOStreams {
9293
io := &IOStreams{
9394
In: os.Stdin,
9495
originalOut: os.Stdout,
95-
Out: os.Stdout,
96-
ErrOut: os.Stderr,
96+
Out: color.Output,
97+
ErrOut: color.Error,
9798
}
9899

99100
// prevent duplicate isTerminal queries now that we know the answer

0 commit comments

Comments
 (0)