Skip to content

Commit 8a425d9

Browse files
committed
Move success marker and color to UI styles package
1 parent 0c4fd5b commit 8a425d9

8 files changed

Lines changed: 27 additions & 24 deletions

File tree

internal/output/plain_format.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"fmt"
55
"strings"
66
"time"
7+
8+
"github.com/localstack/lstk/internal/ui/styles"
79
)
810

911
// FormatEventLine converts an output event into a single display line.
@@ -49,9 +51,9 @@ func formatStatusLine(e ContainerStatusEvent) (string, bool) {
4951
return "Waiting for LocalStack to be ready...", true
5052
case "ready":
5153
if e.Detail != "" {
52-
return fmt.Sprintf("%s LocalStack ready (%s)", SuccessMarkerText(), e.Detail), true
54+
return fmt.Sprintf("%s LocalStack ready (%s)", styles.SuccessMarker(), e.Detail), true
5355
}
54-
return SuccessMarkerText() + " LocalStack ready", true
56+
return styles.SuccessMarker() + " LocalStack ready", true
5557
default:
5658
if e.Detail != "" {
5759
return fmt.Sprintf("LocalStack: %s (%s)", e.Phase, e.Detail), true
@@ -116,7 +118,7 @@ func formatAuthEvent(e AuthEvent) string {
116118
func formatMessageEvent(e MessageEvent) string {
117119
switch e.Severity {
118120
case SeveritySuccess:
119-
return SuccessMarkerText() + " " + e.Text
121+
return styles.SuccessMarker() + " " + e.Text
120122
case SeverityNote:
121123
return "> Note: " + e.Text
122124
case SeverityWarning:
@@ -151,7 +153,7 @@ func formatErrorEvent(e ErrorEvent) string {
151153

152154
func formatInstanceInfo(e InstanceInfoEvent) string {
153155
var sb strings.Builder
154-
sb.WriteString(SuccessMarkerText() + " " + e.EmulatorName + " is running (" + e.Host + ")")
156+
sb.WriteString(styles.SuccessMarker() + " " + e.EmulatorName + " is running (" + e.Host + ")")
155157
var meta []string
156158
if e.Uptime > 0 {
157159
meta = append(meta, "UPTIME: "+formatUptime(e.Uptime))

internal/output/plain_format_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"strings"
55
"testing"
66
"time"
7+
8+
"github.com/localstack/lstk/internal/ui/styles"
79
)
810

911
func TestFormatEventLine(t *testing.T) {
@@ -24,7 +26,7 @@ func TestFormatEventLine(t *testing.T) {
2426
{
2527
name: "message event success",
2628
event: MessageEvent{Severity: SeveritySuccess, Text: "done"},
27-
want: SuccessMarkerText() + " done",
29+
want: styles.SuccessMarker() + " done",
2830
wantOK: true,
2931
},
3032
{
@@ -60,7 +62,7 @@ func TestFormatEventLine(t *testing.T) {
6062
{
6163
name: "status ready with detail",
6264
event: ContainerStatusEvent{Phase: "ready", Container: "localstack-aws", Detail: "abc123"},
63-
want: SuccessMarkerText() + " LocalStack ready (abc123)",
65+
want: styles.SuccessMarker() + " LocalStack ready (abc123)",
6466
wantOK: true,
6567
},
6668
{
@@ -120,7 +122,7 @@ func TestFormatEventLine(t *testing.T) {
120122
ContainerName: "localstack-aws",
121123
Uptime: 4*time.Minute + 23*time.Second,
122124
},
123-
want: SuccessMarkerText() + " LocalStack AWS Emulator is running (localhost.localstack.cloud:4566)\n UPTIME: 4m 23s · CONTAINER: localstack-aws · VERSION: 4.14.1",
125+
want: styles.SuccessMarker() + " LocalStack AWS Emulator is running (localhost.localstack.cloud:4566)\n UPTIME: 4m 23s · CONTAINER: localstack-aws · VERSION: 4.14.1",
124126
wantOK: true,
125127
},
126128
{
@@ -129,7 +131,7 @@ func TestFormatEventLine(t *testing.T) {
129131
EmulatorName: "LocalStack AWS Emulator",
130132
Host: "127.0.0.1:4566",
131133
},
132-
want: SuccessMarkerText() + " LocalStack AWS Emulator is running (127.0.0.1:4566)",
134+
want: styles.SuccessMarker() + " LocalStack AWS Emulator is running (127.0.0.1:4566)",
133135
wantOK: true,
134136
},
135137
{

internal/output/plain_sink_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"time"
1010

11+
"github.com/localstack/lstk/internal/ui/styles"
1112
"github.com/stretchr/testify/assert"
1213
)
1314

@@ -61,12 +62,12 @@ func TestPlainSink_EmitsStatusEvent(t *testing.T) {
6162
{
6263
name: "ready phase with detail",
6364
event: ContainerStatusEvent{Phase: "ready", Container: "localstack-aws", Detail: "abc123"},
64-
expected: fmt.Sprintf("%s LocalStack ready (abc123)\n", SuccessMarkerText()),
65+
expected: fmt.Sprintf("%s LocalStack ready (abc123)\n", styles.SuccessMarker()),
6566
},
6667
{
6768
name: "ready phase without detail",
6869
event: ContainerStatusEvent{Phase: "ready", Container: "localstack-aws"},
69-
expected: fmt.Sprintf("%s LocalStack ready\n", SuccessMarkerText()),
70+
expected: fmt.Sprintf("%s LocalStack ready\n", styles.SuccessMarker()),
7071
},
7172
{
7273
name: "unknown phase with detail",
@@ -163,7 +164,7 @@ func TestPlainSink_EmitsInstanceInfoEvent(t *testing.T) {
163164
Uptime: 4*time.Minute + 23*time.Second,
164165
})
165166

166-
expected := SuccessMarkerText() + " LocalStack AWS Emulator is running (localhost.localstack.cloud:4566)\n UPTIME: 4m 23s · CONTAINER: localstack-aws · VERSION: 4.14.1\n"
167+
expected := styles.SuccessMarker() + " LocalStack AWS Emulator is running (localhost.localstack.cloud:4566)\n UPTIME: 4m 23s · CONTAINER: localstack-aws · VERSION: 4.14.1\n"
167168
assert.Equal(t, expected, out.String())
168169
assert.NoError(t, sink.Err())
169170
})
@@ -177,7 +178,7 @@ func TestPlainSink_EmitsInstanceInfoEvent(t *testing.T) {
177178
Host: "127.0.0.1:4566",
178179
})
179180

180-
expected := SuccessMarkerText() + " LocalStack AWS Emulator is running (127.0.0.1:4566)\n"
181+
expected := styles.SuccessMarker() + " LocalStack AWS Emulator is running (127.0.0.1:4566)\n"
181182
assert.Equal(t, expected, out.String())
182183
assert.NoError(t, sink.Err())
183184
})

internal/output/style.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/ui/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (a App) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
183183
}
184184
if line, ok := output.FormatEventLine(msg); ok {
185185
if msg.Phase == "ready" {
186-
line = strings.Replace(line, output.SuccessMarkerText(), styles.Success.Render(output.SuccessMarkerText()), 1)
186+
line = strings.Replace(line, styles.SuccessMarker(), styles.Success.Render(styles.SuccessMarker()), 1)
187187
}
188188
a.lines = appendLine(a.lines, styledLine{text: line})
189189
}

internal/ui/app_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/charmbracelet/lipgloss"
1212
"github.com/charmbracelet/x/exp/teatest"
1313
"github.com/localstack/lstk/internal/output"
14+
"github.com/localstack/lstk/internal/ui/styles"
1415
"github.com/muesli/termenv"
1516
)
1617

@@ -176,7 +177,7 @@ func TestAppMessageEventRendering(t *testing.T) {
176177
if len(app.lines) != 1 {
177178
t.Fatalf("expected 1 line, got %d", len(app.lines))
178179
}
179-
if !strings.Contains(app.lines[0].text, output.SuccessMarkerText()) || !strings.Contains(app.lines[0].text, "Done") {
180+
if !strings.Contains(app.lines[0].text, styles.SuccessMarker()) || !strings.Contains(app.lines[0].text, "Done") {
180181
t.Fatalf("expected rendered success message, got: %q", app.lines[0].text)
181182
}
182183
}

internal/ui/components/message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func messagePrefix(e output.MessageEvent) (string, string) {
4545
prefix := styles.Secondary.Render("> ")
4646
switch e.Severity {
4747
case output.SeveritySuccess:
48-
checkmark := output.SuccessMarkerText()
48+
checkmark := styles.SuccessMarker()
4949
return checkmark, styles.Success.Render(checkmark)
5050
case output.SeverityNote:
5151
return "> Note:", prefix + styles.Note.Render("Note:")

internal/ui/styles/styles.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@ package styles
22

33
import (
44
"github.com/charmbracelet/lipgloss"
5-
"github.com/localstack/lstk/internal/output"
65
)
76

87
const (
98
NimboDarkColor = "#3F51C7"
109
NimboMidColor = "#5E6AD2"
1110
NimboLightColor = "#7E88EC"
11+
SuccessColorHex = "#B7C95C"
1212
)
1313

14+
func SuccessMarker() string {
15+
return "✔︎"
16+
}
17+
1418
var (
1519
NimboDark = lipgloss.NewStyle().
1620
Foreground(lipgloss.Color(NimboDarkColor))
@@ -42,7 +46,7 @@ var (
4246

4347
// Message severity styles
4448
Success = lipgloss.NewStyle().
45-
Foreground(lipgloss.Color(output.SuccessColorHex))
49+
Foreground(lipgloss.Color(SuccessColorHex))
4650

4751
Note = lipgloss.NewStyle().
4852
Foreground(lipgloss.Color("33"))

0 commit comments

Comments
 (0)