Improvements to embedding api to allow making your own 'screen' - #456
Open
plutonium-239 wants to merge 4 commits into
Open
Improvements to embedding api to allow making your own 'screen'#456plutonium-239 wants to merge 4 commits into
plutonium-239 wants to merge 4 commits into
Conversation
Owner
|
Interesting! Did you try to embed this exact version of moor in your app? Real life data is super valuable here, changing public APIs after the fact is messy. |
walles
reviewed
Aug 16, 2026
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

I was trying to embed
moorinto my own application when I realized that I couldn't actually have moor run in a 60% width preview window and it would have to be a separate screen.One considered solution was to maintain a fork
twinthat can accept an input height/width, but I'm not sure if that would be useful upstream - sincemoordoes not have such a use case.So, this PR does two things that allow embedding, if that is a desirable thing:
1. Add
PageFromStreamWithScreenfor embedded pagingExtract the shared pager setup from
pageFromReaderintopageFromReaderWithScreen, which accepts a caller-providedtwin.Screeninstead of callingtwin.NewScreen(). AddPageFromStreamWithScreenas a public entry point that skips theterm.IsTerminalguard and delegates to the shared implementation.This enables embedding
moorinside another TUI (e.g. abubbleteaapp) withoutmoortaking over the whole terminal. The caller implementstwin.Screento render into a sub-region and feed events from the host TUI's event loop.2. Add event constructors for embedding applications
Add
NewEventRune,NewEventKeyCode, andNewEventMouseso that embedding applications can createtwinevents to feed into a customScreen's event channel. Without these, the unexported fields onEventRune,EventKeyCode, andEventMousemake it impossible for external code to construct events.Another solution if you do not want more exported functions is to export the struct fields themselves.
AI Disclosure
💘 Generated with Crush
Assisted-by: Crush:z-ai/glm-5.2