1
1
mirror of https://github.com/walles/moar.git synced 2024-11-13 11:14:30 +03:00

Make the paging function accept a Reader

This should cover all use cases with just one method.
This commit is contained in:
Johan Walles 2020-12-29 17:22:18 +01:00
parent 7f7b0107d5
commit f069409725
2 changed files with 24 additions and 22 deletions

24
m/embed-api.go Normal file
View File

@ -0,0 +1,24 @@
package m
import "github.com/gdamore/tcell/v2"
// Page displays text in a pager.
//
// The reader parameter can be constructed using one of:
// * NewReaderFromFilename()
// * NewReaderFromText()
// * NewReaderFromStream()
//
// Or your could roll your own Reader based on the source code for any of those
// constructors.
func Page(reader *Reader) error {
screen, e := tcell.NewScreen()
if e != nil {
// Screen setup failed
return e
}
defer screen.Fini()
NewPager(reader).StartPaging(screen)
return nil
}

View File

@ -1,22 +0,0 @@
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
}