fix(cli): render glyph shortcodes in task tracker
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
50d9158920
commit
63481f127c
2 changed files with 21 additions and 1 deletions
|
|
@ -166,6 +166,8 @@ func (tr *TaskTracker) waitStatic() {
|
||||||
allDone := true
|
allDone := true
|
||||||
for i, t := range tasks {
|
for i, t := range tasks {
|
||||||
name, status, state := t.snapshot()
|
name, status, state := t.snapshot()
|
||||||
|
name = compileGlyphs(name)
|
||||||
|
status = compileGlyphs(status)
|
||||||
if state != taskDone && state != taskFailed {
|
if state != taskDone && state != taskFailed {
|
||||||
allDone = false
|
allDone = false
|
||||||
continue
|
continue
|
||||||
|
|
@ -227,6 +229,8 @@ func (tr *TaskTracker) renderLine(idx, frame int) {
|
||||||
tr.mu.Unlock()
|
tr.mu.Unlock()
|
||||||
|
|
||||||
name, status, state := t.snapshot()
|
name, status, state := t.snapshot()
|
||||||
|
name = compileGlyphs(name)
|
||||||
|
status = compileGlyphs(status)
|
||||||
nameW := tr.nameWidth()
|
nameW := tr.nameWidth()
|
||||||
|
|
||||||
var icon string
|
var icon string
|
||||||
|
|
@ -259,7 +263,7 @@ func (tr *TaskTracker) nameWidth() int {
|
||||||
defer tr.mu.Unlock()
|
defer tr.mu.Unlock()
|
||||||
w := 0
|
w := 0
|
||||||
for _, t := range tr.tasks {
|
for _, t := range tr.tasks {
|
||||||
if nameW := displayWidth(t.name); nameW > w {
|
if nameW := displayWidth(compileGlyphs(t.name)); nameW > w {
|
||||||
w = nameW
|
w = nameW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -311,6 +315,8 @@ func (tr *TaskTracker) String() string {
|
||||||
var sb strings.Builder
|
var sb strings.Builder
|
||||||
for _, t := range tasks {
|
for _, t := range tasks {
|
||||||
name, status, state := t.snapshot()
|
name, status, state := t.snapshot()
|
||||||
|
name = compileGlyphs(name)
|
||||||
|
status = compileGlyphs(status)
|
||||||
icon := Glyph(":pending:")
|
icon := Glyph(":pending:")
|
||||||
switch state {
|
switch state {
|
||||||
case taskDone:
|
case taskDone:
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,20 @@ func TestTaskTracker_Good(t *testing.T) {
|
||||||
assert.Contains(t, out, "⠋")
|
assert.Contains(t, out, "⠋")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("glyph shortcodes render in names and statuses", func(t *testing.T) {
|
||||||
|
restoreThemeAndColors(t)
|
||||||
|
UseASCII()
|
||||||
|
|
||||||
|
tr := NewTaskTracker()
|
||||||
|
tr.out = &bytes.Buffer{}
|
||||||
|
|
||||||
|
tr.Add(":check: repo").Done("done :warn:")
|
||||||
|
|
||||||
|
out := tr.String()
|
||||||
|
assert.Contains(t, out, "[OK] repo")
|
||||||
|
assert.Contains(t, out, "[WARN]")
|
||||||
|
})
|
||||||
|
|
||||||
t.Run("ASCII theme uses ASCII symbols", func(t *testing.T) {
|
t.Run("ASCII theme uses ASCII symbols", func(t *testing.T) {
|
||||||
restoreThemeAndColors(t)
|
restoreThemeAndColors(t)
|
||||||
UseASCII()
|
UseASCII()
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue