chocolate

package module
v0.0.0-...-2717be9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: MIT Imports: 15 Imported by: 0

README

Chocolate

Layout container for Bubble Tea the easy way ;) .... hopefully Chocolate is meant to create complex and responsive layouts with themes via flavour working consistent and without hassle together in TUI applications.

State / Idea

The first implementation wasn't really fitting my intentions. Some of the problems that I identified are:

  • Restrictive interface (forced to work in a own specific way for chocolate)
  • Complicated calculations and inefficient handling of the bubbletea layer
  • Force to use chocolate as management layer for the whole bubbletea TUI

So I took the time to work out a way better implementation that solves the main issues and has way better layout handling.

The layout handling is done by using the cassowary algorithm and is implemented like the GTK constraint layouts.

Further the idea is now to provide a library that is focused only on styling and layouts and not on handling the whole bubbletea model handling.

This makes it now able to work out a chocolate specific components set analog bubbles, which will use the chocolate as layout workhorse. It is focusing on UI components in the way, that it shall provide mainly functionality like dialog (ae.: yes, no) via overlays, status bars, menus, unify the selection of models that provide input functionality, handling the visibility and input focus for the underlying models and so on.

This time I'm very convinced that the API is providing what I wanted to have in the first place.

This is a very early state and in theory the whole API can change at any time. Still now is the best time to get ANY feedback to change the way in the right direction if needed.

To get started, please see the examples Created sweets repository

Priority

The following tasks are in order regarding my personal priority scoring:

  • Providing some basic examples
  • Create the bars repository with some useful bars
  • API method naming cleanup
  • Documentation

Documentation

Index

Constants

Variables

This section is empty.

Functions

func NewChocolateFlavour

func NewChocolateFlavour(opts ...ChocolateThemeOption) *chocolateFlavour

Types

type BarModel

type BarModel interface {
	View() string
	Resize(width, height int)
}

type BarViewer

type BarViewer interface {
	View() string
}

type Chocolate

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

func NewChocolate

func NewChocolate(opts ...ChocolateOption) *Chocolate

func (*Chocolate) AddConstraints

func (c *Chocolate) AddConstraints(constraints ...Constraint)

func (*Chocolate) AddModelBarModel

func (c *Chocolate) AddModelBarModel(model BarModel, name string, bar string, flavoured bool, styles ...FlavourStyleSelector)

func (*Chocolate) AddRootThemeModifier

func (c *Chocolate) AddRootThemeModifier(style FlavourStyleSelector, modifiers ...ThemeStyleModifier)

func (*Chocolate) AddStyledViewBarModel

func (c *Chocolate) AddStyledViewBarModel(model BarViewer, name string, bar string, style *lipgloss.Style)

func (*Chocolate) AddTeaModelBarModel

func (c *Chocolate) AddTeaModelBarModel(model tea.Model, name string, bar string, flavoured bool, styles ...FlavourStyleSelector)

func (*Chocolate) AddThemeModifier

func (c *Chocolate) AddThemeModifier(name string, model string, style FlavourStyleSelector, modifiers ...ThemeStyleModifier)

func (*Chocolate) AddViewBarModel

func (c *Chocolate) AddViewBarModel(model BarViewer, name string, bar string, flavoured bool, styles ...FlavourStyleSelector)

func (*Chocolate) FromFile

func (c *Chocolate) FromFile(file string) error

func (*Chocolate) FromJson

func (c *Chocolate) FromJson(layout []byte) error

func (*Chocolate) Hide

func (c *Chocolate) Hide(bar string)

func (*Chocolate) IsBar

func (c *Chocolate) IsBar(bar string) bool

func (*Chocolate) IsHidden

func (c *Chocolate) IsHidden(bar string) bool

func (*Chocolate) MakeBar

func (c *Chocolate) MakeBar(name string, canhide bool) bool

func (*Chocolate) MakeChocolate

func (c *Chocolate) MakeChocolate(name string, bar string, flavoured bool, styles ...FlavourStyleSelector) *Chocolate

func (*Chocolate) MakeOverlay

func (c *Chocolate) MakeOverlay(
	name string,
	zindex int,
	width float64, height float64,
	flavoured bool,
	pos ...OverlayPosition,
) *Overlay

func (*Chocolate) MakeStyledText

func (c *Chocolate) MakeStyledText(name string, bar string, style *lipgloss.Style) *TextModel

func (*Chocolate) MakeText

func (c *Chocolate) MakeText(name string, bar string, flavoured bool, styles ...FlavourStyleSelector) *TextModel

func (*Chocolate) Resize

func (c *Chocolate) Resize(width, height int)

func (*Chocolate) SelectModel

func (c *Chocolate) SelectModel(name string, bar string)

func (*Chocolate) SelectRootStyle

func (c *Chocolate) SelectRootStyle(name FlavourStyleSelector)

func (*Chocolate) SelectStyle

func (c *Chocolate) SelectStyle(name FlavourStyleSelector, bar string)

func (*Chocolate) SetCanHide

func (c *Chocolate) SetCanHide(bar string, v bool)

func (*Chocolate) SetDefault

func (t *Chocolate) SetDefault(style *lipgloss.Style)

func (*Chocolate) SetStyle

func (t *Chocolate) SetStyle(selector FlavourStyleSelector, style *lipgloss.Style)

func (*Chocolate) Unhide

func (c *Chocolate) Unhide(bar string)

func (*Chocolate) View

func (c *Chocolate) View() string

type ChocolateOption

type ChocolateOption func(*Chocolate)

func WithFlavour

func WithFlavour(flavour *chocolateFlavour) ChocolateOption

type ChocolateThemeOption

type ChocolateThemeOption func(*chocolateFlavour)

func DefaultStyle

func DefaultStyle(style *lipgloss.Style) ChocolateThemeOption

func WithDefaults

func WithDefaults(s ...*lipgloss.Style) ChocolateThemeOption

type Constraint

type Constraint struct {
	Target          string              `json:"target"`
	Source          string              `json:"source"`
	TargetAttribute ConstraintAttribute `json:"target_attribute"`
	SourceAttribute ConstraintAttribute `json:"source_attribute"`
	Relation        ConstraintRelation  `json:"relation"`
	Constant        float64             `json:"constant"`
	Multiplier      float64             `json:"multiplier"`
	Strength        ConstraintStrength  `json:"strength"`
}

func NewConstraint

func NewConstraint() Constraint

func (*Constraint) UnmarshalJSON

func (c *Constraint) UnmarshalJSON(data []byte) error

func (Constraint) WithConstant

func (c Constraint) WithConstant(v float64) Constraint

func (Constraint) WithMultiplier

func (c Constraint) WithMultiplier(v float64) Constraint

func (Constraint) WithRelation

func (c Constraint) WithRelation(v ConstraintRelation) Constraint

func (Constraint) WithSource

func (c Constraint) WithSource(v string) Constraint

func (Constraint) WithSourceAttribute

func (c Constraint) WithSourceAttribute(v ConstraintAttribute) Constraint

func (Constraint) WithStrength

func (c Constraint) WithStrength(v ConstraintStrength) Constraint

func (Constraint) WithTarget

func (c Constraint) WithTarget(v string) Constraint

func (Constraint) WithTargetAttribute

func (c Constraint) WithTargetAttribute(v ConstraintAttribute) Constraint

type ConstraintAttribute

type ConstraintAttribute uint8
const (
	WIDTH ConstraintAttribute = iota
	HEIGHT
	XSTART
	YSTART
	XEND
	YEND
)

func (*ConstraintAttribute) UnmarshalJSON

func (ca *ConstraintAttribute) UnmarshalJSON(data []byte) error

type ConstraintRelation

type ConstraintRelation uint8

func (*ConstraintRelation) UnmarshalJSON

func (cr *ConstraintRelation) UnmarshalJSON(data []byte) error

type ConstraintStrength

type ConstraintStrength float64

func (*ConstraintStrength) UnmarshalJSON

func (cs *ConstraintStrength) UnmarshalJSON(data []byte) error

type FlavourStyleSelector

