uvcasso

package module
v0.0.0-...-c62b339 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 4 Imported by: 0

README

[!NOTE] This code is now a part of charmbracelet/ultraviolet.


🏗️ uvcasso

Layout splitting for charmbracelet/ultraviolet based on Cassowary constraint-solving algorithm.

TL;DR

It allows you to dynamically split terminal screen into multiple rectangles based on the given constraints.

For example:

func display(s *uv.TerminalScreen) {
	screen.Clear(s)

	var top, bottom uv.Rectangle

	uvcasso.Vertical(
		uvcasso.Fill(1),
		uvcasso.Len(1),
		uvcasso.Len(3),
	).
		Split(s.Bounds()).
		Assign(&top, nil, &bottom)

	// ^^^^^^^^^^^^^^^^^^^^^^^^^^^
	// The interesting part

	screen.FillArea(s, &uv.Cell{
		Content: "T",
		Width:   1,
	}, top)

	screen.FillArea(s, &uv.Cell{
		Content: "B",
		Width:   1,
	}, bottom)

	// Will fill the screen like this:
	// 1. Top part takes all available space
	// 2. Middle part takes exactly 1 line which we leave empty
	// 3. Bottom part takes exactly 3 lines

	/*
	   TTTTTTTTTTTTTTTT
	   TTTTTTTTTTTTTTTT
	   TTTTTTTTTTTTTTTT
	   TTTTTTTTTTTTTTTT
	   TTTTTTTTTTTTTTTT

	   BBBBBBBBBBBBBBBB
	   BBBBBBBBBBBBBBBB
	   BBBBBBBBBBBBBBBB
	*/

	s.Render()
	s.Flush()
}

Acknowledgements

This code is roughly 1:1 translation of how it's implemented in the ratatui, including the tests.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Constraint

type Constraint interface {
	fmt.Stringer
	// contains filtered or unexported methods
}

type Direction

type Direction int
const (
	DirectionVertical Direction = iota
	DirectionHorizontal
)

type Fill

type Fill int

func (Fill) String

func (f Fill) String() string

type Flex

type Flex int
const (
	FlexLegacy Flex = iota
	FlexStart
	FlexEnd
	FlexCenter
	FlexSpaceBetween
	FlexSpaceAround
)

type Layout

type Layout struct {
	Direction   Direction
	Constraints []Constraint
	Padding     Padding
	Spacing     Spacing
	Flex        Flex
}

func Horizontal

func Horizontal(constraints ...Constraint) Layout

func New

func New(direction Direction, constraints ...Constraint) Layout

func Vertical

func Vertical(constraints ...Constraint) Layout

func (Layout) Split

func (l Layout) Split(area uv.Rectangle) Splitted

func (Layout) SplitWithSpacers

func (l Layout) SplitWithSpacers(area uv.Rectangle) (segments, spacers Splitted)

func (Layout) WithConstraints

func (l Layout) WithConstraints(constraints ...Constraint) Layout

func (Layout) WithDirection

func (l Layout) WithDirection(direction Direction) Layout

func (Layout) WithFlex

func (l Layout) WithFlex(flex Flex) Layout

func (Layout) WithPadding

func (l Layout) WithPadding(padding Padding) Layout

func (Layout) WithSpacing

func (l Layout) WithSpacing(spacing Spacing) Layout

type Len

type Len int

func (Len) String

func (l Len) String() string

type Max

type Max int

func (Max) String

func (m Max) String() string

type Min

type Min int

func (Min) String

func (m Min) String() string

type Padding

type Padding struct {
	Top, Right, Bottom, Left int
}

func NewPadding

func NewPadding(sides ...int) Padding

func (Padding) Apply

func (p Padding) Apply(area uv.Rectangle) uv.Rectangle

func (Padding) WithBottom

func (p Padding) WithBottom(s int) Padding

func (Padding) WithLeft

func (p Padding) WithLeft(s int) Padding

func (Padding) WithRight

func (p Padding) WithRight(s int) Padding

func (Padding) WithTop

func (p Padding) WithTop(s int) Padding

type Percentage

type Percentage int

func (Percentage) String

func (p Percentage) String() string

type Ratio

type Ratio struct{ Num, Den int }

func (Ratio) String

func (r Ratio) String() string

type Spacing

type Spacing interface {
	// contains filtered or unexported methods
}

type SpacingOverlap

type SpacingOverlap int

type SpacingSpace

type SpacingSpace int

type Splitted

type Splitted []uv.Rectangle

func (Splitted) Assign

func (s Splitted) Assign(areas ...*uv.Rectangle)

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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