From d548b708f1683dce233c88283c589fc15de9cb05 Mon Sep 17 00:00:00 2001 From: qbart Date: Sun, 5 Dec 2021 23:38:02 +0100 Subject: [PATCH] Improve status visuals --- cli/color.go | 12 ++++++++++++ emojis/emoji.go | 6 +++++- krab/action_migrate_status.go | 4 ++-- spec/action_migrate_status_arguments_test.go | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 cli/color.go diff --git a/cli/color.go b/cli/color.go new file mode 100644 index 0000000..0851811 --- /dev/null +++ b/cli/color.go @@ -0,0 +1,12 @@ +package cli + +import ( + "fmt" + + "github.com/wzshiming/ctc" +) + +// Red colorizes output. +func Red(s string) string { + return fmt.Sprint(ctc.ForegroundRed, s, ctc.Reset) +} diff --git a/emojis/emoji.go b/emojis/emoji.go index 68a4a62..28067e2 100644 --- a/emojis/emoji.go +++ b/emojis/emoji.go @@ -8,10 +8,14 @@ import ( // CheckMarkColor ✔ emoji func CheckMarkColor(color ctc.Color) string { - return fmt.Sprintf("%s%c%s ", color, '\u2714', ctc.Reset) + return fmt.Sprint(color, ByCode('\u2714'), ctc.Reset) } // CheckMark green check mark func CheckMark() string { return CheckMarkColor(ctc.ForegroundGreen) } + +func ByCode(code rune) string { + return fmt.Sprintf("%c", code) +} diff --git a/krab/action_migrate_status.go b/krab/action_migrate_status.go index f958763..73dc496 100644 --- a/krab/action_migrate_status.go +++ b/krab/action_migrate_status.go @@ -98,9 +98,9 @@ func (a *ActionMigrateStatus) Do(ctx context.Context, db krabdb.DB, tpl *tpls.Te pending := !appliedMigrations.Contains(migration.Version) if pending { - ui.Error(fmt.Sprint("- ", migration.Version, " ", migration.RefName)) + ui.Output(cli.Red(fmt.Sprint("- ", migration.Version, " ", migration.RefName))) } else { - ui.Output(fmt.Sprint(emojis.CheckMark(), migration.Version, " ", migration.RefName)) + ui.Output(fmt.Sprint(emojis.CheckMark(), " ", migration.Version, " ", migration.RefName)) } } diff --git a/spec/action_migrate_status_arguments_test.go b/spec/action_migrate_status_arguments_test.go index 6e84ee3..49ed1d0 100644 --- a/spec/action_migrate_status_arguments_test.go +++ b/spec/action_migrate_status_arguments_test.go @@ -30,5 +30,5 @@ migration_set "animals" { c.AssertSuccessfulRun(t, []string{"migrate", "up", "animals", "-schema", "custom"}) c.AssertSuccessfulRun(t, []string{"migrate", "status", "animals", "-schema", "custom"}) - c.AssertOutputContains(t, fmt.Sprint(emojis.CheckMark(), "v1 create_animals")) + c.AssertOutputContains(t, fmt.Sprint(emojis.CheckMark(), " v1 create_animals")) }