|
| 1 | +package output |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "io" |
| 6 | + |
| 7 | + "github.com/common-nighthawk/go-figure" |
| 8 | +) |
| 9 | + |
| 10 | +// BannerOptions configures the startup banner display. |
| 11 | +type BannerOptions struct { |
| 12 | + ShowBanner bool // Show ASCII art logo |
| 13 | + ShowVersion bool // Show version information |
| 14 | + ShowLicense bool // Show license information |
| 15 | +} |
| 16 | + |
| 17 | +// DefaultBannerOptions returns default banner configuration. |
| 18 | +func DefaultBannerOptions() BannerOptions { |
| 19 | + return BannerOptions{ |
| 20 | + ShowBanner: true, |
| 21 | + ShowVersion: true, |
| 22 | + ShowLicense: true, |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// PrintBanner displays the pathfinder logo and information. |
| 27 | +func PrintBanner(w io.Writer, version string, opts BannerOptions) { |
| 28 | + if w == nil { |
| 29 | + return |
| 30 | + } |
| 31 | + |
| 32 | + if !opts.ShowBanner { |
| 33 | + // Simple text-only banner |
| 34 | + if opts.ShowVersion { |
| 35 | + fmt.Fprintf(w, "Code Pathfinder v%s\n", version) |
| 36 | + } |
| 37 | + if opts.ShowLicense { |
| 38 | + fmt.Fprintf(w, "AGPL-3.0 License | https://codepathfinder.dev\n") |
| 39 | + } |
| 40 | + fmt.Fprintln(w) |
| 41 | + return |
| 42 | + } |
| 43 | + |
| 44 | + // Generate ASCII art using go-figure |
| 45 | + asciiArt := GetASCIILogo() |
| 46 | + fmt.Fprintln(w, asciiArt) |
| 47 | + |
| 48 | + // Version and license info |
| 49 | + if opts.ShowVersion { |
| 50 | + fmt.Fprintf(w, "Code Pathfinder v%s\n", version) |
| 51 | + } |
| 52 | + |
| 53 | + if opts.ShowLicense { |
| 54 | + fmt.Fprintln(w, "AGPL-3.0 License | https://codepathfinder.dev") |
| 55 | + } |
| 56 | + |
| 57 | + // Empty line separator |
| 58 | + fmt.Fprintln(w) |
| 59 | +} |
| 60 | + |
| 61 | +// GetASCIILogo generates the ASCII art logo for "Pathfinder". |
| 62 | +func GetASCIILogo() string { |
| 63 | + // Use "standard" font for compact output |
| 64 | + fig := figure.NewFigure("Pathfinder", "standard", true) |
| 65 | + return fig.String() |
| 66 | +} |
| 67 | + |
| 68 | +// GetCompactBanner returns a single-line banner for non-TTY output. |
| 69 | +func GetCompactBanner(version string) string { |
| 70 | + return fmt.Sprintf("Code Pathfinder v%s | AGPL-3.0 | https://codepathfinder.dev", version) |
| 71 | +} |
| 72 | + |
| 73 | +// ShouldShowBanner determines if banner should be displayed. |
| 74 | +func ShouldShowBanner(isTTY bool, noBannerFlag bool) bool { |
| 75 | + // Never show if --no-banner is set |
| 76 | + if noBannerFlag { |
| 77 | + return false |
| 78 | + } |
| 79 | + // Show full banner only in TTY |
| 80 | + return isTTY |
| 81 | +} |
0 commit comments