logview

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 7 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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 New

func New(width, height int) Model

New returns a Model sized to width x height.

func (*Model) Append

func (m *Model) Append(line string)

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

func (m Model) DrawCells(buf *cellbuf.Buffer, r cellbuf.Rect)

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

func (m Model) LayoutNode() layout.Node

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

func (m Model) Linearize() string

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

func (m Model) NewLines() int

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

func (m *Model) NextMatch() bool

NextMatch and PrevMatch move between search matches (also bound to n and N in Update while a query is set).

func (*Model) PrevMatch

func (m *Model) PrevMatch() bool

PrevMatch moves to the previous search match.

func (*Model) Search

func (m *Model) Search(q string) int

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

func (m *Model) SetFollow(on bool)

SetFollow turns follow-tail mode on or off. Turning it on scrolls to the bottom and clears NewLines.

func (Model) Update

func (m Model) Update(msg tui.Msg) (Model, tui.Cmd)

Update delegates to the embedded viewport.Model's Update.

func (Model) View

func (m Model) View() string

View renders the viewport. While NewLines is positive the last row shows an "N new lines" indicator in place of that row's content.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL