The message box shared by gvoice-tui and at-claude: text, cursor, wrapping and every editing key
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Nelson 6ecd97916f
All checks were successful
Suite release / check-build (none, ubuntu-latest) (ubuntu-latest, none) (push) Has been skipped
Suite release / build (none, ubuntu-latest) (ubuntu-latest, none) (push) Has been skipped
Suite release / reused-checks (push) Has been skipped
Suite release / publish (push) Has been skipped
Suite release / scope (push) Successful in 9s
Suite release / check-package (push) Has been skipped
Suite release / finalize (push) Has been skipped
Suite release / deliver (push) Has been skipped
Suite release / module (push) Has been skipped
Suite release / reserve (push) Has been skipped
Suite release / check-manifest (push) Has been skipped
Suite release / deploy-image (push) Has been skipped
Suite release / deliver-prune (push) Has been skipped
Fix the shared CI's lint findings (PIPT-85) (#6)
2026-11-30 14:28:22 -08:00
.gitignore Start composer: README, license and module 2026-11-16 23:15:27 -08:00
atoms.go Atoms: text an app marks is one unit, and Replace (ATC-191) (#2) 2026-11-23 20:40:11 -08:00
atoms_test.go Replace starting inside an atom no longer crashes (ATC-200) (#4) 2026-11-25 04:16:13 -08:00
bench_test.go Keep the message's layout until its text, width or atoms change (ATC-200) (#3) 2026-11-25 04:14:19 -08:00
box.go Select text in the message box: Shift with the movement keys and the mouse (ATC-238) (#5) 2026-11-29 14:22:51 -08:00
box_test.go APPS-67 The message box: text, cursor, wrapping and every editing key (#1) 2026-11-17 08:10:38 -08:00
commands.go Select text in the message box: Shift with the movement keys and the mouse (ATC-238) (#5) 2026-11-29 14:22:51 -08:00
draw.go Select text in the message box: Shift with the movement keys and the mouse (ATC-238) (#5) 2026-11-29 14:22:51 -08:00
go.mod APPS-67 The message box: text, cursor, wrapping and every editing key (#1) 2026-11-17 08:10:38 -08:00
go.sum APPS-67 The message box: text, cursor, wrapping and every editing key (#1) 2026-11-17 08:10:38 -08:00
keys.go Select text in the message box: Shift with the movement keys and the mouse (ATC-238) (#5) 2026-11-29 14:22:51 -08:00
layout.go Keep the message's layout until its text, width or atoms change (ATC-200) (#3) 2026-11-25 04:14:19 -08:00
layout_test.go Keep the message's layout until its text, width or atoms change (ATC-200) (#3) 2026-11-25 04:14:19 -08:00
LICENSE Start composer: README, license and module 2026-11-16 23:15:27 -08:00
README.md Fix the shared CI's lint findings (PIPT-85) (#6) 2026-11-30 14:28:22 -08:00
select.go Select text in the message box: Shift with the movement keys and the mouse (ATC-238) (#5) 2026-11-29 14:22:51 -08:00
select_test.go Select text in the message box: Shift with the movement keys and the mouse (ATC-238) (#5) 2026-11-29 14:22:51 -08:00

composer

The message box shared by Nelson's terminal apps, gvoice-tui and at-claude: one place for the text, the cursor, wrapping and every editing key, so a change to how typing works reaches both. Work package: APPS-67.

It is a Go library with no terminal of its own, like fzt: an app passes it keys and pastes, and draws it where it wants.

Keys

Key Does
Enter Returns Send; the app sends Value() and resets the box
Shift+Enter, Alt+Enter, Ctrl+J New line (at-terminal sends Shift+Enter as Alt+Enter)
Left, Right; Ctrl or Alt with them, Alt+B, Alt+F A character; a word
Up, Down A row, keeping the column; past the first or last row, Unhandled
Ctrl+Up, Ctrl+Down The start of this line of the message or the one before; the next
Home, End, Ctrl+A, Ctrl+E The start or end of the row
Backspace, Delete, Ctrl+H, Ctrl+D (Shift held too) A character
Ctrl+W, Alt+Backspace, Ctrl+Backspace; Alt+D, Ctrl+Delete A word back; forward
Ctrl+U, Ctrl+K To the start, or the end, of this line of the message
Ctrl+Z, Ctrl+Y Undo, a typed word at a time; redo
Shift with Left, Right, Up, Down, Home or End; with Ctrl+Left, Ctrl+Right, Ctrl+Up, Ctrl+Down Select as the cursor moves; Shift+Up on the first row selects to the message's start, Shift+Down on the last to its end
Ctrl+Shift+Home, Ctrl+Shift+End Select to the message's start or end

Every other key comes back Unhandled for the app: Esc, Tab, PgUp and PgDn, Ctrl+Home and Ctrl+End, Ctrl+C, other Alt keys. An app handles its own keys before giving the rest to the box. Commands lists the box's commands with their keys, for an app's command palette, and Do runs one.

Selecting

A selection runs from where it started to the cursor. Typing, a paste, a new line, Backspace, Delete and every deleting key replace or take it, as one change that undo puts back. Left and Right without Shift end it at its start or end; any other move ends it where the cursor goes. Draw and View show it in Styles.Selection (unset, the message reversed), and View draws no cursor cell while it shows, since its edge is the cursor.

The mouse is the app's to read: Click places the cursor and ends a selection, Drag with the button held selects from the click to a cell (a cell above or below the box scrolls it a row), and SelectWord and SelectLine are a double- and a triple-click, the word (or run of spaces, or atom) and the line of the message under it. The box has no clipboard: Selection is the selected text for the app to copy, Cut takes it out as one change and gives it back, SelectAll and ClearSelection set it, and Selecting says there is one.

Using it

box := composer.New(6)   // grows to 6 rows, then scrolls
box.SetWidth(w)          // columns it takes; text wraps one short, for the cursor
switch box.Key(ev.Key(), ev.Rune(), ev.Modifiers()) {
case composer.Send:
    send(box.Value())
case composer.Unhandled:
    // the app's own key
}
box.Insert(pasted)       // a paste, or text a command puts in, as one change
box.Draw(screen, x, y, styles, true)   // on a tcell screen, its cursor shown
view := box.View(styles, true)         // or as text for a Bubble Tea view

Height is the rows it takes, Top the message's first row shown, Cursor where its cursor is within them, Click places the cursor at a cell, Position and SetPosition give and set it as a line of the message and an offset, Paragraph is the cursor's line, Replace puts text in place of part of a line as one change, and SetValue and Value keep a draft.

SetAtoms(pattern) makes each stretch of text the pattern matches an atom, one unit: the cursor steps over it and never stops inside it, Backspace and Delete take it whole, a deletion that would cut into it takes all of it, it wraps whole unless it is wider than a row, and it is drawn in Styles.Atom. Atoms are the message's text, so Value, SetValue, a paste and undo carry them with nothing else to keep. at-claude uses them for the objects picked from its menu (ATC-191).

Text wraps at the places Unicode allows a line break, a word wider than a row is split, spaces stay at the end of the row they follow, and a character made of several code points (an emoji with its skin tone) is never split. What is typed or pasted keeps its line breaks; a tab becomes four spaces, and other control characters and the bidirectional controls that reorder text are dropped, so nothing in it reaches the terminal as a command or changes how the text around it shows.

Testing

go vet ./...
go test -p 4 ./...

Shipping

Forgejo is its home; GitHub gets a one-way copy so go can fetch it by its github.com/romaine-life/composer name. CI is pipeline-templates' go and release suites (fleet.json): pull requests run vet and tests on Linux and Windows, a merge that changes the code takes the next v0.1.N tag, and gvoice-tui and at-claude take it up through their go.dependencies.