summaryrefslogtreecommitdiffstats
path: root/internal/formatter/username.go
diff options
context:
space:
mode:
authors <[email protected]>2025-11-13 14:43:15 -0500
committers <[email protected]>2025-11-13 14:43:15 -0500
commit344a6f6415c3c1b593677adec3b8844e0839971b (patch)
treeb05291ecdf21917b27e9e234eeb997c2706966d5 /internal/formatter/username.go
parenta5fc01a03753c9a18ddeaf13610dd99b4b311b80 (diff)
downloaddborg-344a6f6415c3c1b593677adec3b8844e0839971b.tar.gz
dborg-344a6f6415c3c1b593677adec3b8844e0839971b.zip
created pretty printing for all commandsv1.0.0
Diffstat (limited to 'internal/formatter/username.go')
-rw-r--r--internal/formatter/username.go143
1 files changed, 143 insertions, 0 deletions
diff --git a/internal/formatter/username.go b/internal/formatter/username.go
new file mode 100644
index 0000000..fc25487
--- /dev/null
+++ b/internal/formatter/username.go
@@ -0,0 +1,143 @@
+package formatter
+
+import (
+ "fmt"
+ "strings"
+
+ "git.db.org.ai/dborg/internal/models"
+ "git.db.org.ai/dborg/internal/utils"
+)
+
+func FormatUsernameSiteResult(result *models.SiteResult) error {
+ if result.Status == "found" {
+ fmt.Printf("%s | %s",
+ Green("✓ FOUND"),
+ result.SiteName)
+
+ if result.URL != "" {
+ fmt.Printf(" | %s", Blue(result.URL))
+ }
+
+ fmt.Println()
+
+ if len(result.Metadata) > 0 {
+ fmt.Print(formatMetadata(result.Metadata))
+ }
+ }
+ return nil
+}
+
+func FormatUsernameResults(response *models.USRSXResponse, asJSON bool) error {
+ if asJSON {
+ return utils.PrintJSON(response)
+ }
+
+ if response.Error != "" {
+ return fmt.Errorf("%s", response.Error)
+ }
+
+ if response.Message != "" {
+ return nil
+ }
+
+ if len(response.Results) == 0 {
+ return nil
+ }
+
+ for _, result := range response.Results {
+ if result.Status == "found" {
+ fmt.Printf("%s | %s",
+ Green("✓ FOUND"),
+ result.SiteName)
+
+ if result.URL != "" {
+ fmt.Printf(" | %s", Blue(result.URL))
+ }
+
+ fmt.Println()
+
+ if len(result.Metadata) > 0 {
+ fmt.Print(formatMetadata(result.Metadata))
+ }
+ }
+ }
+
+ return nil
+}
+
+func formatMetadata(metadata map[string]interface{}) string {
+ var lines []string
+ boxStyle := Dim(" ├─ ")
+ labelStyle := Dim
+
+ if displayName, ok := metadata["display_name"].(string); ok && displayName != "" {
+ lines = append(lines, boxStyle+labelStyle("Name: ")+displayName)
+ }
+
+ if bio, ok := metadata["bio"].(string); ok && bio != "" {
+ bioPreview := bio
+ if len(bioPreview) > 100 {
+ bioPreview = bioPreview[:97] + "..."
+ }
+ lines = append(lines, boxStyle+labelStyle("Bio: ")+bioPreview)
+ }
+
+ if avatar, ok := metadata["avatar_url"].(string); ok && avatar != "" {
+ lines = append(lines, boxStyle+labelStyle("Avatar: ")+avatar)
+ }
+
+ if location, ok := metadata["location"].(string); ok && location != "" {
+ lines = append(lines, boxStyle+labelStyle("Location: ")+location)
+ }
+
+ if website, ok := metadata["website"].(string); ok && website != "" {
+ lines = append(lines, boxStyle+labelStyle("Website: ")+website)
+ }
+
+ if joinDate, ok := metadata["join_date"].(string); ok && joinDate != "" {
+ lines = append(lines, boxStyle+labelStyle("Joined: ")+joinDate)
+ }
+
+ if followers, ok := metadata["follower_count"].(float64); ok && followers > 0 {
+ lines = append(lines, boxStyle+labelStyle("Followers: ")+fmt.Sprintf("%d", int(followers)))
+ }
+
+ if following, ok := metadata["following_count"].(float64); ok && following > 0 {
+ lines = append(lines, boxStyle+labelStyle("Following: ")+fmt.Sprintf("%d", int(following)))
+ }
+
+ if verified, ok := metadata["is_verified"].(bool); ok && verified {
+ lines = append(lines, boxStyle+labelStyle("Verified: ")+Green("✓ Yes"))
+ }
+
+ if additionalLinks, ok := metadata["additional_links"].(map[string]interface{}); ok && len(additionalLinks) > 0 {
+ linkCount := 0
+ linkLines := []string{}
+ for key, value := range additionalLinks {
+ if strVal, ok := value.(string); ok {
+ linkLines = append(linkLines, Dim(" ├─ ")+labelStyle(key+": ")+strVal)
+ linkCount++
+ }
+ }
+ if linkCount > 0 {
+ lastBoxStyle := Dim(" └─ ")
+ lines = append(lines, lastBoxStyle+labelStyle("Links:"))
+ for i, linkLine := range linkLines {
+ if i == linkCount-1 {
+ linkLine = strings.Replace(linkLine, "├─", "└─", 1)
+ }
+ lines = append(lines, linkLine)
+ }
+ }
+ } else {
+ if len(lines) > 0 {
+ lastIdx := len(lines) - 1
+ lines[lastIdx] = strings.Replace(lines[lastIdx], "├─", "└─", 1)
+ }
+ }
+
+ if len(lines) > 0 {
+ return strings.Join(lines, "\n") + "\n"
+ }
+ return ""
+}