Skip to content

Add writebook tui - #14

Open
monorkin wants to merge 16 commits into
mainfrom
tui
Open

monorkin wants to merge 16 commits into
mainfrom
tui

Conversation

@monorkin

Copy link
Copy Markdown
Collaborator

Adds writebook tui, a terminal UI for browsing and editing books.

Screens

  • Instance picker: a rounded window over a starfield, ported from the ONCE installer. Ctrl+I opens it as an overlay from anywhere.
  • Books:
    • A gallery of covers with title, subtitle and author. The selected book gets a rounded border in its theme color, and a book without a cover shows a block in its theme color.
    • v switches to a list.
    • / searches all books, n makes a new book, s opens settings.
  • A book:
    • The cover, title, subtitle and author, then its pages as a gallery of previews with word counts, or as a list.
    • a adds a page, picture or section.
    • d deletes, m moves, p publishes (address, copy, QR code), e edits the book.
    • / searches the book.
  • A page:
    • Pages render their Markdown, including images.
    • Pictures and sections show centered.
    • ←/→ turns pages, and Ctrl+I opens the book's index.
  • Editor: e on a page. You write Markdown, which styles itself as you type, like hey-cli's composer.
    • Lists continue on Enter.
    • Ctrl+U uploads a file into the page.
    • Ctrl+S saves.
  • Book form: for new and edited books, laid out like the web's. It has the cover (picked with a file picker), title, subtitle, author, theme, and who can read and edit.
  • Settings: the invite link (copy, QR code, reset), and people's roles. Nobody can change their own role.
  • Profile: name and email, and your password. Changing the email or password asks for your current one.

Help sits at the bottom of every screen, in hey-cli's style, and ? toggles it. Every confirmation is a Yes/No choice. Ctrl+C asks before quitting, and a second Ctrl+C quits.

How it's built

  • Libraries: ratatui and crossterm draw the screens. ratatui-image draws images over kitty, sixel or iTerm2, with half blocks as the fallback in tmux and other multiplexers. pulldown-cmark renders pages, and qrcode draws the QR codes.
  • Network calls: all of them run on threads, so the screen never waits on the network.
  • Sign-ins: the TUI reuses the CLI's sign-ins and API client. creds::signed_in_token reports why renewing a sign-in failed rather than printing a note. writebook mcp now uses it too, so it no longer says "you're not signed in" when the server is down.

Needs basecamp/writebook#520 for the JSON it reads.

Tests cover the screens' keys and layout, the Markdown rendering and editor styling, the file picker, and search highlighting. writebook tui without a terminal stops with an error.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved defects can crash the TUI on resize, display stale search results or images from another instance, and hide selected entries or clip content.

15 open issues
What changed in this PR

Adds writebook tui, an interactive terminal interface for browsing and editing books that reuses the CLI’s sign-ins and API client.

Changes:

  • Adds book browsing, Markdown reading and editing, file selection, publishing, settings, and profile screens.
  • Adds terminal rendering dependencies, image support, contextual help, and UI tests.
  • Preserves highlighted search snippets and reports sign-in renewal failures to TUI and MCP callers.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
tests/​tui.rs Tests rejection of non-terminal execution.
src/​tui/​views.rs Draws galleries, lists, forms, and confirmation overlays.
src/​tui/​theme.rs Maps book themes to terminal colors.
src/​tui/​starfield.rs Animates the instance picker’s background.
src/​tui/​settings.rs Adds people and invitation management.
src/​tui/​search.rs Adds search input, results, and highlighting.
src/​tui/​reader.rs Displays pages, pictures, sections, and the index.
src/​tui/​profile.rs Adds profile and password editing.
src/​tui/​markdown.rs Renders styled Markdown and image rows.
src/​tui/​images.rs Loads, caches, and renders images.
src/​tui/​help.rs Formats contextual keyboard help.
src/​tui/​files.rs Adds file selection with image previews.
src/​tui/​editor.rs Adds Markdown editing, styling, and list continuation.
src/​tui/​edit.rs Adds book creation and settings forms.
src/​tui/​data.rs Connects TUI operations to existing authentication and APIs.
src/​read.rs Exposes search results and preserves highlighted snippets.
src/​mcp.rs Propagates sign-in renewal errors.
src/​main.rs Registers the tui command.
src/​creds.rs Adds token retrieval with explicit renewal errors.
skills/​writebook/​SKILL.md Documents that the TUI requires human interaction.
README.md Introduces the terminal UI command.
Cargo.toml Adds terminal, image, Markdown, and QR dependencies.
Cargo.lock Locks the added dependencies.

Review effort: Balanced

Comment thread src/tui/data.rs Resolved
Comment thread src/tui/editor.rs Resolved
Comment thread src/tui/editor.rs Resolved
Comment thread src/tui/images.rs Resolved
Comment thread src/tui/markdown.rs Resolved
Comment thread src/tui/search.rs Resolved
Comment thread src/tui/search.rs Resolved
Comment thread src/tui/settings.rs Resolved
Comment thread src/tui/views.rs Resolved
Comment thread src/tui/views.rs Resolved
Each screen and overlay now owns its state, keys, bindings, drawing and the
requests it starts; tui.rs keeps the event loop, message routing and global
keys. Background work goes through one spawn helper, the yes/no questions
are one confirmation overlay, search and the file picker share one large
window, and the "not signed in" error lives in one place.
…hat it does, and encode the clipboard with the base64 crate
…at instead of what's selected when it's answered

Copilot AI left a comment

Copy link
Copy Markdown

…other than what's open, and retry a failed search on enter
…ore ctrl and alt letters in fields, keep tab for the profile's fields, and continue a list only from after its marker
…r a line, keep every bullet of nested list items, and render tables a row to a line
…er a page's Markdown once per width instead of every frame
…ll the people, instances and index to the selected row, and keep the selected person on the list after a reload
… MB and decoded within limits, and fetch images from other sites without the token

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

Unresolved issues can crash the TUI, apply asynchronous results to unrelated screens or instances, discard unsaved edits, and falsely mark changes as saved.

14 open issues
15 resolved since last review

Review effort: Balanced

Comment thread src/tui/markdown.rs Resolved
Comment thread src/tui/overlays.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/publishing.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
Comment thread src/tui/screens.rs Resolved
…nds, so the next paragraph doesn't look for its prefix
…each one gets when it's made

Replies found their target by what was open when they arrived, so a book
save, a deletion, a loaded page or a publishing change could land on another
book's screen, and replies for screens set aside under settings, an editor or
a page, or for an overlay under the quit question, were dropped. Now every
request carries the id of the screen or overlay it's for, and its reply goes
there wherever it is, or nowhere if it's gone.

A page gets a new id for each page turned to, saving waits for uploads into
the page to finish, and only the last invite reset shows its link.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants