Documentation
¶
Overview ¶
Package logview is an append-only scrolling log view. It composes viewport.Model rather than reimplementing scrolling: Log's own job is just appending lines and auto-scrolling to bottom on append when the reader is already at the bottom.
Example ¶
A logview keeps the newest lines in view as they are appended.
package main
import (
"fmt"
"github.com/ows4444/tui/ansi"
"github.com/ows4444/tui/logview"
)
func main() {
m := logview.New(20, 2)
for _, l := range []string{"one", "two", "three"} {
m.Append(l)
}
fmt.Println(ansi.StripANSI(m.View()))
}
Output: two three
Index ¶
- type Model
- func (m *Model) Append(line string)
- func (m Model) DrawCells(buf *cellbuf.Buffer, r cellbuf.Rect)
- func (m Model) LayoutNode() layout.Node
- func (m Model) Linearize() string
- func (m Model) NewLines() int
- func (m *Model) NextMatch() bool
- func (m *Model) PrevMatch() bool
- func (m *Model) Search(q string) int
- func (m *Model) SetFollow(on bool)
- func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)
- func (m Model) View() string
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Model ¶
type Model struct {
Viewport viewport.Model
// Max, if positive, caps the number of lines kept: an Append that would
// exceed it drops the oldest lines. Zero (the default) means unbounded.
Max int
// NewLinesIndicator, when true, makes View show an "N new lines" row
// over the last row while the reader is scrolled up and lines arrived.
// Off by default so View is exactly the viewport's rows; NewLines is
// always tracked.
NewLinesIndicator bool
// Follow, when true, pins the view to the newest line: every Append
// scrolls to the bottom, even if the Viewport was moved off it by code.
// Scrolling away with the keys or mouse wheel (Update), or jumping to a
// search match, turns it off, like pressing a key in `tail -f`; set it
// again, or call SetFollow, to resume. With Follow false an Append still
// stays pinned while the reader is already at the bottom.
Follow bool
// contains filtered or unexported fields
}
Model is an append-only log built on top of viewport.Model.
func (*Model) Append ¶
Append adds line to the log. If the viewport was scrolled to the bottom before the append, it stays pinned to the bottom so the new line is visible. If the reader had scrolled up, the scroll position is left unchanged (and, when Max drops lines above it, keeps showing the same content).
func (Model) DrawCells ¶
DrawCells draws the log into r of buf as View shows it: the viewport's rows, with the "N new lines" indicator replacing the last row when it is on. It implements tui.CellDrawer.
func (Model) LayoutNode ¶
LayoutNode adapts the log to a layout.Node by way of its viewport, sized to the allotted Size. A log that was following its tail (scrolled to the bottom) keeps following it at the new size, as Append does; one the user scrolled up keeps its offset. The Model is not changed.
func (Model) Linearize ¶
Linearize renders the log as plain text for accessible output (see tui.Linearizer): every line, oldest first, with escape sequences removed. There is no header, so an appended line adds only one new line to an append-only transcript.
func (Model) NewLines ¶
NewLines returns how many lines were appended while the reader was scrolled up. It resets to 0 once the view is back at the bottom (End).
func (*Model) NextMatch ¶
NextMatch and PrevMatch move between search matches (also bound to n and N in Update while a query is set).
func (*Model) Search ¶
Search highlights every match of q and jumps to the first one at or below the top row, returning the match count; see viewport.Model.Search. Jumping to a match leaves follow-tail mode unless the match is on screen at the bottom.
func (*Model) SetFollow ¶
SetFollow turns follow-tail mode on or off. Turning it on scrolls to the bottom and clears NewLines.