api-details.md

  1# Lip Gloss v2 API Details
  2
  3## Style Getters
  4
  5```go
  6s.GetBold()               // bool
  7s.GetItalic()             // bool
  8s.GetUnderline()          // bool
  9s.GetUnderlineStyle()     // Underline
 10s.GetUnderlineColor()     // color.Color
 11s.GetStrikethrough()      // bool
 12s.GetReverse()            // bool
 13s.GetBlink()              // bool
 14s.GetFaint()              // bool
 15s.GetForeground()         // color.Color
 16s.GetBackground()         // color.Color
 17s.GetWidth()              // int
 18s.GetHeight()             // int
 19s.GetAlign()              // Position (horizontal)
 20s.GetAlignHorizontal()    // Position
 21s.GetAlignVertical()      // Position
 22s.GetPadding()            // top, right, bottom, left int
 23s.GetPaddingTop()         // int
 24s.GetPaddingRight()       // int
 25s.GetPaddingBottom()      // int
 26s.GetPaddingLeft()        // int
 27s.GetHorizontalPadding()  // int (left + right)
 28s.GetVerticalPadding()    // int (top + bottom)
 29s.GetMargin()             // top, right, bottom, left int
 30s.GetMarginTop()          // int
 31s.GetMarginRight()        // int
 32s.GetMarginBottom()       // int
 33s.GetMarginLeft()         // int
 34s.GetHorizontalMargins()  // int (left + right)
 35s.GetVerticalMargins()    // int (top + bottom)
 36s.GetBorderStyle()        // Border
 37s.GetBorderTop()          // bool
 38s.GetBorderRight()        // bool
 39s.GetBorderBottom()       // bool
 40s.GetBorderLeft()         // bool
 41s.GetHorizontalBorderSize() // int
 42s.GetVerticalBorderSize()   // int
 43s.GetHorizontalFrameSize()  // int (border + margin + padding)
 44s.GetVerticalFrameSize()    // int (border + margin + padding)
 45s.GetMaxWidth()           // int
 46s.GetMaxHeight()          // int
 47s.GetTabWidth()           // int
 48s.GetHyperlink()          // link, params string
 49```
 50
 51## All Unset Methods
 52
 53Every setter has a corresponding `Unset*` method:
 54`UnsetBold`, `UnsetItalic`, `UnsetUnderline`, `UnsetUnderlineStyle`, `UnsetUnderlineColor`,
 55`UnsetStrikethrough`, `UnsetReverse`, `UnsetBlink`, `UnsetFaint`,
 56`UnsetForeground`, `UnsetBackground`, `UnsetWidth`, `UnsetHeight`,
 57`UnsetAlign`, `UnsetAlignHorizontal`, `UnsetAlignVertical`,
 58`UnsetPadding`, `UnsetPaddingTop`, `UnsetPaddingRight`, `UnsetPaddingBottom`, `UnsetPaddingLeft`,
 59`UnsetMargin`, `UnsetMarginTop`, `UnsetMarginRight`, `UnsetMarginBottom`, `UnsetMarginLeft`,
 60`UnsetMarginBackground`, `UnsetBorderStyle`, `UnsetBorderTop`, `UnsetBorderRight`,
 61`UnsetBorderBottom`, `UnsetBorderLeft`, `UnsetBorderForeground`, `UnsetBorderBackground`,
 62`UnsetMaxWidth`, `UnsetMaxHeight`, `UnsetTabWidth`, `UnsetInline`
 63
 64## Border Struct Fields
 65
 66```go
 67type Border struct {
 68    Top, Bottom, Left, Right          string
 69    TopLeft, TopRight                 string
 70    BottomLeft, BottomRight           string
 71    MiddleLeft, MiddleRight           string  // used by tables for row separators
 72    Middle                            string  // used by tables for intersections
 73    MiddleTop, MiddleBottom           string  // used by tables for column header joins
 74}
 75```
 76
 77## Table Data Interface
 78
 79```go
 80type Data interface {
 81    At(row, cell int) string
 82    Rows() int
 83    Columns() int
 84}
 85```
 86
 87Built-in implementations:
 88- `table.NewStringData(rows ...[]string)` - basic string data
 89- `table.NewFilter(data).Filter(func(row int) bool)` - filtered view
 90
 91## Tree Node Interface
 92
 93```go
 94type Node interface {
 95    fmt.Stringer
 96    Value() string
 97    Children() Children
 98    Hidden() bool
 99    SetHidden(bool)
100    SetValue(any)
101}
102```
103
104Types: `*tree.Tree` (has children), `*tree.Leaf` (no children)
105
106## Color Types
107
108```go
109// Function - parse string to color
110func Color(s string) color.Color
111
112// Struct types
113type NoColor struct{}                      // absence of color
114type RGBColor struct{ R, G, B uint8 }      // RGB values
115type ANSIColor = ansi.IndexedColor         // ANSI 256 by number
116
117// Named ANSI 16 constants (type ansi.BasicColor)
118Black, Red, Green, Yellow, Blue, Magenta, Cyan, White
119BrightBlack, BrightRed, BrightGreen, BrightYellow,
120BrightBlue, BrightMagenta, BrightCyan, BrightWhite
121
122// Utility functions
123func Darken(c color.Color, percent float64) color.Color
124func Lighten(c color.Color, percent float64) color.Color
125func Complementary(c color.Color) color.Color
126func Alpha(c color.Color, alpha float64) color.Color
127func Blend1D(steps int, stops ...color.Color) []color.Color
128func Blend2D(width, height int, angle float64, stops ...color.Color) []color.Color
129
130// Adaptive color helpers
131func HasDarkBackground(in *os.File, out *os.File) bool
132func LightDark(isDark bool) LightDarkFunc  // returns func(light, dark color.Color) color.Color
133func Complete(p colorprofile.Profile) CompleteFunc  // returns func(ansi, ansi256, truecolor color.Color) color.Color
134```
135
136## Writer Functions
137
138All auto-downsample colors for the terminal's capability:
139
140```go
141var Writer = colorprofile.NewWriter(os.Stdout, os.Environ())
142
143func Print(v ...any) (int, error)
144func Println(v ...any) (int, error)
145func Printf(format string, v ...any) (int, error)
146func Fprint(w io.Writer, v ...any) (int, error)
147func Fprintln(w io.Writer, v ...any) (int, error)
148func Fprintf(w io.Writer, format string, v ...any) (int, error)
149func Sprint(v ...any) string
150func Sprintln(v ...any) string
151func Sprintf(format string, v ...any) string
152```
153
154## Whitespace Options
155
156Used with `Place`, `PlaceHorizontal`, `PlaceVertical`:
157
158```go
159lipgloss.WithWhitespaceStyle(lipgloss.NewStyle().Background(c))
160lipgloss.WithWhitespaceChars(".")
161```
162
163## List Enumerators
164
165```go
166list.Bullet    // "." (default)
167list.Arabic    // "1.", "2.", "3."
168list.Alphabet  // "A.", "B.", "C."
169list.Roman     // "I.", "II.", "III."
170list.Dash      // "-"
171list.Asterisk  // "*"
172
173// Custom: func(items list.Items, index int) string
174```
175
176## Tree Enumerators
177
178```go
179tree.DefaultEnumerator  // ├── and └──
180tree.RoundedEnumerator  // ├── and ╰──
181
182// Custom: func(children tree.Children, index int) string
183```