type FlavourStyleSelector string
const (
	TS_DEFAULT  FlavourStyleSelector = "default"
	TS_SELECTED FlavourStyleSelector = "selected"
	TS_FOCUSED  FlavourStyleSelector = "focused"
)

type KeyMap

type KeyMap struct {
	// Keybindings used when selecting models.
	Next   key.Binding
	Prev   key.Binding
	Select key.Binding
	Leave  key.Binding

	// Quitting
	Quit key.Binding

	// Help toggle keybindings.
	ShowFullHelp  key.Binding
	CloseFullHelp key.Binding
}

KeyMap defines keybindings. It satisfies to the help.KeyMap interface, which is used to render the menu.

func DefaultKeyMap

func DefaultKeyMap() *KeyMap

DefaultKeyMap returns a default set of keybindings.

type Overlay

type Overlay struct {
	Chocolate
	// contains filtered or unexported fields
}

func (*Overlay) Disable

func (o *Overlay) Disable()

func (*Overlay) Enable

func (o *Overlay) Enable()

func (*Overlay) Resize

func (o *Overlay) Resize(width, height int)

func (*Overlay) SetDefault

func (t *Overlay) SetDefault(style *lipgloss.Style)

func (*Overlay) SetPosition

func (o *Overlay) SetPosition(pos ...OverlayPosition)

func (*Overlay) SetStyle

func (t *Overlay) SetStyle(selector FlavourStyleSelector, style *lipgloss.Style)

func (*Overlay) SetZIndex

func (o *Overlay) SetZIndex(v int)

type OverlayPosition

type OverlayPosition int
const (
	CENTER OverlayPosition = iota
	START
	END
)

type TextModel

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

func (*TextModel) SetText

func (tm *TextModel) SetText(v string)

type ThemeStyleModifier

type ThemeStyleModifier func(lipgloss.Style) lipgloss.Style

func Align

func AlignHorizontal

func AlignHorizontal(p lipgloss.Position) ThemeStyleModifier

func AlignVertical

func AlignVertical(p lipgloss.Position) ThemeStyleModifier
func Blink(v bool) ThemeStyleModifier

func Border

func Border(b lipgloss.Border, sides ...bool) ThemeStyleModifier

func BorderBackground

func BorderBackground(c ...lipgloss.TerminalColor) ThemeStyleModifier

func BorderBottom

func BorderBottom(v bool) ThemeStyleModifier

func BorderBottomBackground

func BorderBottomBackground(c lipgloss.TerminalColor) ThemeStyleModifier

func BorderBottomForeground

func BorderBottomForeground(c lipgloss.TerminalColor) ThemeStyleModifier

func BorderForeground

func BorderForeground(c ...lipgloss.TerminalColor) ThemeStyleModifier

func BorderLeft

func BorderLeft(v bool) ThemeStyleModifier

func BorderRight

func BorderRight(v bool) ThemeStyleModifier

func BorderStyle

func BorderStyle(b lipgloss.Border) ThemeStyleModifier

func BorderTop

func BorderTop(v bool) ThemeStyleModifier

func Faint

func Faint(v bool) ThemeStyleModifier

func Italic

func Italic(v bool) ThemeStyleModifier

func Margin

func Margin(i ...int) ThemeStyleModifier

func MarginBottom

func MarginBottom(i int) ThemeStyleModifier

func MarginLeft

func MarginLeft(i int) ThemeStyleModifier

func MarginRight

func MarginRight(i int) ThemeStyleModifier

func MarginTop

func MarginTop(i int) ThemeStyleModifier

func Padding

func Padding(i ...int) ThemeStyleModifier

func PaddingBottom

func PaddingBottom(i int) ThemeStyleModifier

func PaddingLeft

func PaddingLeft(i int) ThemeStyleModifier

func PaddingRight

func PaddingRight(i int) ThemeStyleModifier

func PaddingTor

func PaddingTor(i int) ThemeStyleModifier

func Reverse

func Reverse(v bool) ThemeStyleModifier

Directories

Path Synopsis
examples
menu_with_main command

Jump to

Keyboard shortcuts

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