Skip to content

Commit

Permalink
Improve status visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
qbart committed Dec 5, 2021
1 parent 044a3f3 commit d548b70
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cli/color.go
Original file line number Diff line number Diff line change
@@ -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)
}
6 changes: 5 additions & 1 deletion emojis/emoji.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
4 changes: 2 additions & 2 deletions krab/action_migrate_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

}
Expand Down
2 changes: 1 addition & 1 deletion spec/action_migrate_status_arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}

0 comments on commit d548b70

Please sign in to comment.