cli + tui to publish to leaflet (wip) & manage tasks, notes & watch/read lists 🍃
charm leaflet readability golang
at main 156 lines 5.4 kB view raw
1package ui 2 3import ( 4 "fmt" 5 6 "github.com/charmbracelet/lipgloss" 7) 8 9// Style constructor helpers 10func newStyle() lipgloss.Style { return lipgloss.NewStyle() } 11func newPStyle(v, h int) lipgloss.Style { return lipgloss.NewStyle().Padding(v, h) } 12func newBoldStyle() lipgloss.Style { return newStyle().Bold(true) } 13func newPBoldStyle(v, h int) lipgloss.Style { return newPStyle(v, h).Bold(true) } 14func newEmStyle() lipgloss.Style { return newStyle().Italic(true) } 15 16// Rendering helpers (private, used by public API) 17func success(msg string) string { return SuccessStyle.Render("✓ " + msg) } 18func errorMsg(msg string) string { return ErrorStyle.Render("✗ " + msg) } 19func warning(msg string) string { return WarningStyle.Render("⚠ " + msg) } 20func info(msg string) string { return InfoStyle.Render("ℹ " + msg) } 21func infop(msg string) string { return InfoStyle.Render(msg) } 22func title(msg string) string { return TitleStyle.Render(msg) } 23func subtitle(msg string) string { return SubtitleStyle.Render(msg) } 24func box(content string) string { return BoxStyle.Render(content) } 25func errorBox(content string) string { return ErrorBoxStyle.Render(content) } 26func text(content string) string { return TextStyle.Render(content) } 27func muted(content string) string { return MutedStyle.Render(content) } 28func accent(content string) string { return AccentStyle.Render(content) } 29func header(content string) string { return HeaderStyle.Render(content) } 30func primary(content string) string { return PrimaryStyle.Render(content) } 31 32// Success prints a formatted success message 33func Success(format string, a ...any) { 34 fmt.Print(success(fmt.Sprintf(format, a...))) 35} 36 37// Successln prints a formatted success message with a newline 38func Successln(format string, a ...any) { 39 fmt.Println(success(fmt.Sprintf(format, a...))) 40} 41 42// Error prints a formatted error message 43func Error(format string, a ...any) { 44 fmt.Print(errorMsg(fmt.Sprintf(format, a...))) 45} 46 47// Errorln prints a formatted error message with a newline 48func Errorln(format string, a ...any) { 49 fmt.Println(errorMsg(fmt.Sprintf(format, a...))) 50} 51 52// Warning prints a formatted warning message 53func Warning(format string, a ...any) { 54 fmt.Print(warning(fmt.Sprintf(format, a...))) 55} 56 57// Warningln prints a formatted warning message with a newline 58func Warningln(format string, a ...any) { 59 fmt.Println(warning(fmt.Sprintf(format, a...))) 60} 61 62// Info prints a formatted info message 63func Info(format string, a ...any) { 64 fmt.Print(info(fmt.Sprintf(format, a...))) 65} 66 67// Infoln prints a formatted info message with a newline 68func Infoln(format string, a ...any) { 69 fmt.Println(infop(fmt.Sprintf(format, a...))) 70} 71 72// Infop prints a formatted info message, sans icon 73func Infop(format string, a ...any) { 74 fmt.Print(infop(fmt.Sprintf(format, a...))) 75} 76 77// Infopln prints a formatted info message with a newline, sans icon 78func Infopln(format string, a ...any) { 79 fmt.Println(info(fmt.Sprintf(format, a...))) 80} 81 82// Title prints a formatted title 83func Title(format string, a ...any) { 84 fmt.Print(title(fmt.Sprintf(format, a...))) 85} 86 87// Titleln prints a formatted title with a newline 88func Titleln(format string, a ...any) { 89 fmt.Println(title(fmt.Sprintf(format, a...))) 90} 91 92// Subtitle prints a formatted subtitle 93func Subtitle(format string, a ...any) { 94 fmt.Print(subtitle(fmt.Sprintf(format, a...))) 95} 96 97// Subtitleln prints a formatted subtitle with a newline 98func Subtitleln(format string, a ...any) { 99 fmt.Println(subtitle(fmt.Sprintf(format, a...))) 100} 101 102// Box prints content in a styled box 103func Box(format string, a ...any) { 104 fmt.Print(box(fmt.Sprintf(format, a...))) 105} 106 107// Boxln prints content in a styled box with a newline 108func Boxln(format string, a ...any) { 109 fmt.Println(box(fmt.Sprintf(format, a...))) 110} 111 112// ErrorBox prints error content in a styled error box 113func ErrorBox(format string, a ...any) { 114 fmt.Print(errorBox(fmt.Sprintf(format, a...))) 115} 116 117// ErrorBoxln prints error content in a styled error box with a newline 118func ErrorBoxln(format string, a ...any) { 119 fmt.Println(errorBox(fmt.Sprintf(format, a...))) 120} 121 122func Newline() { fmt.Println() } 123func Plain(format string, a ...any) { fmt.Print(text(fmt.Sprintf(format, a...))) } 124func Plainln(format string, a ...any) { fmt.Println(text(fmt.Sprintf(format, a...))) } 125func Header(format string, a ...any) { fmt.Print(header(fmt.Sprintf(format, a...))) } 126func Headerln(format string, a ...any) { fmt.Println(header(fmt.Sprintf(format, a...))) } 127 128// Muted prints muted/secondary text 129func Muted(format string, a ...any) { 130 fmt.Print(muted(fmt.Sprintf(format, a...))) 131} 132 133// Mutedln prints muted/secondary text with a newline 134func Mutedln(format string, a ...any) { 135 fmt.Println(muted(fmt.Sprintf(format, a...))) 136} 137 138// Accent prints accent-colored text 139func Accent(format string, a ...any) { 140 fmt.Print(accent(fmt.Sprintf(format, a...))) 141} 142 143// Accentln prints accent-colored text with a newline 144func Accentln(format string, a ...any) { 145 fmt.Println(accent(fmt.Sprintf(format, a...))) 146} 147 148// Primary prints primary-colored text 149func Primary(format string, a ...any) { 150 fmt.Print(primary(fmt.Sprintf(format, a...))) 151} 152 153// Primaryln prints primary-colored text with a newline 154func Primaryln(format string, a ...any) { 155 fmt.Println(primary(fmt.Sprintf(format, a...))) 156}