One color package to rule them all.

This commit is contained in:
Arturo Filastò
2018-06-29 16:50:05 +02:00
parent c4c13cb279
commit d8cbfd1b90
6 changed files with 28 additions and 69 deletions
+2 -2
View File
@@ -9,8 +9,8 @@ import (
"github.com/alecthomas/kingpin"
"github.com/apex/log"
"github.com/fatih/color"
"github.com/ooni/probe-cli/internal/cli/root"
"github.com/ooni/probe-cli/internal/colors"
"github.com/ooni/probe-cli/internal/database"
"github.com/ooni/probe-cli/nettests"
"github.com/ooni/probe-cli/nettests/groups"
@@ -22,7 +22,7 @@ func init() {
var nettestGroupNames []string
for name := range groups.NettestGroups {
nettestGroupNames = append(nettestGroupNames, colors.Blue(name))
nettestGroupNames = append(nettestGroupNames, color.BlueString(name))
}
nettestGroup := cmd.Arg("name",
-40
View File
@@ -1,40 +0,0 @@
package colors
import (
color "github.com/aybabtme/rgbterm"
)
// Gray string.
func Gray(s string) string {
return color.FgString(s, 150, 150, 150)
}
// Blue string.
func Blue(s string) string {
return color.FgString(s, 77, 173, 247)
}
// Cyan string.
func Cyan(s string) string {
return color.FgString(s, 34, 184, 207)
}
// Green string.
func Green(s string) string {
return color.FgString(s, 0, 200, 255)
}
// Red string.
func Red(s string) string {
return color.FgString(s, 194, 37, 92)
}
// Yellow string.
func Yellow(s string) string {
return color.FgString(s, 252, 196, 25)
}
// Purple string.
func Purple(s string) string {
return color.FgString(s, 96, 97, 190)
}
+5 -5
View File
@@ -4,8 +4,8 @@ import (
"fmt"
"github.com/apex/log"
"github.com/fatih/color"
"github.com/ooni/probe-cli/config"
"github.com/ooni/probe-cli/internal/colors"
"github.com/ooni/probe-cli/internal/output"
survey "gopkg.in/AlecAivazis/survey.v1"
)
@@ -42,10 +42,10 @@ func Onboarding(config *config.Config) error {
}
survey.AskOne(quiz1, &answer, nil)
if answer != "true" {
output.Paragraph(colors.Red("Actually..."))
output.Paragraph(color.RedString("Actually..."))
output.Paragraph("OONI Probe is not a privacy tool. Therefore, anyone monitoring your internet activity may be able to see which software you are running.")
} else {
output.Paragraph(colors.Blue("Good job!"))
output.Paragraph(color.BlueString("Good job!"))
}
answer = ""
quiz2 := &survey.Select{
@@ -55,10 +55,10 @@ func Onboarding(config *config.Config) error {
}
survey.AskOne(quiz2, &answer, nil)
if answer != "true" {
output.Paragraph(colors.Red("Actually..."))
output.Paragraph(color.RedString("Actually..."))
output.Paragraph("The network data you will collect will automatically be published to increase transparency of internet censorship (unless you opt-out in the settings).")
} else {
output.Paragraph(colors.Blue("Well done!"))
output.Paragraph(color.BlueString("Well done!"))
}
changeDefaults := false
+3 -3
View File
@@ -9,17 +9,17 @@ import (
"unicode"
"unicode/utf8"
"github.com/ooni/probe-cli/internal/colors"
"github.com/fatih/color"
)
// Log outputs a log message.
func Log(msg string, v ...interface{}) {
fmt.Printf(" %s\n", colors.Purple(fmt.Sprintf(msg, v...)))
fmt.Printf(" %s\n", color.CyanString(msg, v...))
}
// Fatal error
func Fatal(err error) {
fmt.Fprintf(os.Stderr, "\n %s %s\n\n", colors.Red("Error:"), err)
fmt.Fprintf(os.Stderr, "\n %s %s\n\n", color.RedString("Error:"), err)
os.Exit(1)
}
+1 -2
View File
@@ -4,14 +4,13 @@ import (
"testing"
"github.com/fatih/color"
ocolor "github.com/ooni/probe-cli/internal/colors"
)
func TestEscapeAwareRuneCountInString(t *testing.T) {
var bold = color.New(color.Bold)
var myColor = color.New(color.FgBlue)
s := myColor.Sprintf("•ABC%s%s", bold.Sprintf("DEF"), ocolor.Red("GHI"))
s := myColor.Sprintf("•ABC%s%s", bold.Sprintf("DEF"), "\x1B[00;38;5;244m\x1B[m\x1B[00;38;5;33mGHI\x1B[0m")
count := EscapeAwareRuneCountInString(s)
if count != 10 {
t.Errorf("Count was incorrect, got: %d, want: %d.", count, 10)