Documentation
¶
Index ¶
- type AppMode
- type AttachRequestedMsg
- type AttachmentDiscardedMsg
- type EditingMode
- type MentionQueryMsg
- type MentionResultsMsg
- type MentionSpan
- type MessageSubmittedMsg
- type Mode
- type Model
- func (m Model) Attachment() string
- func (m Model) ChatId() int64
- func (m Model) Draft() string
- func (m Model) DraftChats() map[int64]bool
- func (m Model) EditingMode() EditingMode
- func (m *Model) EnterEditMode(messageID int64, currentText string, mentions ...MentionSpan) string
- func (m *Model) EnterReplyMode(messageID int64, previewText string)
- func (m Model) Expanded() bool
- func (m Model) HasDraft() bool
- func (m Model) HasDraftFor(chatID int64) bool
- func (m *Model) InsertMention(anchor, end int, label string, userID int64)
- func (m Model) IsComposing() bool
- func (m Model) IsEditing() bool
- func (m Model) IsViNormalMode() bool
- func (m Model) MentionActive() bool
- func (m Model) MentionPicker(width, maxRows int) (lines []string, ok bool)
- func (m *Model) Reset()
- func (m Model) Rows() int
- func (m *Model) SetAttachment(path string, asPhoto bool) string
- func (m *Model) SetChatId(chatID int64) string
- func (m *Model) SetEditingMode(mode EditingMode)
- func (m *Model) SetExpanded(on bool)
- func (m *Model) SetFocused(focused bool)
- func (m *Model) SetMentionCandidates(chatID int64, users []*telegram.User)
- func (m *Model) SetMentionsEnabled(on bool)
- func (m *Model) SetMode(mode AppMode)
- func (m *Model) SetNotice(notice string)
- func (m *Model) SetParseMarkdown(on bool)
- func (m *Model) SetRoles(r theme.Roles)
- func (m *Model) SetSize(width, height int)
- func (m *Model) SetUploadProgress(path string, generation uint64, uploaded, total int64, failed bool)
- func (m Model) Update(msg tea.Msg) (Model, tea.Cmd)
- func (m Model) View() string
- type PasteRequestedMsg
- type ResizedMsg
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AppMode ¶
type AppMode int
AppMode is the interaction mode the badge reports.
It is a copy of the app's InteractionMode rather than a shared type because the app imports this package and not the other way round. The mapping is one switch in internal/app with a test that walks every value, which is a cheaper coupling than a third package existing to hold four constants.
The badge REPORTS the mode; it never decides one. Decision 3: a badge that altered key routing would be a second source of truth for something Model.Mode() already derives.
const ( // AppNormal: printable keys navigate. A browsing panel, or an overlay // that navigates rather than collects text. AppNormal AppMode = iota // AppInsert: printable keys type. AppInsert // AppVi: this composer is in vi editing and has returned to its // command state, so the next letter runs a vi command on the draft // (decision I-12). It shared NORMAL with the browsing panels for a // release while sharing none of their keys. AppVi // AppCommand: the palette owns the keyboard. AppCommand )
func (AppMode) PromptGlyph ¶ added in v0.0.32
PromptGlyph is the shape drawn in the prompt cell for this mode.
A shape per mode, because colour was the only channel this badge had and the four are neighbours in one low-saturation palette: NORMAL and INSERT read as the same state at a glance. The shape is what survives a monochrome terminal, a screenshot and a reader who cannot separate those hues, and TestEveryModeDrawsItsOwnGlyph pins that no two ever collide.
Every one of these must measure exactly one cell under cell.Width, or the gutter arithmetic in promptRow is wrong and the whole row shears. U+25AA is East-Asian-Ambiguous and U+276F is a Dingbats ornament, so neither is obviously safe; TestEveryModeGlyphIsExactlyOneCell measures them rather than trusting the block they came from.
Exported because the host's own tests locate the prompt column by it, and a locator that hunts for a hardcoded glyph stops finding the column the moment this changes — silently, since a missing glyph reads as column -1.
type AttachRequestedMsg ¶
type AttachRequestedMsg struct{}
AttachRequestedMsg is emitted when the user asks to attach a file (Ctrl+T).
type AttachmentDiscardedMsg ¶
type AttachmentDiscardedMsg struct {
Path string
}
AttachmentDiscardedMsg is emitted when a pending attachment is dropped without being sent (Escape), so the owner can delete the spooled file.
type EditingMode ¶
type EditingMode int
EditingMode selects which line-editing keymap the composer speaks. The default is ModeEmacs, so a Model that is never configured behaves exactly as it did before vi mode existed.
Only the composer is modal. Every other widgets.TextArea user (the search overlay, chatview's find bar, the auth prompts) keeps emacs semantics unconditionally — a one-line search field has nothing to gain from a normal mode, and Escape there already means "close the overlay".
const ( // ModeEmacs is the readline keymap: ctrl+a/e move to the ends of the // line, ctrl+b/f a character, ctrl+k/u kill to either end, ctrl+w kills // the previous word, ctrl+d deletes forward. ModeEmacs EditingMode = iota // ModeVi is the modal keymap: Escape leaves insert mode for a normal // mode with h/j/k/l, w/b, 0/$, x, dd, D and i/a/A/o/O. ModeVi )
func EditingModeFor ¶
func EditingModeFor(name string) EditingMode
EditingModeFor maps a configured keymap name onto an EditingMode. It is the bridge from config.ResolveComposeEditing (which returns "emacs" or "vi") and, being total, treats anything it does not recognise as emacs rather than leaving the composer in a mode the user did not ask for.
func (EditingMode) String ¶
func (e EditingMode) String() string
type MentionQueryMsg ¶ added in v0.0.28
MentionQueryMsg asks the host for the members an @ could mean (issue #41).
The composer emits one when completion opens — with an empty Query, which a supergroup answers with its recent members — and again every time the query changes. Anchor is the rune offset of the @ in the draft, and Gen is this query's generation: no two queries share one, for the life of the composer.
The answer is a MentionResultsMsg carrying all four back. A host that debounces may skip a query outright, since a newer one supersedes it.
type MentionResultsMsg ¶ added in v0.0.28
type MentionResultsMsg struct {
ChatID int64
Anchor int
Query string
Gen uint64
Users []*telegram.User
Err error
}
MentionResultsMsg answers a MentionQueryMsg: the members the search found, or why it failed (issue #41). ChatID, Anchor, Query and Gen are the query's, copied back.
The composer applies it only while all four still describe the completion on screen, and drops it silently otherwise — so an answer that arrives late can neither overwrite a newer query's nor reopen a picker that has closed. An Err keeps whatever the picker already had to offer, and says the search failed.
type MentionSpan ¶ added in v0.0.28
type MentionSpan struct {
Start, End int
UserID int64
// Label is the text the span covers. It is what the span is checked
// against after every edit, and a span that no longer covers it goes.
Label string
}
MentionSpan marks the runes of the draft that mention a user: the label the picker inserted, and who it means.
Start and End are RUNE offsets into the composer's text, End exclusive, the same unit the textarea's cursor uses. UTF-16 is the wire's business and is converted there.
The span is recorded when the mention is inserted and carried with the draft from then on (issue #41). It is never rediscovered from the visible text: two members can share a display name, and a name typed by hand is not a mention of anybody.
func MentionsIn ¶ added in v0.0.28
func MentionsIn(ft *telegram.FormattedText) []MentionSpan
MentionsIn returns the mentions by ID in a message's text, as spans of it, for EnterEditMode.
Only TextEntityTypeMentionName counts. A plain @username mention is its own text and needs no span, and nothing else names a user. An entity that does not fit inside the text is skipped rather than clamped: a shortened span would cover part of a name, and that is not a mention of anybody.
type MessageSubmittedMsg ¶
type MessageSubmittedMsg struct {
ChatId int64
Text string
ReplyToId int64
EditMessageId int64
Attachment string // local file path, empty if none
AsPhoto bool // send the attachment as an inline photo, not a document
// Mentions are the users mentioned by ID in Text, as rune ranges of it,
// sorted by Start (issue #41). Only the mentions a username cannot carry
// are here; "@username" typed out is already a mention on its own.
// Converting to UTF-16 and merging with the Markdown entities is the
// send path's business.
Mentions []MentionSpan
}
MessageSubmittedMsg is emitted when the user submits a message.
type Model ¶
type Model struct {
// contains filtered or unexported fields
}
Model is the message composer component.
func (Model) Attachment ¶
Attachment returns the pending attachment path, empty when there is none.
func (Model) Draft ¶
Draft is the text currently in the composer, for a host that needs to see what was typed rather than only whether anything was.
func (Model) DraftChats ¶
DraftChats is the set of chats holding parked drafts, for the chat list.
func (Model) EditingMode ¶
func (m Model) EditingMode() EditingMode
EditingMode reports the composer's current line-editing keymap.
func (*Model) EnterEditMode ¶
func (m *Model) EnterEditMode(messageID int64, currentText string, mentions ...MentionSpan) string
EnterEditMode starts editing a message. An edit cannot carry media, so any pending attachment is discarded and its path returned for the caller to delete.
The draft on screen is PARKED first (decision I-3): loading the message text over it used to destroy whatever was half-written, without a confirm and without a way back. Cancelling the edit or sending it puts the draft back — see unparkEdit.
mentions are the message's own mentions by ID, as spans of currentText — MentionsIn reads them off the message. They are checked against the text like any other span, and without them an edit would send the names back as plain words.
func (*Model) EnterReplyMode ¶
EnterReplyMode starts replying to a message.
func (Model) HasDraft ¶
HasDraft reports whether the composer holds unsent text.
It exists for app.go's quit-confirm rule: "q" from a browsing panel quits outright, unless there is work in the composer to lose, in which case it asks first. Whitespace alone is not work, so it is trimmed.
Not replaceable by IsComposing: that answers a different question (does Escape belong to the composer) and is true for reply/edit mode and, in vi mode, for insert mode — regardless of whether anything has been typed.
func (Model) HasDraftFor ¶
HasDraftFor reports whether a chat has unsent work parked. The chat list shows it in the preview row.
The open chat never has one: restoreDraft consumed its entry on the way in, because its draft is on screen in the composer rather than parked. Saying "draft: saved locally" about the thing you are looking at would tell the reader nothing and cost them the message preview.
func (*Model) InsertMention ¶ added in v0.0.28
InsertMention completes a mention: it replaces the runes [anchor, end) — the "@query" being typed — with label and a space, and leaves the cursor after the space, ready for the rest of the message.
userID says who label means. A member with a username is mentioned by typing it, so for them the label is "@username", userID is 0, and only the text goes in. A member without one can only be mentioned by an entity carrying their ID, so the label — their name — gets a span. The span covers the label and not the space: the space is the composer's, not theirs, and deleting it must not cost the mention.
Mentions already in the draft stay in step with the replacement: those before the token stay, those after it move along, and one inside it is replaced with it.
func (Model) IsComposing ¶
IsComposing reports whether Escape belongs to the composer rather than to app.go's focus-back handler: reply/edit mode or a pending attachment needs clearing first, in vi mode an Escape pressed in insert mode has to reach the composer so it can switch to normal mode, and an open mention picker has to be closed.
func (Model) IsEditing ¶
IsEditing reports whether the composer is editing an existing message. Attachments cannot be added to an edit.
func (Model) IsViNormalMode ¶
IsViNormalMode reports whether vi mode is active and currently in normal mode. Exposed for the status/hint rendering and for tests.
func (Model) MentionActive ¶ added in v0.0.28
MentionActive reports whether the picker is open. While it is, the composer owns Up, Down, Enter, Tab and Esc — so a host that takes any of those before the composer sees them has to let them through.
func (Model) MentionPicker ¶ added in v0.0.28
MentionPicker renders the open picker as rows of exactly width cells, no more than maxRows of them, ready to paint above the composer. ok is false when there is nothing to paint.
The matches come best first, five at most, scrolled so the selected one is always on screen. On a short terminal the host passes a smaller maxRows, and the picker draws fewer rows rather than spill onto the composer.
A one-line status follows them when there is something to say and a row to say it in; see mentionStatus. It never takes a row a match could have.
func (Model) Rows ¶
Rows is how many terminal rows the composer needs.
The host asks before computing the layout, so the thread gives up exactly the rows the composer is about to use — a composer that rendered more rows than it asked for would push the bottom of the history off screen, and one that rendered fewer would leave a hole. Rows is how many rows the composer WANTS: one to type into, and one each for the context above it.
What it wants, not what it was given — the layout budgets from this, and a Rows that reported its own budget back would be a loop that settles on one row and never grows. What it actually DRAWS is bounded separately; see View.
func (*Model) SetAttachment ¶
SetAttachment sets the pending attachment path shown above the composer. asPhoto requests that an image be sent inline rather than as a document. It returns the attachment it replaced (empty when there was none) so the caller can clean up a spool file that is no longer referenced.
func (*Model) SetChatId ¶
SetChatId switches the composer to another chat, parking the current chat's draft and restoring that chat's own (decision 13).
It used to discard: the draft and any staged attachment went in the bin and the path came back for cleanup. That made the chat list unusable while half-way through a message — checking who else had written cost you what you had typed — so switching now costs nothing. Drafts live for the session only and are never synced to Telegram, so nothing here can surprise another client.
The return value is the attachment path the caller should delete. It is now always empty, since nothing is displaced; the signature is unchanged so callers keep cleaning up after the paths that ARE dropped, by Escape and by entering edit mode.
func (*Model) SetEditingMode ¶
func (m *Model) SetEditingMode(mode EditingMode)
SetEditingMode selects the composer's line-editing keymap. Switching to vi starts in insert mode, which is what a chat composer wants: typing a message is the common case and a normal-mode landing would swallow the first word.
func (*Model) SetExpanded ¶
SetExpanded switches between the inline row and the eight-row form.
func (*Model) SetFocused ¶
SetFocused sets focus state. SetFocused moves the keyboard into or out of the composer.
Arriving in the composer puts vi mode back into INSERT. The reason is the one SetEditingMode already gives for starting there: typing a message is the common case, and a normal-mode landing swallows the first word — but the state was only initialised once, so the composer remembered whatever mode it was left in.
A vi user leaves the composer with two escapes: the first goes to normal mode, the second gives the panel back. So the composer was ALWAYS in normal mode by the time it was next entered, and r, e and i each landed there. Pressing r and typing "abc" produced "bc" — the "a" was vi's append. ctrl+j did not insert a newline for the same reason, deliberately (see isNewlineChord); ctrl+o worked because it is handled before the modal dispatch, which is why the external editor looked like the only way in.
Only on the transition, so a setFocus while already focused cannot pull a vi user out of normal mode mid-command.
func (*Model) SetMentionCandidates ¶ added in v0.0.28
SetMentionCandidates supplies the members of chatID the host already knows — recent senders, a basic group's member list — most recent first. The picker offers them the moment an @ is typed, ahead of the member search's answer, and goes on offering them if the search fails.
They are kept until the chat changes, so the host can supply them once when the chat opens and again whenever it learns more. Candidates for any chat but the open one are ignored.
func (*Model) SetMentionsEnabled ¶ added in v0.0.28
SetMentionsEnabled says whether a typed @ may open completion here. The host switches it on for basic groups and supergroups.
It is a property of the open chat: SetChatId switches it off again, so the host calls this after every switch. Forgetting to leaves a group without completion — never a private chat with it.
func (*Model) SetMode ¶
SetMode tells the composer which interaction mode to report for the states it cannot see itself: COMMAND, and the NORMAL of another panel holding focus. The app resolves it; see internal/app/mode.go.
func (*Model) SetParseMarkdown ¶
SetParseMarkdown tells the composer whether outgoing markdown parsing is on, which decides both the "md" label and whether the expanded form's preview shows parsed text or the text verbatim.
The label is only honest when it reflects the setting: showing "md" with parsing off would promise a transformation that will not happen.
func (*Model) SetRoles ¶
SetRoles supplies the TUI 2.0 semantic palette, and re-derives the textarea's styles from it — New built those from the palette it was given, and they would otherwise stay in that one.
func (*Model) SetUploadProgress ¶ added in v0.0.21
func (m *Model) SetUploadProgress(path string, generation uint64, uploaded, total int64, failed bool)
SetUploadProgress records how far the pending attachment has got on its way to Telegram, for the chip above the prompt to show. Reports about any other file are ignored: an upload started for an attachment that has since been replaced outlives it by a moment, and the chip must not show its progress under the new file's name.
generation says which attempt is reporting. One older than the attempt on the chip is dropped — a cancelled upload of the same path is still reporting after its replacement started, and neither its percentage nor its failure is news about the file now going up. A newer one is the replacement, and starts from nothing known.
Within an attempt the percentage only ever climbs. The parts are confirmed by four threads and the callback runs outside the counter's lock, so an older percentage can arrive after a newer one — and a chip that fell from ✓ back to ↑ 99% would sit there, because the report that would have repaired it has already been and gone.
A failed upload clears the state instead of freezing a percentage that will never advance — the send re-uploads the file itself, so there is nothing for the reader to act on.
func (Model) Update ¶
Update handles messages.
Key dispatch matches on tea.KeyPressMsg.Keystroke() for every chord, and on String() only for the unmodified printables that drive vi's normal mode. String() returns Key.Text whenever the terminal attached any: a Kitty-protocol shift+enter arrives as CSI 13;2;13u, so String() is "\r" while Keystroke() is "shift+enter". Matching the newline chord on String() would have made it invisible in exactly the terminals that can report it. See the keyPress doc comment in internal/app/keymap.go.
type PasteRequestedMsg ¶
type PasteRequestedMsg struct{}
PasteRequestedMsg is emitted when the user asks to attach whatever image is on the system clipboard (Ctrl+V).
type ResizedMsg ¶
type ResizedMsg struct{}
ResizedMsg is emitted when the composer's row count changes, so the host can recompute the layout before the next paint.
The composer cannot resize itself: the rows it takes come out of the thread's budget, and only the host knows what the rest of the screen is doing. Emitting rather than assuming is what keeps the two from disagreeing about where the composer starts.