package tui import ( "strings" tea "charm.land/bubbletea/v2" "github.com/charmbracelet/x/ansi" ) // ChatAttachMsg asks to open the chat's moved session on the daemon it moved // to, carrying what was typed so it can be sent there. type ChatAttachMsg struct { SessionID string Draft string } // ChatChecklistMsg asks to reopen the checklist of the chat's move waiting // to be finished. type ChatChecklistMsg struct{ SessionID string } // answerMoved takes enter on a moved session: this daemon refuses its input, // so enter opens it where it went instead, and a draft goes along. A slash // command still runs here. func (m *ChatModel) answerMoved(msg tea.KeyPressMsg) (tea.Cmd, bool) { switch { case msg.String() != "enter" || strings.HasPrefix(m.TextArea.Value(), "/"): return nil, false case m.movedNote != "" && !m.movedFailed: return nil, true // already opening it } id, draft := m.SessionID, m.TextArea.Value() return func() tea.Msg { return ChatAttachMsg{SessionID: id, Draft: draft} }, true } // attaching shows an attach under way, or the one that failed, in the banner. func (m *ChatModel) attaching(note string, failed bool) { m.movedNote, m.movedFailed = note, failed m.syncLayout() } // movedRows is the banner above a moved session's composer: where it went, // the key that opens it there, and the last attach's failure. A session // whose move waits in its checklist says so, and enter reopens it. func (m ChatModel) movedRows(width int) []string { var where, keys string switch { case m.moved != nil: where = "moved to " + m.moved.Host if m.moved.Workspace != "" { where += " · " + m.moved.Workspace } keys = keyHints(hint{"enter", "open it there"}) if m.movedNote != "" && !m.movedFailed { keys = DefaultStyles.Faint.Render(m.movedNote) } case m.movePending != nil: where = "moving to " + m.movePending.Host + " · checklist pending" keys = keyHints(hint{"enter", "open the checklist"}) default: return nil } var rows []string if ansi.StringWidth(where)+3+ansi.StringWidth(keys) <= width { rows = []string{DefaultStyles.Muted.Render(where) + " " + keys} } else { rows = []string{DefaultStyles.Muted.Render(ansi.Truncate(where, width, "…")), ansi.Truncate(keys, width, "…")} } if m.movedFailed { for line := range strings.SplitSeq(ansi.Wrap(m.movedNote, width, " "), "\n") { rows = append(rows, DefaultStyles.Error.Render(line)) } } return rows }