From 5d0de0da8e52989ec056dc195e78ef7c5c4187a6 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Thu, 25 Apr 2019 17:02:13 -0700 Subject: [PATCH 1/4] Standardize ASCII prefixes --- pkg/minikube/console/style.go | 84 +++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index adddc4bc6591..d19662918b31 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -24,8 +24,14 @@ import ( ) var ( - defaultLowPrefix = "- " - defautlLowIndentPrefix = " - " + // lowBullet is a bullet-point prefix for low-fi mode + lowBullet = "* " + // lowBullet is an indented bullet-point prefix for low-fi mode + lowIndent = " - " + // lowBullet is a warning prefix for low-fi mode + lowWarning = "! " + // lowBullet is an error prefix for low-fi mode + lowError = "X " ) // style describes how to stylize a message. @@ -41,47 +47,47 @@ type style struct { // styles is a map of style name to style struct // For consistency, ensure that emojis added render with the same width across platforms. var styles = map[string]style{ - "happy": {Prefix: "๐Ÿ˜„ ", LowPrefix: "o "}, + "happy": {Prefix: "๐Ÿ˜„ "}, "success": {Prefix: "โœ… "}, - "failure": {Prefix: "โŒ ", LowPrefix: "X "}, - "conflict": {Prefix: "๐Ÿ’ฅ ", LowPrefix: "x "}, - "fatal": {Prefix: "๐Ÿ’ฃ ", LowPrefix: "! "}, - "notice": {Prefix: "๐Ÿ“Œ ", LowPrefix: "* "}, - "ready": {Prefix: "๐Ÿ„ ", LowPrefix: "= "}, - "running": {Prefix: "๐Ÿƒ ", LowPrefix: ": "}, - "provisioning": {Prefix: "๐ŸŒฑ ", LowPrefix: "> "}, - "restarting": {Prefix: "๐Ÿ”„ ", LowPrefix: ": "}, - "reconfiguring": {Prefix: "๐Ÿ“ฏ ", LowPrefix: ": "}, - "stopping": {Prefix: "โœ‹ ", LowPrefix: ": "}, + "failure": {Prefix: "โŒ "}, + "conflict": {Prefix: "๐Ÿ’ฅ ", LowPrefix: lowWarning}, + "fatal": {Prefix: "๐Ÿ’ฃ ", LowPrefix: lowError}, + "notice": {Prefix: "๐Ÿ“Œ "}, + "ready": {Prefix: "๐Ÿ„ "}, + "running": {Prefix: "๐Ÿƒ "}, + "provisioning": {Prefix: "๐ŸŒฑ "}, + "restarting": {Prefix: "๐Ÿ”„ "}, + "reconfiguring": {Prefix: "๐Ÿ“ฏ "}, + "stopping": {Prefix: "โœ‹ "}, "stopped": {Prefix: "๐Ÿ›‘ "}, - "warning": {Prefix: "โš ๏ธ ", LowPrefix: "! "}, - "waiting": {Prefix: "โŒ› ", LowPrefix: ": "}, - "waiting-pods": {Prefix: "โŒ› ", LowPrefix: ": ", OmitNewline: true}, + "warning": {Prefix: "โš ๏ธ ", LowPrefix: lowWarning}, + "waiting": {Prefix: "โŒ› "}, + "waiting-pods": {Prefix: "โŒ› ", OmitNewline: true}, "usage": {Prefix: "๐Ÿ’ก "}, "launch": {Prefix: "๐Ÿš€ "}, - "sad": {Prefix: "๐Ÿ˜ฟ ", LowPrefix: "* "}, + "sad": {Prefix: "๐Ÿ˜ฟ "}, "thumbs-up": {Prefix: "๐Ÿ‘ "}, - "option": {Prefix: " โ–ช "}, // Indented bullet - "command": {Prefix: " โ–ช "}, // Indented bullet - "log-entry": {Prefix: " "}, // Indent + "option": {Prefix: " โ–ช ", LowPrefix: lowIndent}, // Indented bullet + "command": {Prefix: " โ–ช ", LowPrefix: lowIndent}, // Indented bullet + "log-entry": {Prefix: " "}, // Indent "crushed": {Prefix: "๐Ÿ’” "}, - "url": {Prefix: "๐Ÿ‘‰ "}, + "url": {Prefix: "๐Ÿ‘‰ ", LowPrefix: lowIndent}, "documentation": {Prefix: "๐Ÿ“˜ "}, "issues": {Prefix: "โ‰๏ธ "}, - "issue": {Prefix: " โ–ช "}, // Indented bullet + "issue": {Prefix: " โ–ช ", LowPrefix: lowIndent}, // Indented bullet "check": {Prefix: "โœ”๏ธ "}, // Specialized purpose styles - "iso-download": {Prefix: "๐Ÿ’ฟ ", LowPrefix: "@ "}, - "file-download": {Prefix: "๐Ÿ’พ ", LowPrefix: "@ "}, - "caching": {Prefix: "๐Ÿคน ", LowPrefix: "$ "}, - "starting-vm": {Prefix: "๐Ÿ”ฅ ", LowPrefix: "> "}, - "starting-none": {Prefix: "๐Ÿคน ", LowPrefix: "> "}, - "resetting": {Prefix: "๐Ÿ”„ ", LowPrefix: "# "}, - "deleting-host": {Prefix: "๐Ÿ”ฅ ", LowPrefix: "x "}, + "iso-download": {Prefix: "๐Ÿ’ฟ "}, + "file-download": {Prefix: "๐Ÿ’พ "}, + "caching": {Prefix: "๐Ÿคน "}, + "starting-vm": {Prefix: "๐Ÿ”ฅ "}, + "starting-none": {Prefix: "๐Ÿคน "}, + "resetting": {Prefix: "๐Ÿ”„ "}, + "deleting-host": {Prefix: "๐Ÿ”ฅ "}, "copying": {Prefix: "โœจ "}, "connectivity": {Prefix: "๐Ÿ“ถ "}, - "internet": {Prefix: "๐ŸŒ ", LowPrefix: "o "}, + "internet": {Prefix: "๐ŸŒ "}, "mounting": {Prefix: "๐Ÿ“ "}, "celebrate": {Prefix: "๐ŸŽ‰ "}, "container-runtime": {Prefix: "๐ŸŽ "}, @@ -94,13 +100,13 @@ var styles = map[string]style{ "pulling": {Prefix: "๐Ÿšœ "}, "verifying": {Prefix: "๐Ÿค” "}, "verifying-noline": {Prefix: "๐Ÿค” ", OmitNewline: true}, - "kubectl": {Prefix: "๐Ÿ’— ", LowPrefix: "+ "}, - "meh": {Prefix: "๐Ÿ™„ ", LowPrefix: "? "}, - "embarrassed": {Prefix: "๐Ÿคฆ ", LowPrefix: "* "}, - "tip": {Prefix: "๐Ÿ’ก ", LowPrefix: "i "}, - "unmount": {Prefix: "๐Ÿ”ฅ ", LowPrefix: "x "}, - "mount-options": {Prefix: "๐Ÿ’พ ", LowPrefix: "o "}, - "fileserver": {Prefix: "๐Ÿš€ ", LowPrefix: "@ ", OmitNewline: true}, + "kubectl": {Prefix: "๐Ÿ’— "}, + "meh": {Prefix: "๐Ÿ™„ ", LowPrefix: lowWarning}, + "embarrassed": {Prefix: "๐Ÿคฆ ", LowPrefix: lowWarning}, + "tip": {Prefix: "๐Ÿ’ก "}, + "unmount": {Prefix: "๐Ÿ”ฅ "}, + "mount-options": {Prefix: "๐Ÿ’พ "}, + "fileserver": {Prefix: "๐Ÿš€ ", OmitNewline: true}, } // Add a prefix to a string @@ -123,9 +129,9 @@ func lowPrefix(s style) string { return s.LowPrefix } if strings.HasPrefix(s.Prefix, " ") { - return defautlLowIndentPrefix + return lowIndent } - return defaultLowPrefix + return lowBullet } // Apply styling to a format string From 04346b31e13d4eb8d8f93c4fbda40c340185ce02 Mon Sep 17 00:00:00 2001 From: tstromberg Date: Thu, 2 May 2019 10:41:33 -0700 Subject: [PATCH 2/4] Change lowBullet to > based on poll results --- pkg/minikube/console/console_test.go | 8 ++++---- pkg/minikube/console/style.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/minikube/console/console_test.go b/pkg/minikube/console/console_test.go index a12f6ae78df2..39d32f086e8f 100644 --- a/pkg/minikube/console/console_test.go +++ b/pkg/minikube/console/console_test.go @@ -65,15 +65,15 @@ func TestOutStyle(t *testing.T) { " โ–ช Message with params: encode '%' signs %s%%%d\n", }, - {"happy", "false", "This is happy.", nil, "o This is happy.\n"}, - {"Docker", "false", "This is Docker.", nil, "- This is Docker.\n"}, - {"option", "false", "This is option.", nil, " - This is option.\n"}, + {"happy", "false", "This is happy.", nil, "> This is happy.\n"}, + {"Docker", "false", "This is Docker.", nil, "> This is Docker.\n"}, + {"option", "false", "This is option.", nil, " - This is option.\n"}, { "option", "false", "Message with params: %s %s", []interface{}{"encode '%' signs", "%s%%%d"}, - " - Message with params: encode '%' signs %s%%%d\n", + " - Message with params: encode '%' signs %s%%%d\n", }, } for _, tc := range tests { diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index d19662918b31..ed4787608e93 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -25,7 +25,7 @@ import ( var ( // lowBullet is a bullet-point prefix for low-fi mode - lowBullet = "* " + lowBullet = "> " // lowBullet is an indented bullet-point prefix for low-fi mode lowIndent = " - " // lowBullet is a warning prefix for low-fi mode From 5978555826a3e68640cf68760a2d14255236b20d Mon Sep 17 00:00:00 2001 From: tstromberg Date: Thu, 2 May 2019 16:10:01 -0700 Subject: [PATCH 3/4] Improve TestOutStyle --- pkg/minikube/console/console_test.go | 73 +++++++++++++--------------- 1 file changed, 33 insertions(+), 40 deletions(-) diff --git a/pkg/minikube/console/console_test.go b/pkg/minikube/console/console_test.go index 79c0c87c5684..4fe1958f70cc 100644 --- a/pkg/minikube/console/console_test.go +++ b/pkg/minikube/console/console_test.go @@ -18,7 +18,9 @@ package console import ( "bytes" + "fmt" "os" + "strconv" "testing" "golang.org/x/text/language" @@ -48,49 +50,40 @@ func (f *fakeFile) String() string { func TestOutStyle(t *testing.T) { var tests = []struct { - style string - envValue string - message string - params []interface{} - want string + style string + message string + params []interface{} + want string + wantASCII string }{ - {"happy", "true", "This is happy.", nil, "๐Ÿ˜„ This is happy.\n"}, - {"Docker", "true", "This is Docker.", nil, "๐Ÿณ This is Docker.\n"}, - {"option", "true", "This is option.", nil, " โ–ช This is option.\n"}, - { - "option", - "true", - "Message with params: %s %s", - []interface{}{"encode '%' signs", "%s%%%d"}, - " โ–ช Message with params: encode '%' signs %s%%%d\n", - }, - - {"happy", "false", "This is happy.", nil, "> This is happy.\n"}, - {"Docker", "false", "This is Docker.", nil, "> This is Docker.\n"}, - {"option", "false", "This is option.", nil, " - This is option.\n"}, - { - "option", - "false", - "Message with params: %s %s", - []interface{}{"encode '%' signs", "%s%%%d"}, - " - Message with params: encode '%' signs %s%%%d\n", - }, - {"issue", "true", "No separators for long ints: %d", []interface{}{10000}, " โ–ช No separators for long ints: 10000\n"}, - {"issue", "false", "No separators for long ints: %d", []interface{}{5000}, " - No separators for long ints: 5000\n"}, + {"happy", "Happy", nil, "๐Ÿ˜„ Happy\n", "> Happy\n"}, + {"option", "Option", nil, " โ–ช Option\n", " - Option\n"}, + {"warning", "Warning", nil, "โš ๏ธ Warning\n", "! Warning\n"}, + {"fatal", "Fatal: %v", []interface{}{"ugh"}, "๐Ÿ’ฃ Fatal: ugh\n", "X Fatal: ugh\n"}, + {"waiting-pods", "wait", nil, "โŒ› wait", "> wait"}, + {"issue", "http://i/%d", []interface{}{10000}, " โ–ช http://i/10000\n", " - http://i/10000\n"}, + {"usage", "raw: %s %s", []interface{}{"'%'", "%d"}, "๐Ÿ’ก raw: '%' %d\n", "> raw: '%' %d\n"}, } for _, tc := range tests { - t.Run(tc.style+"-"+tc.envValue, func(t *testing.T) { - os.Setenv(OverrideEnv, tc.envValue) - f := newFakeFile() - SetOutFile(f) - if err := OutStyle(tc.style, tc.message, tc.params...); err != nil { - t.Errorf("unexpected error: %q", err) - } - got := f.String() - if got != tc.want { - t.Errorf("OutStyle() = %q, want %q", got, tc.want) - } - }) + for _, override := range []bool{true, false} { + t.Run(fmt.Sprintf("%s-override-%v", tc.style, override), func(t *testing.T) { + // Set MINIKUBE_IN_STYLE= + os.Setenv(OverrideEnv, strconv.FormatBool(override)) + f := newFakeFile() + SetOutFile(f) + if err := OutStyle(tc.style, tc.message, tc.params...); err != nil { + t.Errorf("unexpected error: %q", err) + } + got := f.String() + want := tc.wantASCII + if override { + want = tc.want + } + if got != want { + t.Errorf("OutStyle() = %q (%d runes), want %q (%d runes)", got, len(got), want, len(want)) + } + }) + } } } From 283d54caedfde9a12b50182c9d2a2c55a7d0f6ff Mon Sep 17 00:00:00 2001 From: tstromberg Date: Mon, 6 May 2019 11:57:19 -0700 Subject: [PATCH 4/4] Asterisks won in the votes --- pkg/minikube/console/console_test.go | 6 +++--- pkg/minikube/console/style.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/minikube/console/console_test.go b/pkg/minikube/console/console_test.go index 4fe1958f70cc..6692101c2b45 100644 --- a/pkg/minikube/console/console_test.go +++ b/pkg/minikube/console/console_test.go @@ -56,13 +56,13 @@ func TestOutStyle(t *testing.T) { want string wantASCII string }{ - {"happy", "Happy", nil, "๐Ÿ˜„ Happy\n", "> Happy\n"}, + {"happy", "Happy", nil, "๐Ÿ˜„ Happy\n", "* Happy\n"}, {"option", "Option", nil, " โ–ช Option\n", " - Option\n"}, {"warning", "Warning", nil, "โš ๏ธ Warning\n", "! Warning\n"}, {"fatal", "Fatal: %v", []interface{}{"ugh"}, "๐Ÿ’ฃ Fatal: ugh\n", "X Fatal: ugh\n"}, - {"waiting-pods", "wait", nil, "โŒ› wait", "> wait"}, + {"waiting-pods", "wait", nil, "โŒ› wait", "* wait"}, {"issue", "http://i/%d", []interface{}{10000}, " โ–ช http://i/10000\n", " - http://i/10000\n"}, - {"usage", "raw: %s %s", []interface{}{"'%'", "%d"}, "๐Ÿ’ก raw: '%' %d\n", "> raw: '%' %d\n"}, + {"usage", "raw: %s %s", []interface{}{"'%'", "%d"}, "๐Ÿ’ก raw: '%' %d\n", "* raw: '%' %d\n"}, } for _, tc := range tests { for _, override := range []bool{true, false} { diff --git a/pkg/minikube/console/style.go b/pkg/minikube/console/style.go index c47af699b9b8..022dadb580f9 100644 --- a/pkg/minikube/console/style.go +++ b/pkg/minikube/console/style.go @@ -26,7 +26,7 @@ import ( var ( // lowBullet is a bullet-point prefix for low-fi mode - lowBullet = "> " + lowBullet = "* " // lowBullet is an indented bullet-point prefix for low-fi mode lowIndent = " - " // lowBullet is a warning prefix for low-fi mode