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:
parent
7f7b0107d5
commit
f069409725
24
m/embed-api.go
Normal file
24
m/embed-api.go
Normal 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
|
||||
}
|
22
m/util.go
22
m/util.go
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user