rendering

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2025 License: MIT Imports: 7 Imported by: 0

README

renderer package

Responsible for rendering

Dependencies

This package should not not import any other UI package, and should have minimal, ideally zero, dependency on common, utils or any other spf package. Its meant as a utilites to be used by ui components and main model. It also should not be even in-directly coupled with any UI components. Assume anything like color, style, border config of any other UI component change. This package should not have any changes.

To-dos

  • Use rendering package for other models like sort Menu, Help menu, etc.

Notes

  • Can we move this whole thing into a good useful TUI library outside of this repo ?. At least code it in a way that it can be moved

Documentation

Index

Constants

View Source
const (
	PlainTruncateRight = iota
	TailsTruncateRight
)

These truncate styles must preserve ansi escape codes. If something doesn't preserves it shouldn't be here

Variables

This section is empty.

Functions

func TruncateBasedOnStyle

func TruncateBasedOnStyle(line string, maxWidth int, truncateStyle TruncateStyle) string

Types

type BorderConfig

type BorderConfig struct {
	// contains filtered or unexported fields
}

func NewBorderConfig

func NewBorderConfig(height int, width int) BorderConfig

func (*BorderConfig) AddDivider

func (b *BorderConfig) AddDivider(idx int)

func (*BorderConfig) AreInfoItemsTruncated

func (b *BorderConfig) AreInfoItemsTruncated() bool

func (*BorderConfig) GetBorder

func (b *BorderConfig) GetBorder(borderStrings lipgloss.Border) lipgloss.Border

border.Top with something that takes up more than 1 runewidth will not work, so we only allow 1 runewidth for now, in the config. multiple things like border corner characters must be single rune, or else it would break rendering. This is all filled in one function to prevent passing around too many values in helper functions

func (*BorderConfig) SetInfoItems

func (b *BorderConfig) SetInfoItems(infoItems ...string)

func (*BorderConfig) SetTitle

func (b *BorderConfig) SetTitle(title string)

type ContentRenderer

type ContentRenderer struct {
	// contains filtered or unexported fields
}

func NewContentRenderer

func NewContentRenderer(maxLines int, maxLineWidth int, truncateStyle TruncateStyle) ContentRenderer

func (*ContentRenderer) AddLineWithCustomTruncate

func (r *ContentRenderer) AddLineWithCustomTruncate(lineStr string, truncateStyle TruncateStyle)

Maybe better return an error ? AddLineWithCustomTruncate adds lines to the renderer, truncating each line according to the specified style. It does not trims whitespace, and its possible to add multiple empty lines using this.

func (*ContentRenderer) AddLines

func (r *ContentRenderer) AddLines(lines ...string)

func (*ContentRenderer) ClearLines

func (r *ContentRenderer) ClearLines()

func (*ContentRenderer) CntLines

func (r *ContentRenderer) CntLines() int

func (*ContentRenderer) Render

func (r *ContentRenderer) Render() string

type Renderer

type Renderer struct {
	// contains filtered or unexported fields
}

For now we are not allowing to add/update/remove lines to previous sections We may allow that later. Also we could have functions about getting sections count, line count, adding updating a specific line in a specific section, and adjusting section sizes. But not needed now.

func NewRenderer

func NewRenderer(cfg RendererConfig) (*Renderer, error)

func (*Renderer) AddLineWithCustomTruncate

func (r *Renderer) AddLineWithCustomTruncate(line string, truncateStyle TruncateStyle)

Truncate would always preserve ansi codes.

func (*Renderer) AddLines

func (r *Renderer) AddLines(lines ...string) *Renderer

Add lines as much as the remaining capacity allows

func (*Renderer) AddSection

func (r *Renderer) AddSection()

Lines until now will belong to current section, and Any new lines will belong to a new section

func (*Renderer) AreInfoItemsTruncated

func (r *Renderer) AreInfoItemsTruncated() bool

func (*Renderer) Render

func (r *Renderer) Render() string

Should not do any updates on 'r'

func (*Renderer) SetBorderInfoItems

func (r *Renderer) SetBorderInfoItems(infoItems ...string)

func (*Renderer) SetBorderTitle

func (r *Renderer) SetBorderTitle(title string)

func (*Renderer) Style

func (r *Renderer) Style() lipgloss.Style

type RendererConfig

type RendererConfig struct {
	TotalHeight int
	TotalWidth  int

	DefTruncateStyle TruncateStyle
	TruncateHeight   bool
	BorderRequired   bool

	ContentFGColor lipgloss.TerminalColor
	ContentBGColor lipgloss.TerminalColor

	BorderFGColor lipgloss.TerminalColor
	BorderBGColor lipgloss.TerminalColor

	Border lipgloss.Border
}

func DefaultRendererConfig

func DefaultRendererConfig(totalHeight int, totalWidth int) RendererConfig

type TruncateStyle

type TruncateStyle int

Jump to

Keyboard shortcuts

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