-
Notifications
You must be signed in to change notification settings - Fork 272
feat(tui): add clipboard copy via OSC 52 on observation screens #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,8 @@ | ||
| package tui | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/Gentleman-Programming/engram/internal/setup" | ||
| "github.com/charmbracelet/bubbles/spinner" | ||
| tea "github.com/charmbracelet/bubbletea" | ||
|
|
@@ -125,6 +127,20 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { | |
| return m, cmd | ||
| } | ||
| return m, nil | ||
|
|
||
| case clipboardCopiedMsg: | ||
| if msg.err != nil { | ||
| m.CopyFeedback = "✗ Copy failed" | ||
| } else { | ||
| m.CopyFeedback = "✓ Copied!" | ||
| } | ||
| return m, tea.Tick(2*time.Second, func(time.Time) tea.Msg { | ||
| return copyFeedbackClearMsg{} | ||
| }) | ||
|
|
||
| case copyFeedbackClearMsg: | ||
| m.CopyFeedback = "" | ||
| return m, nil | ||
| } | ||
|
|
||
| return m, nil | ||
|
|
@@ -307,6 +323,11 @@ func (m Model) handleSearchResultsKeys(key string) (tea.Model, tea.Cmd) { | |
| m.PrevScreen = ScreenSearchResults | ||
| return m, loadTimeline(m.store, obsID) | ||
| } | ||
| case "c": | ||
| if len(m.SearchResults) > 0 && m.Cursor < len(m.SearchResults) { | ||
| r := m.SearchResults[m.Cursor] | ||
| return m, copyToClipboard(r.Content) | ||
| } | ||
|
Comment on lines
323
to
+330
|
||
| case "/", "s": | ||
| m.PrevScreen = ScreenSearchResults | ||
| m.Screen = ScreenSearch | ||
|
|
@@ -358,6 +379,11 @@ func (m Model) handleRecentKeys(key string) (tea.Model, tea.Cmd) { | |
| m.PrevScreen = ScreenRecent | ||
| return m, loadTimeline(m.store, obsID) | ||
| } | ||
| case "c": | ||
| if len(m.RecentObservations) > 0 && m.Cursor < len(m.RecentObservations) { | ||
| obs := m.RecentObservations[m.Cursor] | ||
| return m, copyToClipboard(obs.Content) | ||
| } | ||
| case "esc", "q": | ||
| m.Screen = ScreenDashboard | ||
| m.Cursor = 0 | ||
|
|
@@ -382,6 +408,10 @@ func (m Model) handleObservationDetailKeys(key string) (tea.Model, tea.Cmd) { | |
| if m.SelectedObservation != nil { | ||
| return m, loadTimeline(m.store, m.SelectedObservation.ID) | ||
| } | ||
| case "c": | ||
| if m.SelectedObservation != nil { | ||
| return m, copyToClipboard(m.SelectedObservation.Content) | ||
| } | ||
| case "esc", "q": | ||
| m.Screen = m.PrevScreen | ||
| m.Cursor = 0 | ||
|
|
@@ -484,6 +514,11 @@ func (m Model) handleSessionDetailKeys(key string) (tea.Model, tea.Cmd) { | |
| m.PrevScreen = ScreenSessionDetail | ||
| return m, loadTimeline(m.store, obsID) | ||
| } | ||
| case "c": | ||
| if len(m.SessionObservations) > 0 && m.Cursor < len(m.SessionObservations) { | ||
| obs := m.SessionObservations[m.Cursor] | ||
| return m, copyToClipboard(obs.Content) | ||
| } | ||
| case "esc", "q": | ||
| m.Screen = ScreenSessions | ||
| m.Cursor = m.SelectedSessionIdx | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -88,6 +88,15 @@ func (m Model) View() string { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content += "\n" + errorStyle.Render("Error: "+m.ErrorMsg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Show copy feedback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if m.CopyFeedback != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fbStyle := lipgloss.NewStyle().Bold(true).Foreground(colorGreen) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if strings.HasPrefix(m.CopyFeedback, "✗") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fbStyle = lipgloss.NewStyle().Bold(true).Foreground(colorRed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| content += "\n" + fbStyle.Render(m.CopyFeedback) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return appStyle.Render(content) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+93
to
102
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fbStyle := lipgloss.NewStyle().Bold(true).Foreground(colorGreen) | |
| if strings.HasPrefix(m.CopyFeedback, "✗") { | |
| fbStyle = lipgloss.NewStyle().Bold(true).Foreground(colorRed) | |
| } | |
| content += "\n" + fbStyle.Render(m.CopyFeedback) | |
| } | |
| return appStyle.Render(content) | |
| } | |
| fbStyle := m.copyFeedbackStyle() | |
| content += "\n" + fbStyle.Render(m.CopyFeedback) | |
| } | |
| return appStyle.Render(content) | |
| } | |
| // copyFeedbackStyle determines the style for the current copy feedback message. | |
| // NOTE: This currently infers error vs. success from the message content, but | |
| // the logic is centralized here so it can later be switched to a dedicated | |
| // structured state (e.g., a bool/enum on the model) without touching View. | |
| func (m Model) copyFeedbackStyle() lipgloss.Style { | |
| // Default to success style. | |
| style := lipgloss.NewStyle().Bold(true).Foreground(colorGreen) | |
| // If the feedback indicates a failure, use the error style. | |
| if strings.HasPrefix(m.CopyFeedback, "✗") { | |
| style = lipgloss.NewStyle().Bold(true).Foreground(colorRed) | |
| } | |
| return style | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyToClipboard()writes OSC 52 sequences directly toos.Stderrfrom within a Bubbletea command. This bypasses Bubbletea’s configured output writer (the program uses stdout by default) and introduces hard-to-test, side-effecting I/O from a goroutine, which can also interleave with the renderer’s output. Consider emitting the OSC 52 sequence through the same output stream as the TUI (or making the writer injectable) so clipboard writes are routed consistently and can be tested deterministically.