bluesky viewer in the terminal
at main 3.6 kB view raw
1package ui 2 3import ( 4 "io" 5 "strings" 6 7 "github.com/charmbracelet/lipgloss" 8 "github.com/urfave/cli/v3" 9) 10 11// styleSectionHeader applies accent color to section headers (NAME:, USAGE:, etc.) 12func styleSectionHeader(s string) string { 13 if strings.HasSuffix(s, ":") { 14 return AccentStyle.Bold(true).Render(s) 15 } 16 return s 17} 18 19// styleCommandName applies primary color to command names 20func styleCommandName(s string) string { 21 return PrimaryStyle.Render(s) 22} 23 24// styleDim applies dim styling to descriptions 25func styleDim(s string) string { 26 return lipgloss.NewStyle().Faint(true).Render(s) 27} 28 29// StyledHelpPrinter is a custom help printer that uses our color system 30// It extends the default printer with custom styling functions 31func StyledHelpPrinter(w io.Writer, templ string, data any) { 32 customFuncs := map[string]any{ 33 "styleHeader": styleSectionHeader, 34 "styleCommand": styleCommandName, 35 "styleDim": styleDim, 36 "styleAccent": func(s string) string { return AccentStyle.Render(s) }, 37 "stylePrimary": func(s string) string { return PrimaryStyle.Render(s) }, 38 } 39 40 cli.DefaultPrintHelpCustom(w, templ, data, customFuncs) 41} 42 43// RootCommandHelpTemplate uses the default template structure with styling functions 44const RootCommandHelpTemplate = `{{styleHeader "NAME:"}} 45 {{template "helpNameTemplate" .}} 46 47{{styleHeader "USAGE:"}} 48 {{if .UsageText}}{{wrap .UsageText 3}}{{else}}{{.FullName}} {{if .VisibleFlags}}[global options]{{end}}{{if .VisibleCommands}} [command [command options]]{{end}}{{if .ArgsUsage}} {{.ArgsUsage}}{{else}}{{if .Arguments}} [arguments...]{{end}}{{end}}{{end}}{{if .Version}}{{if not .HideVersion}} 49 50{{styleHeader "VERSION:"}} 51 {{stylePrimary .Version}}{{end}}{{end}}{{if .Description}} 52 53{{styleHeader "DESCRIPTION:"}} 54 {{template "descriptionTemplate" .}}{{end}} 55{{- if len .Authors}} 56 57{{styleHeader "AUTHOR"}}{{template "authorsTemplate" .}}{{end}}{{if .VisibleCommands}} 58 59{{styleHeader "COMMANDS:"}}{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} 60 61{{styleHeader "GLOBAL OPTIONS:"}}{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} 62 63{{styleHeader "GLOBAL OPTIONS:"}}{{template "visibleFlagTemplate" .}}{{end}}{{if .Copyright}} 64 65{{styleHeader "COPYRIGHT:"}} 66 {{template "copyrightTemplate" .}}{{end}} 67` 68 69// CommandHelpTemplate uses the default template structure with styling 70const CommandHelpTemplate = `{{styleHeader "NAME:"}} 71 {{template "helpNameTemplate" .}} 72 73{{styleHeader "USAGE:"}} 74 {{template "usageTemplate" .}}{{if .Category}} 75 76{{styleHeader "CATEGORY:"}} 77 {{.Category}}{{end}}{{if .Description}} 78 79{{styleHeader "DESCRIPTION:"}} 80 {{template "descriptionTemplate" .}}{{end}}{{if .VisibleFlagCategories}} 81 82{{styleHeader "OPTIONS:"}}{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} 83 84{{styleHeader "OPTIONS:"}}{{template "visibleFlagTemplate" .}}{{end}} 85` 86 87// SubcommandHelpTemplate uses the default template structure with styling 88const SubcommandHelpTemplate = `{{styleHeader "NAME:"}} 89 {{template "helpNameTemplate" .}} 90 91{{styleHeader "USAGE:"}} 92 {{template "usageTemplate" .}}{{if .Category}} 93 94{{styleHeader "CATEGORY:"}} 95 {{.Category}}{{end}}{{if .Description}} 96 97{{styleHeader "DESCRIPTION:"}} 98 {{template "descriptionTemplate" .}}{{end}}{{if .VisibleCommands}} 99 100{{styleHeader "COMMANDS:"}}{{template "visibleCommandCategoryTemplate" .}}{{end}}{{if .VisibleFlagCategories}} 101 102{{styleHeader "OPTIONS:"}}{{template "visibleFlagCategoryTemplate" .}}{{else if .VisibleFlags}} 103 104{{styleHeader "OPTIONS:"}}{{template "visibleFlagTemplate" .}}{{end}} 105`