diff --git a/README.md b/README.md index bce219a..80eeb5b 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,27 @@ Issues Issues are tracked [here](https://github.com/walles/moar/issues), or you can send questions to . +Embedding +--------- + +Here's how to embed `moar` in your app: + +```go +package main + +import ( + "github.com/walles/moar/m" +) + +func main() { + err := m.PageString("Months", "March, April\nMay") + if err != nil { + // Handle pager problems + panic(err) + } +} +``` + Developing ---------- diff --git a/m/util.go b/m/util.go new file mode 100644 index 0000000..6bc6a12 --- /dev/null +++ b/m/util.go @@ -0,0 +1,22 @@ +package m + +import "github.com/gdamore/tcell/v2" + +// PageString displays a multi-line text in a pager. +// +// name - Will be displayed in the bottom left corner of the pager window +// +// text - This is the (potentially long) multi line text that will be displayed +func PageString(name string, text string) error { + reader := NewReaderFromText(name, text) + + screen, e := tcell.NewScreen() + if e != nil { + // Screen setup failed + return e + } + defer screen.Fini() + + NewPager(reader).StartPaging(screen) + return nil +}