1
1
mirror of https://github.com/walles/moar.git synced 2025-01-08 14:30:57 +03:00

Merge pull request #52 from 89z/master

DeInit: make output copy friendly
This commit is contained in:
Johan Walles 2021-04-24 09:22:14 +02:00 committed by GitHub
commit 9e6af21106
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -21,6 +21,7 @@ var sgrSequencePattern = regexp.MustCompile("\x1b\\[([0-9;]*m)")
// A Line represents a line of text that can / will be paged
type Line struct {
done bool
raw *string
plain *string
cells []twin.Cell
@ -48,13 +49,13 @@ func (line *Line) Plain() string {
}
func (line *Line) parse() {
if line.raw == nil {
if line.done {
// Already done
return
}
line.cells, line.plain = cellsFromString(*line.raw)
line.raw = nil
line.done = true
}
// SetManPageFormatFromEnv parses LESS_TERMCAP_xx environment variables and

View File

@ -1,6 +1,9 @@
package m
import "github.com/walles/moar/twin"
import (
"fmt"
"github.com/walles/moar/twin"
)
// Page displays text in a pager.
func (p *Pager) Page() error {
@ -10,19 +13,17 @@ func (p *Pager) Page() error {
return e
}
defer func() {
screen.Close()
if p.DeInit {
screen.Close()
return
}
// See: https://github.com/walles/moar/pull/39
// FIXME: Consider moving this logic into the twin package.
w, h := screen.Size()
screen.ShowCursorAt(0, h-1)
for x := 0; x < w; x++ {
screen.SetCell(x, h-1, twin.NewCell(' ', twin.StyleDefault))
_, height := p.screen.Size()
lines := p.reader.GetLines(p.firstLineOneBased, height-1).lines
for _, line := range lines {
fmt.Println(*line.raw)
}
screen.Show()
}()
p.StartPaging(screen)