bublog

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2025 License: MIT Imports: 5 Imported by: 0

README

Logging component for bubbletea TUI framework

If you want to duplicate logs of your application to TUI and any other number of io.Writers. To integrate it to slog:

	slog.SetDefault(slog.New(slog.NewTextHandler(m)))

Documentation

Overview

Package bublog to show your logs in TUI and duplicate them to other places.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitLine added in v0.0.3

func SplitLine(line []rune, maxWidth int) [][]rune

SplitLine fits an array of []rune into several with max length of maxWidth.

Types

type KeyMap added in v0.0.3

type KeyMap struct {
	StickToBottom key.Binding
	ScrollDown    key.Binding
	ScrollUp      key.Binding
}

func DefaultKeyMap added in v0.0.3

func DefaultKeyMap() *KeyMap

type Model

type Model struct {
	AdditionalWriters []io.Writer
	Viewer            *TextViewer
	KeyMap            *KeyMap
}

func NewModel added in v0.0.3

func NewModel(initialText string, additionalWriters ...io.Writer) *Model

func (*Model) Init

func (m *Model) Init() tea.Cmd

func (*Model) SetSize

func (m *Model) SetSize(sizes ...int)

SetSize accepts up to two arguments. First fill be Width, second - Height.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Model) View

func (m *Model) View() string

func (*Model) Write

func (m *Model) Write(p []byte) (n int, err error)

Write allows using this model as an argument to logging tools.

type TextViewer added in v0.0.3

type TextViewer struct {
	// Inner representation of Text is already split by /n to make it easier to navigate.
	Text [][]rune

	// DisplayText has several layer structure.
	// Upper level represents a complete /n line from Text.
	// Level below is a sublines - several strings gotten from original to fix into Width.
	// Last level is rune representation of a string.
	DisplayText [][][]rune

	Width  int
	Height int

	// LineInText shows from which line current DisplayText is rendered.
	LineInText           int
	SubLineInDisplayText int

	StickedToBottom bool
}

TextViewer takes Text and allows to have only a portion of it being displayed in given Private.Width and Private.Height

func NewTextViewer added in v0.0.3

func NewTextViewer(text []rune) *TextViewer

func (*TextViewer) AppendToText added in v0.0.3

func (t *TextViewer) AppendToText(s string)

func (*TextViewer) Recalculate added in v0.0.3

func (t *TextViewer) Recalculate()

func (*TextViewer) ScrollDown added in v0.0.3

func (t *TextViewer) ScrollDown() bool

func (*TextViewer) ScrollTextDown added in v0.0.3

func (t *TextViewer) ScrollTextDown() bool

func (*TextViewer) ScrollTextUp added in v0.0.3

func (t *TextViewer) ScrollTextUp() bool

func (*TextViewer) ScrollUp added in v0.0.3

func (t *TextViewer) ScrollUp() bool

func (*TextViewer) SetHeight added in v0.0.3

func (t *TextViewer) SetHeight(h int)

func (*TextViewer) SetWidth added in v0.0.3

func (t *TextViewer) SetWidth(w int)

func (*TextViewer) SwitchStickToBottom added in v0.0.3

func (t *TextViewer) SwitchStickToBottom()

func (*TextViewer) View added in v0.0.3

func (t *TextViewer) View() [][]rune

Jump to

Keyboard shortcuts

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