mirror of
https://github.com/Dvorinka/Devour.git
synced 2026-06-03 20:13:03 +00:00
first commit
This commit is contained in:
@@ -0,0 +1,206 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Version information (set via ldflags at build time)
|
||||
var (
|
||||
Version = "dev"
|
||||
BuildDate = "unknown"
|
||||
GitCommit = "unknown"
|
||||
)
|
||||
|
||||
// ANSI color codes for terminal output
|
||||
const (
|
||||
ColorReset = "\033[0m"
|
||||
ColorCyan = "\033[36m"
|
||||
ColorTeal = "\033[38;5;37m"
|
||||
ColorBold = "\033[1m"
|
||||
ColorDim = "\033[2m"
|
||||
ColorItalic = "\033[3m"
|
||||
)
|
||||
|
||||
// IsColorSupported checks if the terminal supports colors
|
||||
func IsColorSupported() bool {
|
||||
// Check if stdout is a terminal
|
||||
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
|
||||
// Check for NO_COLOR environment variable
|
||||
if os.Getenv("NO_COLOR") != "" {
|
||||
return false
|
||||
}
|
||||
// Check for TERM variable
|
||||
term := os.Getenv("TERM")
|
||||
return term != "" && term != "dumb"
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Colorize returns a colorized string if colors are supported
|
||||
func Colorize(text, colorCode string) string {
|
||||
if IsColorSupported() {
|
||||
return colorCode + text + ColorReset
|
||||
}
|
||||
return text
|
||||
}
|
||||
|
||||
// PrintHeader prints a styled header with the Devour branding
|
||||
func PrintHeader(title string) {
|
||||
useColor := IsColorSupported()
|
||||
border := strings.Repeat("=", len(title)+4)
|
||||
|
||||
if useColor {
|
||||
fmt.Printf("%s%s%s\n", ColorCyan, border, ColorReset)
|
||||
fmt.Printf("%s %s %s\n", ColorCyan+ColorBold, title, ColorReset)
|
||||
fmt.Printf("%s%s%s\n", ColorCyan, border, ColorReset)
|
||||
} else {
|
||||
fmt.Println(border)
|
||||
fmt.Printf(" %s \n", title)
|
||||
fmt.Println(border)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintSection prints a section header
|
||||
func PrintSection(title string) {
|
||||
useColor := IsColorSupported()
|
||||
line := strings.Repeat("-", 40)
|
||||
|
||||
if useColor {
|
||||
fmt.Printf("\n%s%s%s\n", ColorTeal, line, ColorReset)
|
||||
fmt.Printf("%s%s%s\n", ColorTeal+ColorBold, title, ColorReset)
|
||||
fmt.Printf("%s%s%s\n", ColorTeal, line, ColorReset)
|
||||
} else {
|
||||
fmt.Printf("\n%s\n", line)
|
||||
fmt.Println(title)
|
||||
fmt.Printf("%s\n", line)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintKeyValue prints a key-value pair with styling
|
||||
func PrintKeyValue(key, value string) {
|
||||
useColor := IsColorSupported()
|
||||
|
||||
if useColor {
|
||||
fmt.Printf(" %s%-20s%s %s\n", ColorCyan, key+":", ColorReset, value)
|
||||
} else {
|
||||
fmt.Printf(" %-20s %s\n", key+":", value)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintSuccess prints a success message
|
||||
func PrintSuccess(message string) {
|
||||
useColor := IsColorSupported()
|
||||
|
||||
if useColor {
|
||||
fmt.Printf("%s%s%s %s\n", ColorCyan, "SUCCESS:", ColorReset, message)
|
||||
} else {
|
||||
fmt.Printf("SUCCESS: %s\n", message)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintError prints an error message
|
||||
func PrintError(message string) {
|
||||
fmt.Fprintf(os.Stderr, "ERROR: %s\n", message)
|
||||
}
|
||||
|
||||
// PrintWarning prints a warning message
|
||||
func PrintWarning(message string) {
|
||||
fmt.Printf("WARNING: %s\n", message)
|
||||
}
|
||||
|
||||
// PrintInfo prints an info message
|
||||
func PrintInfo(message string) {
|
||||
useColor := IsColorSupported()
|
||||
|
||||
if useColor {
|
||||
fmt.Printf("%s%s%s\n", ColorDim, message, ColorReset)
|
||||
} else {
|
||||
fmt.Println(message)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintVersionInfo prints detailed version information
|
||||
func PrintVersionInfo() {
|
||||
PrintHeader("Devour Version Info")
|
||||
PrintKeyValue("Version", Version)
|
||||
PrintKeyValue("Build Date", BuildDate)
|
||||
PrintKeyValue("Git Commit", GitCommit)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// PrintHelpBanner prints the help banner with character
|
||||
func PrintHelpBanner() {
|
||||
PrintBanner(Version)
|
||||
}
|
||||
|
||||
// PrintStartupBanner prints the startup banner for interactive sessions
|
||||
func PrintStartupBanner() {
|
||||
PrintWelcome(Version)
|
||||
}
|
||||
|
||||
// BoxStyle defines a box drawing style
|
||||
type BoxStyle struct {
|
||||
TopLeft string
|
||||
TopRight string
|
||||
BottomLeft string
|
||||
BottomRight string
|
||||
Horizontal string
|
||||
Vertical string
|
||||
}
|
||||
|
||||
// DefaultBoxStyle is the default box style
|
||||
var DefaultBoxStyle = BoxStyle{
|
||||
TopLeft: " ",
|
||||
TopRight: " ",
|
||||
BottomLeft: " ",
|
||||
BottomRight: " ",
|
||||
Horizontal: " ",
|
||||
Vertical: " ",
|
||||
}
|
||||
|
||||
// DoubleBoxStyle uses double-line box characters
|
||||
var DoubleBoxStyle = BoxStyle{
|
||||
TopLeft: " ",
|
||||
TopRight: " ",
|
||||
BottomLeft: " ",
|
||||
BottomRight: " ",
|
||||
Horizontal: " ",
|
||||
Vertical: " ",
|
||||
}
|
||||
|
||||
// PrintInBox prints text inside a box
|
||||
func PrintInBox(text string, style BoxStyle) {
|
||||
lines := strings.Split(text, "\n")
|
||||
maxWidth := 0
|
||||
for _, line := range lines {
|
||||
if len(line) > maxWidth {
|
||||
maxWidth = len(line)
|
||||
}
|
||||
}
|
||||
|
||||
// Top border
|
||||
fmt.Printf("%s%s%s\n", style.TopLeft, strings.Repeat(style.Horizontal, maxWidth+2), style.TopRight)
|
||||
|
||||
// Content
|
||||
for _, line := range lines {
|
||||
padding := maxWidth - len(line)
|
||||
fmt.Printf("%s %s%s %s\n", style.Vertical, line, strings.Repeat(" ", padding), style.Vertical)
|
||||
}
|
||||
|
||||
// Bottom border
|
||||
fmt.Printf("%s%s%s\n", style.BottomLeft, strings.Repeat(style.Horizontal, maxWidth+2), style.BottomRight)
|
||||
}
|
||||
|
||||
// PrintDivider prints a horizontal divider
|
||||
func PrintDivider() {
|
||||
useColor := IsColorSupported()
|
||||
line := strings.Repeat(" ", 50)
|
||||
|
||||
if useColor {
|
||||
fmt.Printf("%s%s%s\n", ColorDim, line, ColorReset)
|
||||
} else {
|
||||
fmt.Println(line)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,179 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// DevourCharacter is the ASCII art representation of the Devour mascot
|
||||
// A documentation-devouring creature with cyan/teal coloring
|
||||
const DevourCharacter = `
|
||||
___
|
||||
.-' '-.
|
||||
/ \
|
||||
| O O |
|
||||
| __ |
|
||||
\ ' ' /
|
||||
'-.___.-'
|
||||
___ / \ ___
|
||||
_.-' '/ \' '-._
|
||||
_.-' | | '-._
|
||||
/ \ ___ / \
|
||||
| __ \ / \ / __ |
|
||||
| .' '. .---. | | .---. .' '. |
|
||||
| | | | | | | | | | | |
|
||||
\ \__/ / | | | | | \__/ /
|
||||
'.____.' | | | | '.____.'
|
||||
| | | |
|
||||
| | | |
|
||||
/ | | \
|
||||
/ | | \
|
||||
/ |_____| \
|
||||
/ / \ \
|
||||
/ / \ \
|
||||
/ / \ \
|
||||
/_____/ \_____\
|
||||
Devour - Documentation Devourer
|
||||
`
|
||||
|
||||
// DevourCharacterSmall is a smaller version for compact displays
|
||||
const DevourCharacterSmall = `
|
||||
___
|
||||
.-' '-.
|
||||
/ O O \
|
||||
| _ |
|
||||
\ '-' /
|
||||
'-.___.-'
|
||||
Documentation Devourer
|
||||
`
|
||||
|
||||
// DevourLogo is a stylized text logo
|
||||
const DevourLogo = `
|
||||
____ _____ __________ _____ ____ _____
|
||||
| _ \| ____| ___| ___|_ _| _ \| ____|
|
||||
| | | | _| | |_ | |_ | | | | | | _|
|
||||
| |_| | |___| _| | _| | | | |_| | |___
|
||||
|____/|_____|_| |_| |_| |____/|_____|
|
||||
Documentation Devourer
|
||||
`
|
||||
|
||||
// DevourBanner combines the character with version info
|
||||
const DevourBanner = `
|
||||
___
|
||||
.-' '-.
|
||||
/ O O \
|
||||
| _ |
|
||||
\ '-' /
|
||||
'-.___.-'
|
||||
____ _____ __________ _____
|
||||
| _ \| ____| ___| ___|_ _|
|
||||
| | | | _| | |_ | |_ | |
|
||||
| |_| | |___| _| | _| | |
|
||||
|____/|_____|_| |_| |_|
|
||||
|
||||
Documentation Devourer v%s
|
||||
`
|
||||
|
||||
// PrintCharacter prints the full ASCII character
|
||||
func PrintCharacter() {
|
||||
fmt.Println(DevourCharacter)
|
||||
}
|
||||
|
||||
// PrintCharacterSmall prints the smaller character version
|
||||
func PrintCharacterSmall() {
|
||||
fmt.Println(DevourCharacterSmall)
|
||||
}
|
||||
|
||||
// PrintLogo prints just the text logo
|
||||
func PrintLogo() {
|
||||
fmt.Println(DevourLogo)
|
||||
}
|
||||
|
||||
// PrintBanner prints the character with version info
|
||||
func PrintBanner(version string) {
|
||||
fmt.Printf(DevourBanner, version)
|
||||
}
|
||||
|
||||
// GetCharacter returns the character string
|
||||
func GetCharacter() string {
|
||||
return DevourCharacter
|
||||
}
|
||||
|
||||
// GetCharacterSmall returns the small character string
|
||||
func GetCharacterSmall() string {
|
||||
return DevourCharacterSmall
|
||||
}
|
||||
|
||||
// GetLogo returns the logo string
|
||||
func GetLogo() string {
|
||||
return DevourLogo
|
||||
}
|
||||
|
||||
// GetBanner returns the formatted banner string
|
||||
func GetBanner(version string) string {
|
||||
return fmt.Sprintf(DevourBanner, version)
|
||||
}
|
||||
|
||||
// PrintWelcome prints a welcome message with the character
|
||||
func PrintWelcome(version string) {
|
||||
PrintBanner(version)
|
||||
fmt.Println()
|
||||
fmt.Println(" Context ingestion and management for AI")
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// PrintWithColor prints the character with ANSI color codes (cyan/teal theme)
|
||||
func PrintWithColor(useColor bool) {
|
||||
if useColor {
|
||||
// Cyan color for the character
|
||||
cyan := "\033[36m"
|
||||
reset := "\033[0m"
|
||||
fmt.Printf("%s%s%s", cyan, DevourCharacter, reset)
|
||||
} else {
|
||||
PrintCharacter()
|
||||
}
|
||||
}
|
||||
|
||||
// GetColoredCharacter returns the character with ANSI color codes
|
||||
func GetColoredCharacter(useColor bool) string {
|
||||
if useColor {
|
||||
cyan := "\033[36m"
|
||||
reset := "\033[0m"
|
||||
return cyan + DevourCharacter + reset
|
||||
}
|
||||
return DevourCharacter
|
||||
}
|
||||
|
||||
// PrintStatusWithCharacter prints status output with the small character
|
||||
func PrintStatusWithCharacter(statusLines []string) {
|
||||
// Print small character on the left
|
||||
lines := strings.Split(DevourCharacterSmall, "\n")
|
||||
maxWidth := 0
|
||||
for _, line := range lines {
|
||||
if len(line) > maxWidth {
|
||||
maxWidth = len(line)
|
||||
}
|
||||
}
|
||||
|
||||
// Pad character lines and add status
|
||||
charIdx := 0
|
||||
statusIdx := 0
|
||||
|
||||
for charIdx < len(lines) || statusIdx < len(statusLines) {
|
||||
if charIdx < len(lines) {
|
||||
line := lines[charIdx]
|
||||
// Pad to align status
|
||||
padding := maxWidth - len(line)
|
||||
if statusIdx < len(statusLines) {
|
||||
fmt.Printf("%s%s %s\n", line, strings.Repeat(" ", padding+2), statusLines[statusIdx])
|
||||
statusIdx++
|
||||
} else {
|
||||
fmt.Println(line)
|
||||
}
|
||||
charIdx++
|
||||
} else if statusIdx < len(statusLines) {
|
||||
fmt.Printf("%s %s\n", strings.Repeat(" ", maxWidth+2), statusLines[statusIdx])
|
||||
statusIdx++
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user