Documentation
¶
Overview ¶
Public API for embedding a pager in your application
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PageFromFile ¶
If stdout is not a terminal, the file contents will just be printed to stdout.
func PageFromStream ¶
PageFromStream reads the contents of the given reader and presents it in a pager.
Note that if the provided reader implements io.Closer, it will be closed automatically once the pager has finished reading from it or when the pager exits.
If stdout is not a terminal, the stream contents will just be printed to stdout.
func PageFromStreamWithScreen ¶ added in v2.18.0
PageFromStreamWithScreen is like PageFromStream but lets the caller provide a custom twin.Screen implementation instead of allocating one from the real terminal. This enables embedding moor inside another TUI (e.g. a bubbletea app): the caller implements twin.Screen to render moor's output into a pane and feed keyboard/mouse events from the host TUI's event loop.
Unlike PageFromStream, this function does not require stdout to be a terminal - the caller's custom screen decides where output goes.
The caller owns the screen and is responsible for closing it; moor will not call screen.Close().
options.QuitIfOneScreen is not supported here: it's built around printing leftover output to the real stdout on the way out, which assumes moor owns the real terminal.
This function blocks until the pager exits, either because of user input (e.g. pressing 'q') or because the caller pushes a twin.EventExit into screen.Events() — the same channel keyboard, mouse, and other events should be fed into from another goroutine. Run this in its own goroutine if you need concurrent rendering.
func PageFromString ¶
If stdout is not a terminal, the string contents will just be printed to stdout.
Types ¶
type Options ¶
type Options struct {
// Name displayed in the bottom left corner of the pager.
//
// Defaults to the file name when paging files, otherwise nothing. Leave
// blank for default.
Title string
// The default is to auto format JSON input. Set this to true to disable
// auto formatting.
NoAutoFormat bool
// The default is to truncate long lines, and let the user press right-arrow
// to see more of them. Set this to true to wrap long lines instead. Users
// can toggle wrapping on / off using the 'w' key while paging.
WrapLongLines bool
// The default is to show line numbers. Set this to true to disable line
// numbers. The user can toggle line numbers on by pressing the left-arrow
// key while paging.
NoLineNumbers bool
// The default is to always start the pager. If this is set to true, short
// input will just be printed, and no paging will happen.
QuitIfOneScreen bool
}
If you feel some option is missing, make PRs at https://github.com/walles/moor/pulls open an issue.