stream

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogMsg

func LogMsg(l *slog.Logger, level slog.Level, text string, label string, msg tea.Msg, args ...any)

LogMsg is equivalent to LogMsgCtx, using the context.Background() as context. See LogMsgCtx.

func LogMsgCtx

func LogMsgCtx(ctx context.Context, l *slog.Logger, level slog.Level, text string, label string, msg tea.Msg, args ...any)

LogMsgCtx is a helper function that logs a tea.Msg to a slog.Logger. It logs the key type and value. If the message supports the fmt.Stringer interface, it is used to format the key value. Otherwise, the value is formatted using fmt's "%#v" printing verb.

Types

type KeyMap

type KeyMap struct {
	WordWrap   key.Binding
	AutoScroll key.Binding
}

KeyMap represents the key bindings for a Stream.

func DefaultKeyMap

func DefaultKeyMap() KeyMap

DefaultKeyMap returns the default key map for a Stream.

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

FullHelp returns the key bindings for the stream. Returns the same as ShortHelp.

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

ShortHelp returns the key bindings for the stream.

type Option

type Option func(*Stream)

Option is a functional option for configuring a Stream.

func WithAutoScroll

func WithAutoScroll(autoScroll bool) Option

WithAutoScroll overrides the initial state of auto-scrolling.

func WithKeyMap

func WithKeyMap(keyMap KeyMap) Option

WithKeyMap overrides the default keyMap.

func WithMaxSize

func WithMaxSize(max uint32) Option

WithMaxSize sets the maximum number of bytes that are kept in memory.

func WithShowToggles

func WithShowToggles(show bool) Option

WithShowToggles switches showing the state of the word wrap and auto-scrolling toggles.

func WithWrapLines

func WithWrapLines(wrapLines bool) Option

WithWrapLines overrides the initial state of word wrapping.

type SetSizeMsg

type SetSizeMsg struct {
	Width  int
	Height int
}

SetSizeMsg sets the size of the Stream contents

type Stream

type Stream struct {
	viewport.Model
	// contains filtered or unexported fields
}

A Stream is a model that implements io.Writer. Applications can write data to the stream and it will be displayed in a viewport.

This model was written to display an application's slog output, but it can be used for any kind of streaming data.

func NewStream

func NewStream(width, height int, o ...Option) Stream

func (Stream) Init

func (s Stream) Init() tea.Cmd

Init implements the tea.Model interface.

func (Stream) Update

func (s Stream) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update implements the tea.Model interface.

func (Stream) View

func (s Stream) View() string

View implements the tea.Model interface.

func (Stream) Write

func (s Stream) Write(p []byte) (n int, err error)

Write implements io.Writer. Any data written to the stream will be displayed in the viewport.

Jump to

Keyboard shortcuts

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