bluesky viewer in the terminal
1package ui
2
3import (
4 "fmt"
5
6 "github.com/charmbracelet/lipgloss"
7 "github.com/stormlightlabs/skypanel/cli/internal/utils"
8)
9
10var (
11 PrimaryStyle = newStyle().Foreground(lipgloss.Color(utils.ColorPrimary))
12 AccentStyle = newStyle().Foreground(lipgloss.Color(utils.ColorAccent))
13 ErrorStyle = newStyle().Foreground(lipgloss.Color(utils.ColorError))
14 TextStyle = newStyle().Foreground(lipgloss.Color(utils.ColorText))
15 TitleStyle = newPBoldStyle(0, 1).Foreground(lipgloss.Color(utils.ColorAccent))
16 SubtitleStyle = newEmStyle().Foreground(lipgloss.Color(utils.ColorPrimary))
17 SuccessStyle = newBoldStyle().Foreground(lipgloss.Color(utils.ColorPrimary))
18 WarningStyle = newBoldStyle().Foreground(lipgloss.Color(utils.ColorAccent))
19 InfoStyle = newStyle().Foreground(lipgloss.Color(utils.ColorText))
20 BoxStyle = newPStyle(1, 2).Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(utils.ColorPrimary))
21 ErrorBoxStyle = newPStyle(1, 2).Border(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color(utils.ColorError))
22 ListItemStyle = newStyle().Foreground(lipgloss.Color(utils.ColorText)).PaddingLeft(2)
23 SelectedItemStyle = newBoldStyle().Foreground(lipgloss.Color(utils.ColorAccent)).PaddingLeft(2)
24 HeaderStyle = newPBoldStyle(0, 1).Foreground(lipgloss.Color(utils.ColorPrimary))
25 CellStyle = newPStyle(0, 1).Foreground(lipgloss.Color(utils.ColorText))
26
27 TableBaseStyle = newPStyle(0, 1)
28 TableHeaderStyle = newPStyle(0, 1).Foreground(lipgloss.Color(utils.ColorPrimary)).Bold(true)
29 TableBorderStyle = newStyle().Foreground(lipgloss.Color(utils.ColorAccent))
30 TableRowEvenStyle = newPStyle(0, 1).Foreground(lipgloss.Color("252"))
31 TableRowOddStyle = newPStyle(0, 1).Foreground(lipgloss.Color("245"))
32)
33
34func newStyle() lipgloss.Style {
35 return lipgloss.NewStyle()
36}
37
38func newPStyle(v, h int) lipgloss.Style {
39 return lipgloss.NewStyle().Padding(v, h)
40}
41
42func newBoldStyle() lipgloss.Style {
43 return newStyle().Bold(true)
44}
45
46func newPBoldStyle(v, h int) lipgloss.Style {
47 return newPStyle(v, h).Bold(true)
48}
49
50func newEmStyle() lipgloss.Style {
51 return newStyle().Italic(true)
52}
53
54// success renders a success message
55func success(msg string) string {
56 return SuccessStyle.Render("✓ " + msg)
57}
58
59// error renders an error message
60func errorMsg(msg string) string {
61 return ErrorStyle.Render("✗ " + msg)
62}
63
64// warning renders a warning message
65func warning(msg string) string {
66 return WarningStyle.Render("⚠ " + msg)
67}
68
69// info renders an info message
70func info(msg string) string {
71 return InfoStyle.Render("ℹ " + msg)
72}
73
74// title renders a title
75func title(msg string) string {
76 return TitleStyle.Render(msg)
77}
78
79// subtitle renders a subtitle
80func subtitle(msg string) string {
81 return SubtitleStyle.Render(msg)
82}
83
84// box wraps content in a styled box
85func box(content string) string {
86 return BoxStyle.Render(content)
87}
88
89// errorBox wraps error content in a styled error box
90func errorBox(content string) string {
91 return ErrorBoxStyle.Render(content)
92}
93
94// Success prints a formatted success message
95func Success(format string, a ...any) {
96 fmt.Print(success(fmt.Sprintf(format, a...)))
97}
98
99// Successln prints a formatted success message with a newline
100func Successln(format string, a ...any) {
101 fmt.Println(success(fmt.Sprintf(format, a...)))
102}
103
104// Error prints a formatted error message
105func Error(format string, a ...any) {
106 fmt.Print(errorMsg(fmt.Sprintf(format, a...)))
107}
108
109// Errorln prints a formatted error message with a newline
110func Errorln(format string, a ...any) {
111 fmt.Println(errorMsg(fmt.Sprintf(format, a...)))
112}
113
114// Warning prints a formatted warning message
115func Warning(format string, a ...any) {
116 fmt.Print(warning(fmt.Sprintf(format, a...)))
117}
118
119// Warningln prints a formatted warning message with a newline
120func Warningln(format string, a ...any) {
121 fmt.Println(warning(fmt.Sprintf(format, a...)))
122}
123
124// Info prints a formatted info message
125func Info(format string, a ...any) {
126 fmt.Print(info(fmt.Sprintf(format, a...)))
127}
128
129// Infoln prints a formatted info message with a newline
130func Infoln(format string, a ...any) {
131 fmt.Println(info(fmt.Sprintf(format, a...)))
132}
133
134// Title prints a formatted title
135func Title(format string, a ...any) {
136 fmt.Print(title(fmt.Sprintf(format, a...)))
137}
138
139// Titleln prints a formatted title with a newline
140func Titleln(format string, a ...any) {
141 fmt.Println(title(fmt.Sprintf(format, a...)))
142}
143
144// Subtitle prints a formatted subtitle
145func Subtitle(format string, a ...any) {
146 fmt.Print(subtitle(fmt.Sprintf(format, a...)))
147}
148
149// Subtitleln prints a formatted subtitle with a newline
150func Subtitleln(format string, a ...any) {
151 fmt.Println(subtitle(fmt.Sprintf(format, a...)))
152}
153
154// Box prints content in a styled box
155func Box(format string, a ...any) {
156 fmt.Print(box(fmt.Sprintf(format, a...)))
157}
158
159// Boxln prints content in a styled box with a newline
160func Boxln(format string, a ...any) {
161 fmt.Println(box(fmt.Sprintf(format, a...)))
162}
163
164// ErrorBox prints error content in a styled error box
165func ErrorBox(format string, a ...any) {
166 fmt.Print(errorBox(fmt.Sprintf(format, a...)))
167}
168
169// ErrorBoxln prints error content in a styled error box with a newline
170func ErrorBoxln(format string, a ...any) {
171 fmt.Println(errorBox(fmt.Sprintf(format, a...)))
172}