Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions docs/tui.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ uppercase belongs to Labels:
| `r` | reply |
| `f` | forward |
| `v` | move |
| `w` | bubble up now, schedule a return, or cancel a bubble-up |
| `b` | manage labels |
| `n` | add to or remove from a collection |
| `e` / `u` | mark seen / unseen — every selected thread when any are selected (Imbox only, as in HEY's web app), otherwise the one under the cursor |
Expand Down Expand Up @@ -82,6 +83,24 @@ Sending a reply or a forward from a thread closes the thread and returns you to

While reading a thread, the From header shows the actual send-as address when HEY records one separately from the account user.

Press `w` from the mail list or an open thread for the **Bubble up** menu. Use the
arrow keys and Enter to choose Now, Later today, Tomorrow, This weekend, Next week,
or Choose a date. Presets show the scheduled time in your local zone. HEY schedules
on its UTC calendar: morning is 08:00 UTC and Later today is 18:00 UTC. The menu
omits Later today once that time has passed. A custom date uses 08:00 UTC, or
18:00 UTC if you choose today's UTC date; past slots are refused. In the date field,
type YYYY-MM-DD or use Up/Down to change the day. Escape returns to the menu;
Escape again closes it without changing the thread.

For scheduled or already bubbled-up threads, the menu also offers Cancel bubble-up.
HEY returns a canceled thread to the Imbox, marked seen. A successful action closes
the open thread and refreshes its list. A failed action keeps the menu open for retry.
From search, the menu first checks whether the thread has a bubble-up to cancel.
Escape cancels the lookup; if it fails, Ctrl+R retries it.

Bubble up acts on one thread at a time; clear a bulk selection in the visible list
first, and open a bundle to choose an individual thread.

While reading a thread, links can be selected without a mouse. Tab selects the next link in document order and Shift+Tab selects the previous one; both wrap at the ends. A fixed row above the shortcut bar shows the selected destination without moving the thread. A destination too long for one row wraps onto as many rows as it needs, so you always see all of it. Press Enter to open it; opening stays unavailable until the terminal is tall enough to show the whole destination. Press Escape once to clear the selection, and Escape again to leave the thread. A thread with no selectable links keeps the normal global Tab focus behavior. Existing OSC 8 mouse links remain available.

Most of those keep working while you are reading a thread, the way the web app's topic
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/bubble_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type recordedBubble struct {

func bubbleServer(t *testing.T) (*httptest.Server, *recordedBubble) {
t.Helper()
recorded := &recordedBubble{status: http.StatusNoContent}
recorded := &recordedBubble{status: http.StatusOK}
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
recorded.requests++
recorded.method = r.Method
Expand Down
2 changes: 2 additions & 0 deletions internal/mail/posting.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Posting struct {
// from the posting's kind — HEY's `bundled` flag means filed *inside* a bundle.
IsBundle bool
BubbledUp bool
BubbleScheduled bool
Muted bool
VisibleEntryCount int32
Creator Contact
Expand Down Expand Up @@ -86,6 +87,7 @@ func NewPosting(posting generated.Posting) Posting {
Seen: posting.Seen,
IsBundle: posting.Kind == "bundle",
BubbledUp: posting.BubbledUp,
BubbleScheduled: !posting.BubbleUpSchedule.BubbleUpAt.IsZero() || posting.BubbleUpSchedule.SurpriseMe,
Muted: posting.Muted,
VisibleEntryCount: posting.VisibleEntryCount,
Creator: contactOf(posting.Creator),
Expand Down
14 changes: 14 additions & 0 deletions internal/mail/posting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,17 @@ func TestPostingsDescribesAPage(t *testing.T) {
t.Error("an empty page should describe as an empty slice, not nil")
}
}

func TestNewPostingKeepsBubbleSchedulePresence(t *testing.T) {
for _, schedule := range []generated.BubbleUpSchedule{
{BubbleUpAt: time.Date(2026, 12, 4, 8, 0, 0, 0, time.UTC)},
{SurpriseMe: true},
} {
if !NewPosting(generated.Posting{BubbleUpSchedule: schedule}).BubbleScheduled {
t.Fatal("lost scheduled bubble-up")
}
}
if NewPosting(generated.Posting{}).BubbleScheduled {
t.Fatal("empty schedule should not offer cancellation")
}
}
281 changes: 281 additions & 0 deletions internal/tui/bubble.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,281 @@
package tui

import (
"context"
"strings"
"time"

tea "charm.land/bubbletea/v2"
hey "github.com/basecamp/hey-sdk/go/pkg/hey"

"github.com/basecamp/hey-cli/internal/mail"
)

type bubbleAction int

const (
bubbleNow bubbleAction = iota
bubbleSchedule
bubbleChooseDate
bubbleCancel
)

type bubbleChoice struct {
action bubbleAction
name string
slot hey.BubbleUpSlot
at time.Time
}

type bubblePicker struct {
plainModal
postingID int64
choices []bubbleChoice
cursor int
date *dateTimePicker
busy bool
loading bool
unknownState bool
lookupCancel context.CancelFunc
problem string
now func() time.Time
openedDay string
}

type bubbleDoneMsg struct {
picker *bubblePicker
message string
err error
}

func newBubblePicker(posting mail.Posting, scheduled bool, now func() time.Time) *bubblePicker {
at := now().UTC()
morning := time.Date(at.Year(), at.Month(), at.Day(), 8, 0, 0, 0, time.UTC)
p := &bubblePicker{postingID: posting.ID, now: now, openedDay: at.Format("2006-01-02")}
p.choices = append(p.choices, bubbleChoice{name: "Now"})
if evening := morning.Add(10 * time.Hour); evening.After(at) {
p.choices = append(p.choices, bubbleChoice{name: "Later today", action: bubbleSchedule, slot: hey.BubbleUpLaterToday, at: evening})
}
p.choices = append(p.choices,
bubbleChoice{name: "Tomorrow", action: bubbleSchedule, slot: hey.BubbleUpTomorrow, at: morning.AddDate(0, 0, 1)},
bubbleChoice{name: "This weekend", action: bubbleSchedule, slot: hey.BubbleUpThisWeekend, at: morning.AddDate(0, 0, nextBubbleDay(at.Weekday(), time.Saturday))},
bubbleChoice{name: "Next week", action: bubbleSchedule, slot: hey.BubbleUpNextWeek, at: morning.AddDate(0, 0, nextBubbleDay(at.Weekday(), time.Monday))},
bubbleChoice{name: "Choose a date…", action: bubbleChooseDate},
)
if scheduled || posting.BubbledUp {
p.choices = append(p.choices, bubbleChoice{name: "Cancel bubble-up", action: bubbleCancel})
}
return p
}

func nextBubbleDay(from, to time.Weekday) int { return (int(to)-int(from)+6)%7 + 1 }

func (v *mailView) startBubblePicker() tea.Cmd {
if !v.inThread && !v.searchActive && !v.bundleActive && v.refuseForSelection() {
return nil
}
if v.requests.loading {
return nil
}
posting := v.actionPosting()
if !v.inThread && v.searchActive {
posting = v.searchList.selectedPosting()
}
if !v.inThread && v.bundleActive {
posting = v.bundleList.selectedPosting()
}
if posting == nil || posting.ID == 0 || posting.IsBundle {
v.notice = "Open an individual email thread to bubble it up"
return nil
}
scheduled := posting.BubbleScheduled
for _, box := range v.boxes {
if box.ID == posting.BoxID && box.Kind == mail.KindBox && box.BoxKind == hey.BoxKindBubbleUp {
scheduled = true
}
}
picker := newBubblePicker(*posting, scheduled, time.Now)
v.openModal(picker)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 21db033, with the root-model regression in 67ad6bb. Opening the picker changed the help/footer height, and the resulting resize revealed the selected link or changed the offset at the bottom. The fix preserves the reading position across those modal layout changes and restores it on dismissal.

The regression sends Tab, scrolling, w, and Escape through model.Update, covering a wrapping selected-link footer and an unselected thread, both partway down and at the bottom. Actual terminal resizing still lays out the thread at its new dimensions.

TUI/mail tests and lint pass. Offline PTY checks on the combined build also verified that Bubble Up restores the rendered screen after dismissal, including at the bottom.

if v.searchActive && posting.BoxID == 0 && !posting.BubbledUp && !posting.BubbleScheduled {
return v.loadBubbleState(picker)
}
return nil
}

func (p *bubblePicker) handleKey(v *mailView, msg tea.KeyPressMsg) (tea.Cmd, bool) {
if p.unknownState {
if msg.Key().Code == tea.KeyEscape {
if p.lookupCancel != nil {
p.lookupCancel()
}
return nil, false
}
if !p.loading && msg.String() == "ctrl+r" {
return v.loadBubbleState(p), true
}
return nil, true
}
if p.busy {
return nil, true
}
if p.date != nil {
switch msg.Key().Code {
case tea.KeyEscape:
p.date = nil
p.problem = ""
return nil, true
case tea.KeyEnter:
return p.submit(v, bubbleChoice{name: "Choose a date…", action: bubbleChooseDate}), true
}
return p.date.handleKey(msg), true
}
switch msg.Key().Code {
case tea.KeyEscape:
return nil, false
case tea.KeyEnter:
choice := p.choices[p.cursor]
if choice.action == bubbleChooseDate {
p.date = newDateTimePicker(p.now().UTC().AddDate(0, 0, 1), true)
return p.date.focusFirst(), true
}
return p.submit(v, choice), true
}
p.cursor = stepListCursor(p.cursor, len(p.choices), msg)
p.problem = ""
return nil, true
}

func (p *bubblePicker) submit(v *mailView, choice bubbleChoice) tea.Cmd {
sdk, ctx, id := v.vc.sdk, v.vc.ctx, p.postingID
now := p.now().UTC()
date := ""
if p.date != nil {
at, err := time.Parse("2006-01-02", p.date.date())
if err != nil || at.Format("2006-01-02") != p.date.date() {
p.problem = "Enter a date as YYYY-MM-DD"
return nil
}
choice.at = at.Add(8 * time.Hour)
if at.Format("2006-01-02") == now.Format("2006-01-02") {
choice.slot = hey.BubbleUpLaterToday
choice.at = at.Add(18 * time.Hour)
} else {
date = at.Format("2006-01-02")
}
} else if choice.slot != "" && now.Format("2006-01-02") != p.openedDay {
p.problem = "The date changed. Close and reopen Bubble up."
return nil
}
if !choice.at.IsZero() && !choice.at.After(now) {
p.problem = "Choose a future date; today's slot is 18:00 UTC"
return nil
}
p.busy = true
p.problem = ""
v.pendingMutations++
return func() tea.Msg {
var err error
message := "Thread will bubble up"
switch {
case choice.action == bubbleCancel:
err = sdk.Postings().CancelBubbleUp(ctx, id)
message = "Bubble-up canceled; thread returned to the Imbox, marked seen"
case choice.action == bubbleNow:
err = sdk.Postings().BubbleUpNow(ctx, id)
message = "Thread bubbled up"
case date != "":
err = sdk.Postings().ScheduleBubbleUp(ctx, date, id)
default:
err = sdk.Postings().ScheduleBubbleUpFor(ctx, choice.slot, id)
}
return bubbleDoneMsg{picker: p, message: message, err: err}
}
}

func (v *mailView) bubbleDone(msg bubbleDoneMsg) tea.Cmd {
v.finishMutation()
p := msg.picker
p.busy = false
if msg.err != nil {
p.problem = errorNotice("Could not change bubble-up", msg.err)
return nil
}
if v.modal == p {
v.modal = nil
}
if v.inThread && v.threadPosting.ID == p.postingID {
v.ExitThread()
}
v.notice = msg.message
// Re-read the source instead of guessing its membership and ordering after HEY
// schedules, pops, or immediately resurfaces a thread.
if v.seenActive {
requestID, ctx := v.requests.begin(v.vc.ctx, mailRequestSeen)
v.seenNextPage = ""
v.seenLoadingMore = false
v.seenMoreID++
return v.fetchSeenPostings(ctx, requestID)
}
if v.searchActive {
return v.requestSearch(v.searchQuery)
}
if v.bundleActive {
if v.bundleContactID != 0 {
return v.requestContactThreads(v.bundleContactID)
}
return v.requestBundle(v.bundlePostingID)
}
return v.reloadPostings()
}

func (p *bubblePicker) handleMsg(msg tea.Msg) (tea.Cmd, bool) {
if p.date == nil || p.busy {
return nil, false
}
var cmd tea.Cmd
p.date.dateInput, cmd = p.date.dateInput.Update(msg)
return cmd, true
}

func (p *bubblePicker) draw(v *mailView) string {
var body string
if p.loading {
body = "Loading Bubble Up…"
} else if p.unknownState {
body = "Press Ctrl+R to retry, or Esc to cancel."
} else if p.date != nil {
body = "Date (YYYY-MM-DD, on HEY's UTC calendar)\n" + p.date.view() + "\n\n08:00 UTC; today's date uses 18:00 UTC."
} else {
names := make([]string, len(p.choices))
for i, choice := range p.choices {
names[i] = choice.name
if !choice.at.IsZero() {
names[i] += " · " + choice.at.Local().Format("Mon Jan 2, 15:04 MST")
}
}
body = strings.Join(modalListRows(names, p.cursor, modalContentWidth(v.vc.width), max(modalContentRows(v.vc.height)-3, 1)), "\n")
}
if p.busy {
body += "\n\nSaving…"
}
if p.problem != "" {
body += "\n\n" + p.problem
}
return overlayModal(v.contentView(), modalFrame("Bubble up", body, v.vc.width), v.vc.width, v.vc.height)
}

func (p *bubblePicker) helpBindings() []helpBinding {
if p.loading {
return []helpBinding{{"esc", "cancel"}}
}
if p.unknownState {
return []helpBinding{{"ctrl+r", "retry"}, {"esc", "cancel"}}
}
if p.busy {
return []helpBinding{{"", "saving bubble-up…"}}
}
if p.date != nil {
return []helpBinding{{"↑/↓", "change day"}, {"enter", "schedule"}, {"esc", "back"}}
}
return []helpBinding{{"↑/↓", "choose"}, {"enter", "apply"}, {"esc", "cancel"}}
}
Loading