Skip to content

Commit

Permalink
fix: printing copilot analysis on terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
1x-eng committed Nov 4, 2024
1 parent 48eb63d commit a878bfb
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 19 deletions.
26 changes: 19 additions & 7 deletions pkg/pomodoro/pom.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,17 +185,29 @@ func (p *TomatickMemento) runTomatickMementoCycle() {
if err != nil {
fmt.Println(p.auroraInstance.Red("Error getting AI analysis:"), err)
} else {
if analysis == "" {
fmt.Println(p.auroraInstance.Yellow("Warning: Received empty analysis"))
}

presenter := ui.NewAnalysisPresenter(p.theme)
formattedAnalysis := presenter.Present(analysis)
fmt.Println(formattedAnalysis)

// Prompt user to acknowledge
prompt := &survey.Confirm{
Message: p.theme.Styles.InfoText.Render("Ready for your break?"),
Default: true,
// Keep prompting until user is ready
for {
prompt := &survey.Confirm{
Message: p.theme.Styles.Break.Render("Ready for your break?"),
Default: true,
}
var ready bool
survey.AskOne(prompt, &ready)

if ready {
break
} else {
fmt.Println(p.theme.Styles.Break.Render("\nTake your time to review the analysis. Press Y when ready to continue."))
}
}
var ready bool
survey.AskOne(prompt, &ready)

p.lastAnalysis = analysis
}
Expand Down Expand Up @@ -568,7 +580,7 @@ func (p *TomatickMemento) printTotalHoursWorked() {

func displayWelcomeMessage(au aurora.Aurora) {
asciiArt := `
████████╗ ██████╗ ███╗ ██╗ █████╗ ████████╗██╗ ██████╗██╗ ██╗
████████╗ ██████╗ ███╗ ██╗ █████╗ ████████╗██╗ ██████╗██╗ ██╗
╚══██╔══╝██╔═══██╗████╗ ████║██╔══██╗╚══██╔══╝██║██╔════╝██║ ██╔╝
██║ ██║ ██║██╔████╔██║███████║ ██║ ██║██║ █████╔╝
██║ ██║ ██║██║╚██╔╝██║██╔══██║ ██║ ██║██║ ██╔═██╗
Expand Down
50 changes: 38 additions & 12 deletions pkg/ui/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,31 @@ func (ap *AnalysisPresenter) parseAnalysis(analysis string) map[string][]string
for _, line := range lines {
line = strings.TrimSpace(line)

if strings.HasPrefix(line, "##") {
// Match both ## and **Section** headers
if strings.HasPrefix(line, "##") || (strings.HasPrefix(line, "**") && strings.HasSuffix(line, "**")) {
if currentSection != "" {
sections[currentSection] = currentContent
}
currentSection = strings.TrimSpace(strings.TrimPrefix(line, "##"))
// Clean up section header
currentSection = strings.TrimSpace(strings.Trim(strings.TrimPrefix(strings.TrimPrefix(line, "##"), "**"), "**"))
currentContent = []string{}
} else if line != "" {
// Normalize bullet points and numbering
} else if strings.HasPrefix(line, "-") || strings.HasPrefix(line, "*") || strings.HasPrefix(line, "•") {
// Normalize bullet points and add to current content
line = ap.normalizeListItem(line)
if line != "" {
currentContent = append(currentContent, line)
}
} else if line != "" && currentSection != "" {
// Add non-empty lines that aren't headers or bullets
currentContent = append(currentContent, line)
}
}

// Don't forget the last section
if currentSection != "" {
sections[currentSection] = currentContent
}

return sections
}

Expand All @@ -64,27 +74,43 @@ func (ap *AnalysisPresenter) normalizeListItem(line string) string {
func (ap *AnalysisPresenter) formatSections(sections map[string][]string) string {
var sb strings.Builder

// Initial title with single newline
sb.WriteString(ap.theme.Styles.Subtitle.Render("🤖 Your copilot's analysis"))
// Initial title with double newline and border
sb.WriteString("\n" + ap.theme.Styles.Subtitle.Render("🤖 Your copilot's analysis"))
sb.WriteString("\n\n" + ap.theme.Styles.Subtitle.Render(strings.Repeat("─", 50)) + "\n")

// If sections is empty, add a message
if len(sections) == 0 {
sb.WriteString("\n" + ap.theme.Styles.InfoText.Render("Analysis processing..."))
return sb.String()
}

for section, content := range sections {
// Add section header with consistent spacing
sb.WriteString(fmt.Sprintf("\n\n%s %s",
sb.WriteString(fmt.Sprintf("\n%s %s\n",
ap.theme.Emoji.Section,
ap.theme.Styles.TaskNumber.Render(section)))

// Process content items
for _, line := range content {
line = strings.TrimSpace(line)
if line == "" {
continue
}

// Remove any markdown formatting
line = strings.ReplaceAll(line, "**", "")
line = strings.ReplaceAll(line, "*", "")
line = strings.ReplaceAll(line, "[", "")
line = strings.ReplaceAll(line, "]", "")

if line != "" {
sb.WriteString(fmt.Sprintf("\n%s %s",
ap.theme.Emoji.Bullet,
ap.theme.Styles.InfoText.Render(line)))
}
sb.WriteString(fmt.Sprintf("%s %s\n",
ap.theme.Emoji.Bullet,
ap.theme.Styles.InfoText.Render(line)))
}
}

// Add bottom border
sb.WriteString("\n" + ap.theme.Styles.Subtitle.Render(strings.Repeat("─", 50)))

return sb.String()
}
5 changes: 5 additions & 0 deletions pkg/ui/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ThemeStyles struct {
Progress lipgloss.Style
Spinner lipgloss.Style
AIMessage lipgloss.Style
Break lipgloss.Style
}

type ThemeEmoji struct {
Expand Down Expand Up @@ -106,6 +107,10 @@ func NewTheme() *Theme {
AIMessage: lipgloss.NewStyle().
Foreground(lipgloss.Color("#B8E7E1")).
Italic(true),

Break: lipgloss.NewStyle().
Foreground(lipgloss.Color("#86EFAC")).
Bold(true),
},
Emoji: ThemeEmoji{
TaskComplete: "✅",
Expand Down

0 comments on commit a878bfb

Please sign in to comment.