1
1
mirror of https://github.com/walles/moar.git synced 2024-12-02 09:15:46 +03:00

Add embedding instructions

Improves #31 with both documentation and a simpler API.
This commit is contained in:
Johan Walles 2020-12-28 19:27:25 +01:00
parent 17ac7e8e62
commit d7e0e7e8ff
2 changed files with 43 additions and 0 deletions

View File

@ -72,6 +72,27 @@ Issues
Issues are tracked [here](https://github.com/walles/moar/issues), or
you can send questions to <johan.walles@gmail.com>.
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
----------

22
m/util.go Normal file
View File

@ -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
}