### Create LightDarkFunc Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Example of creating and using a LightDarkFunc to choose a color based on terminal background. This is useful for dynamic color selection. ```go lightDark := lipgloss.LightDark(hasDarkBackground) red, blue := lipgloss.Color("#ff0000"), lipgloss.Color("#0000ff") myHotColor := lightDark(red, blue) ``` -------------------------------- ### Example Usage of NoColor Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Demonstrates how to apply NoColor to a style's background. ```go var style = someStyle.Background(lipgloss.NoColor{}) ``` -------------------------------- ### Render ASCII Table Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 An example of a rendered table with an ASCII border, displaying language names and their formal and informal greetings. ```text +----------+--------------+-----------+ | LANGUAGE | FORMAL | INFORMAL | +----------+--------------+-----------+ | Chinese | Nǐn hǎo | Nǐ hǎo | | French | Bonjour | Salut | | Russian | Zdravstvuyte | Privet | | Spanish | Hola | ¿Qué tal? | +----------+--------------+-----------+ ``` -------------------------------- ### Example ANSIColor Usage Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Demonstrates how to create ANSIColor values using the lipgloss.ANSIColor constructor. ```go colorA := lipgloss.ANSIColor(8) colorB := lipgloss.ANSIColor(134) ``` -------------------------------- ### Dash Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Demonstrates the dash enumeration style for lists. ```go func Dash(Items, int) string ``` -------------------------------- ### Asterisk Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Demonstrates the asterisk enumeration style for lists. ```go func Asterisk(Items, int) string ``` -------------------------------- ### Render Markdown Table Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 An example of a rendered table with a Markdown border, showcasing language names and their formal and informal greetings. ```text | LANGUAGE | FORMAL | INFORMAL | |----------|--------------|-----------| | Chinese | Nǐn hǎo | Nǐ hǎo | | French | Bonjour | Salut | | Russian | Zdravstvuyte | Privet | | Spanish | Hola | ¿Qué tal? | ``` -------------------------------- ### Alphabet Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Demonstrates the alphabetical enumeration style for lists. ```go func Alphabet(_ Items, i int) string ``` -------------------------------- ### Initialize Lip Gloss Table Rendering Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Import the `table` sub-package to start rendering tables. Define rows of string data that will be used to populate the table. ```go import "github.com/charmbracelet/lipgloss/table" rows := [][]string{ {"Chinese", "您好", "你好"}, {"Japanese", "こんにちは", "やあ"}, {"Arabic", "أهلين", "أهلا"}, {"Russian", "Здравствуйте", "Привет"}, {"Spanish", "Hola", "¿Qué tal?"}, } ``` -------------------------------- ### Arabic Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Demonstrates the Arabic numeral enumeration style for lists. ```go func Arabic(_ Items, i int) string { return fmt.Sprintf("%d.", i+1) } ``` -------------------------------- ### Arabic Numerals Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Shows the format for listing with Arabic numerals. ```go func Arabic(_ Items, i int) string { return "1." } ``` -------------------------------- ### Bullet Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Demonstrates the bullet point enumeration style for lists. ```go func Bullet(Items, int) string ``` -------------------------------- ### Build a Tree Structure with Lipgloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Demonstrates how to construct a tree with nested children and various file/directory names using the tree package. This example showcases the basic API for adding nodes and sub-nodes. ```go t := tree.New(). Child( ".git", tree.Root("examples/"). Child( tree.Root("list/"). Child("main.go"). tree.Root("table/"). Child("main.go"). ) tree.Root("list/"). Child("list.go", "list_test.go"). tree.New(). Root("table/"). Child("table.go", "table_test.go"). "align.go", "align_test.go", "join.go", "join_test.go", ) ``` -------------------------------- ### Roman Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Demonstrates the Roman numeral enumeration style for lists. ```go func Roman(_ Items, i int) string ``` -------------------------------- ### Get Layer Content Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Content returns the content of the Layer. ```go func (l *Layer) Content() string ``` -------------------------------- ### New Table Initialization Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/table Create a new Table instance. By default, tables have normal borders, no styling, and no rows. Use this as a starting point for building your table. ```go func New() *Table ``` -------------------------------- ### Alphabetical Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Illustrates the format for alphabetical listing using the Alphabet enumerator. ```go func Alphabet(_ Items, i int) string { return "a. " } ``` -------------------------------- ### Create a New Empty Tree Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/tree Initializes a new, empty Tree. This is the starting point for building a tree structure. ```go func New() *Tree ``` -------------------------------- ### Basic Rendering with Lip Gloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Render styled strings using the `Render` method. This example shows basic text styling with bold and concatenating rendered strings. ```go style := lipgloss.NewStyle().Bold(true).SetString("Hello,") fmt.Println(style.Render("kitty.")) // Hello, kitty. fmt.Println(style.Render("puppy.")) // Hello, puppy. ``` -------------------------------- ### Table Output Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Demonstrates the visual output of the Lip Gloss table component with different content and wrapping behaviors. ```text ╭──────────────┬───────────────┬───────────────┬───────────────┬───────────────╮ │ Hello │ 你好 │ مرحبًا │ 안녕하세요 │ │ ├──────────────┼───────────────┼───────────────┼───────────────┼───────────────┤ │ Lorem ipsum… │ 耐許ヱヨカハ… │ شيء قد للحكو… │ 版応道潟部中… │ 각급 선거관… │ ╰──────────────┴───────────────┴───────────────┴───────────────┴───────────────╯ ╭──────────────┬───────────────┬───────────────┬───────────────┬───────────────╮ │ Hello │ 你好 │ مرحبًا │ 안녕하세요 │ │ ├──────────────┼───────────────┼───────────────┼───────────────┼───────────────┤ │ Lorem ipsum │ 耐許ヱヨカハ │ شيء قد │ 版応道潟部中 │ 각급 │ │ dolor sit │ 調出あゆ監件 │ للحكومة │ 幕爆営報門案 │ 선거관리위원 │ │ amet, │ び理別よン國 │ والكوري │ 名見壌府。博 │ 회의 │ │ regione │ 給災レホチ権 │ الأوروبيّون, │ 健必権次覧編 │ 조직·직무범위 │ │ detracto eos │ 輝モエフ会割 │ بوابة تعديل │ 仕断青場内凄 │ 기타 필요한 │ │ an. Has ei │ もフ響3現エツ │ واعتلاء ضرب │ 新東深簿代供 │ 사항은 법률로 │ │ quidam │ 文時しだびほ │ بـ. إذ أسر │ 供。守聞書神 │ 정한다. │ │ hendrerit │ 経機ムイメフ │ اتّجة اعلان, │ 秀同浜東波恋 │ 임시회의 │ │ intellegebat │ 敗文ヨク現義 │ ٣٠ اكتوبر │ 闘秀。未格打 │ 회기는 30일을 │ │ , id tamquam │ なさド請情ゆ │ العصبة │ 好作器来利阪 │ 초과할 수 │ │ iudicabit │ 州けでふく。 │ استمرار ومن. │ 持西焦朝三女 │ 없다. 국가는 │ │ necessitatib │ 排ゃわつげ美 │ أفاق للسيطرة │ 娘購合旧資健 │ 여자의 복지와 │ │ us ius, at │ 刊ヱミ出見ツ │ التاريخ، مع │ 載員式活陸。 │ 권익의 향상을 │ │ errem │ 南者オ抜豆ハ │ بحث, كلّ اتّجة │ 術吉迎暮広知 │ 위하여 │ │ officiis │ トロネ論索モ │ تم حتى, لكل │ 角亡志不説空 │ 노력하여야 │ │ hendrerit │ ネニイ任償ス │ تم جسيمة │ 住。法省当死 │ 한다. 국군의 │ │ mei. Exerci │ ヲ話破リヤヨ │ الإحتفاظ │ 年勝絡聞方北 │ 조직과 편성은 │ │ noster at │ 秒止口イセソ │ وباستثناء, عل │ 投健。室分性 │ 법률로 │ │ has, sit id │ ス止央のさ食 │ فرنسا وانتهاءً │ 山天態意画詳 │ 정한다. │ │ tota │ 周健でてつだ │ الإقتصادية │ 知浅方裁。変 │ │ │ convenire, │ 官送ト読聴遊 │ عرض. ونتج │ 激伝阜中野品 │ │ │ vel ex rebum │ 容ひるべ。際 │ دأبوا إحكام │ 省載嗅闘額端 │ │ │ inciderint │ ぐドらづ市居 │ بال إذ. لغات │ 反。中必台際 │ │ │ liberavisse. │ ネムヤ研校35 │ عملية وتم مع, │ 造事寄民経能 │ │ │ Quaeque │ 岩6繹ごわク報 │ وصل بداية │ 前作臓 │ │ │ delectus │ 拐イ革深52球 │ وبغطاء البرية │ │ │ │ corrumpit cu │ ゃレスご究東 │ بل, أي قررت │ │ │ │ cum. │ スラ衝3間ラ録 │ بلاده فكانت │ │ │ │ │ 占たス。 │ حدى │ │ │ │ │ 禁にンご忘康 │ │ │ │ │ │ ざほぎル騰般 │ │ │ │ │ │ ねど事超スん │ │ │ │ │ │ いう真表何カ │ │ │ │ │ │ モ自浩ヲシミ │ │ │ │ │ │ 図客線るふ静 │ │ │ │ │ │ 王ぱーま写村 │ │ │ │ │ │ 月掛焼詐面ぞ │ │ │ │ │ │ ゃ。昇強ごン │ │ │ │ │ │ トほ価保キ族8 │ │ │ │ │ │ 5岡モテ恋困ひ │ │ │ │ │ │ りこな刊並せ │ │ │ │ │ │ ご出来ぼぎむ │ │ │ │ │ │ う点目ヲウ止 │ │ │ │ │ │ 環公ニレ事応 │ │ │ │ │ │ タス必書タメ │ │ │ │ │ │ ムノ当84無信 │ │ │ │ │ │ 升ちひょ。価 │ │ │ │ │ │ ーぐ中客テサ │ │ │ │ │ │ 告覧ヨトハ極 │ │ │ │ │ │ 整ラ得95稿は │ │ │ │ ``` -------------------------------- ### Build a Tree Structure Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/tree Constructs a tree with nested directories and files using the tree package. This example demonstrates defining root nodes and children recursively. ```go t := tree.New(). Child( ".git", tree.Root("examples/"). Child( tree.Root("list/"). Child("main.go"). tree.Root("table/"). Child("main.go"). ). tree.Root("list/"). Child("list.go", "list_test.go"). tree.New(). Root("table/"). Child("table.go", "table_test.go"). "align.go", "align_test.go", "join.go", "join_test.go", ) ``` -------------------------------- ### Roman Numerals Enumerator Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Demonstrates list items enumerated with Roman numerals. ```go func Roman(_ Items, i int) string { return "I." } ``` -------------------------------- ### Example ANSIColor Usage Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Demonstrates equivalent ways to define an ANSI color using either the `ANSIColor` type or the `Color` function. ```go // These two statements are equivalent. colorA := lipgloss.ANSIColor(21) colorB := lipgloss.Color("21") ``` -------------------------------- ### List Enumerators Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Provides examples of predefined enumerator functions for different list styles. ```APIDOC ## Enumerator Functions ### Description Predefined functions to format list item enumeration. ### Alphabet ```go func Alphabet(_ Items, i int) string ``` Example: ``` a. Foo b. Bar c. Baz d. Qux. ``` ### Arabic ```go func Arabic(_ Items, i int) string ``` Example: ``` 1. Foo 2. Bar 3. Baz 4. Qux. ``` ### Asterisk ```go func Asterisk(Items, int) string ``` Example: ``` * Foo * Bar * Baz * Qux. ``` ### Bullet ```go func Bullet(Items, int) string ``` Example: ``` • Foo • Bar • Baz • Qux. ``` ### Dash ```go func Dash(Items, int) string ``` Example: ``` - Foo - Bar - Baz - Qux. ``` ### Roman ```go func Roman(_ Items, i int) string ``` Example: ``` I. Foo II. Bar III. Baz IV. Qux. ``` ``` -------------------------------- ### Create a New Tree with a Root Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/tree Initializes a new Tree with a specified root value. This is a convenient way to start a tree with a single top-level node. ```go func Root(root any) *Tree ``` -------------------------------- ### Parse Color String Example Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Demonstrates parsing different color formats including ANSI, ANSI256, and hex. Use this to convert string representations into usable color.Color types. ```go ansiColor := lipgloss.Color("1") // The same as lipgloss.Red ansi256Color := lipgloss.Color("21") hexColor := lipgloss.Color("#0000ff") ``` -------------------------------- ### Get Layer by ID Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Get returns the Layer with the given ID. If the ID is not found, it returns nil. ```go func (l *Layer) Get(id string) *Layer ``` -------------------------------- ### Create List with Items Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Demonstrates creating a new list and initializing it with several items. The 'list' package must be imported. ```go alphabet := list.New( "A", "B", "C", "D", "E", "F", ... ) ``` -------------------------------- ### Get Height Setting Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the height setting for the style. Returns 0 if no height is set. ```go func (s Style) GetHeight() int ``` -------------------------------- ### Get Layer from Canvas Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Get returns the Layer with the given ID. If the ID is not found, nil is returned. ```go func (c *Canvas) Get(id string) *Layer ``` -------------------------------- ### Example Usage of AdaptiveColor Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/compat Instantiate an AdaptiveColor with specific hex color codes for light and dark backgrounds. This demonstrates how to define adaptive colors for use with Lip Gloss. ```go color := lipgloss.AdaptiveColor{Light: "#0000ff", Dark: "#000099"} ``` -------------------------------- ### List Creation and Basic Usage Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Demonstrates how to create a new list with initial items and print it to the console. ```APIDOC ## List.New ### Description Creates a new list with the provided items. ### Method `list.New(items ...any) *List` ### Parameters - `items` (...any) - The items to include in the list. Can be of any type, including other lists. ### Request Example ```go groceries := list.New( "Bananas", "Barley", "Cashews", "Milk", list.New( "Almond Milk" "Coconut Milk" "Full Fat Milk" ) "Eggs", "Fish Cake", "Leeks", "Papaya", ) fmt.Println(groceries) ``` ``` -------------------------------- ### Create a New Lip Gloss List Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Initialize a new list with basic string items. ```go l := list.New("A", "B", "C") ``` -------------------------------- ### Create and Print a List Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/list Demonstrates creating a list with nested sublists and printing its string representation. Ensure the 'list' and 'fmt' packages are imported. ```go groceries := list.New( "Bananas", "Barley", "Cashews", "Milk", list.New( "Almond Milk" "Coconut Milk" "Full Fat Milk" ) "Eggs", "Fish Cake", "Leeks", "Papaya", ) fmt.Println(groceries) ``` -------------------------------- ### Get Layer Z-index Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 GetZ returns the z-index of the Layer. ```go func (l *Layer) GetZ() int ``` -------------------------------- ### Get Layer Y-coordinate Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 GetY returns the y-coordinate of the Layer. ```go func (l *Layer) GetY() int ``` -------------------------------- ### Define True Color Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Examples of defining colors using the True Color (24-bit) profile. ```go lipgloss.Color("#0000FF") // good ol' 100% blue lipgloss.Color("#04B575") // a green lipgloss.Color("#3C3C3C") // a dark gray ``` -------------------------------- ### Define and Print a Simple List Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Create a new list with basic string items and print it to the console. ```go l := list.New("A", "B", "C") fmt.Println(l) // • A // • B // • C ``` -------------------------------- ### Get Layer X-coordinate Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 GetX returns the x-coordinate of the Layer. ```go func (l *Layer) GetX() int ``` -------------------------------- ### Get Frame Size Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Calculates the total horizontal and vertical space occupied by margins, padding, and borders. ```go func (s Style) GetFrameSize() (x, y int) ``` -------------------------------- ### Configure and Render a Table Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Create a new table instance, set its border, style function, headers, and rows. The `StyleFunc` allows custom styling for different rows and columns. ```go t := table.New(). Border(lipgloss.NormalBorder()). BorderStyle(lipgloss.NewStyle().Foreground(purple)). StyleFunc(func(row, col int) lipgloss.Style { switch { case row == table.HeaderRow: return headerStyle case row%2 == 0: return evenRowStyle default: return oddRowStyle } }). Headers("LANGUAGE", "FORMAL", "INFORMAL"). Rows(rows...) // You can also add tables row-by-row t.Row("English", "You look absolutely fabulous.", "How's it going?") fmt.Println(t) ``` -------------------------------- ### Get Layer Width Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 GetWidth returns the width of the Layer. ```go func (l *Layer) GetWidth() int ``` -------------------------------- ### Get Default Renderer Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Returns the default lipgloss terminal renderer. This is typically used to initialize rendering capabilities. ```go func DefaultRenderer() *Renderer ``` -------------------------------- ### Set os.Stderr as Default Writer Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/compat Configure the impure writer and dark background detection to use os.Stderr. This setup is useful when you need to explicitly direct Lip Gloss output to the standard error stream. ```go import ( "os" "github.com/charmbracelet/colorprofile" "github.com/charmbracelet/lipgloss/v2/impure" ) func init() { impure.Writer = colorprofile.NewWriter(os.Stderr, os.Environ()) impure.HasDarkBackground, _ = lipgloss.HasDarkBackground(os.Stdin, os.Stderr) } ``` -------------------------------- ### Get Layer ID Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 GetID returns the ID of the Layer. ```go func (l *Layer) GetID() string ``` -------------------------------- ### Create and Render a Basic Style Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Defines a style with bold text, custom foreground and background colors, and padding, then renders it. ```go import "github.com/charmbracelet/lipgloss" var style = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FAFAFA")), Background(lipgloss.Color("#7D56F4")), PaddingTop(2). PaddingLeft(4). Width(22) fmt.Println(style.Render("Hello, kitty")) ``` -------------------------------- ### Get Layer Height Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 GetHeight returns the height of the Layer. ```go func (l *Layer) GetHeight() int ``` -------------------------------- ### Initialize a New Filter Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Initializes a new Filter with the provided children data. Use this to start filtering operations on a tree structure. ```go func NewFilter(data Children) *Filter ``` -------------------------------- ### Create New Range Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Constructs a Range object, which defines a start and end index along with a Style, for use with StyleRanges. ```go func NewRange(start, end int, style Style) Range ``` -------------------------------- ### Initialize Table Rendering Package Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Import the table sub-package to enable table rendering functionality. This is a prerequisite for creating and styling tables. ```go import "github.com/charmbracelet/lipgloss/table" ``` -------------------------------- ### Get Layer Bounds Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Bounds returns the bounds of the Layer. ```go func (l *Layer) Bounds() image.Rectangle ``` -------------------------------- ### Get Canvas Bounds Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Bounds returns the bounds of the Canvas. ```go func (c *Canvas) Bounds() image.Rectangle ``` -------------------------------- ### Import Lip Gloss Tree Package Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Import the necessary tree sub-package from Lip Gloss. ```go import "github.com/charmbracelet/lipgloss/tree" ``` -------------------------------- ### Get Node Value Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Retrieves the value associated with this node. ```go func (l *List) Value() string ``` -------------------------------- ### Create a New List Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Initializes a new list with provided items. Items can include other lists, trees, tables, or any renderable content. ```go groceries := list.New( "Bananas", "Barley", "Cashews", "Milk", list.New( "Almond Milk" "Coconut Milk" "Full Fat Milk" ) "Eggs", "Fish Cake", "Leeks", "Papaya", ) fmt.Println(groceries) ``` ```go alphabet := list.New( "A", "B", "C", "D", "E", "F", ... ) ``` -------------------------------- ### Offset Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Sets the starting and ending offsets for the Tree children. ```APIDOC ## Offset ### Description Offset sets the Tree children offsets. ### Method func (*Tree) Offset(start, end int) *Tree ``` -------------------------------- ### Create and Render a Basic Style Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Defines a style with bold text, custom foreground and background colors, padding, and a fixed width, then renders it. ```go import "github.com/charmbracelet/lipgloss" var style = lipgloss.NewStyle(). Bold(true). Foreground(lipgloss.Color("#FAFAFA")), Background(lipgloss.Color("#7D56F4")), PaddingTop(2). PaddingLeft(4). Width(22) fmt.Println(style.Render("Hello, kitty")) ``` -------------------------------- ### Import Lip Gloss List Package Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Import the necessary list sub-package from Lip Gloss. ```go import "github.com/charmbracelet/lipgloss/list" ``` -------------------------------- ### Create a New Lip Gloss Tree Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Initialize a new tree structure with a root and child nodes. ```go t := tree.Root("."). Child("A", "B", "C") ``` -------------------------------- ### Get Rounded Border Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 RoundedBorder returns a Border struct with rounded corners. ```go func RoundedBorder() Border ``` -------------------------------- ### Get Border Setting (Right, Top) Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Checks if a specific border (right or top) is enabled. Returns false if no value is set. ```go func (s Style) GetBorderRight() bool ``` ```go func (s Style) GetBorderTop() bool ``` -------------------------------- ### Get Leaf Value Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Retrieves the value stored within a Leaf node. ```go func (s Leaf) Value() string ``` -------------------------------- ### Rendering Text with Lip Gloss Styles Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Demonstrates the primary method for rendering styled text using the `Render` method. It also shows how to use the `SetString` method and the `Stringer` interface for rendering. ```go style := lipgloss.NewStyle().Bold(true).SetString("Hello,") fmt.Println(style.Render("kitty.")) // Hello, kitty. fmt.Println(style.Render("puppy.")) // Hello, puppy. var style = lipgloss.NewStyle().SetString("你好,猫咪。").Bold(true) fmt.Println(style) // 你好,猫咪。 ``` -------------------------------- ### Configure and Style Lip Gloss Table Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Create a new table instance and configure its borders, styles, and header. A `StyleFunc` can be provided to apply different styles to rows and columns, including alternating row colors. ```go var ( purple = lipgloss.Color("99") gray = lipgloss.Color("245") lightGray = lipgloss.Color("241") headerStyle = lipgloss.NewStyle().Foreground(purple).Bold(true).Align(lipgloss.Center) cellStyle = lipgloss.NewStyle().Padding(0, 1).Width(14) oddRowStyle = cellStyle.Foreground(gray) evenRowStyle = cellStyle.Foreground(lightGray) ) t := table.New(). Border(lipgloss.NormalBorder()). BorderStyle(lipgloss.NewStyle().Foreground(purple)). StyleFunc(func(row, col int) lipgloss.Style { switch { case row == table.HeaderRow: return headerStyle case row%2 == 0: return evenRowStyle default: return oddRowStyle } }). Headers("LANGUAGE", "FORMAL", "INFORMAL"). Rows(rows...) // You can also add tables row-by-row t.Row("English", "You look absolutely fabulous.", "How's it going?") ``` -------------------------------- ### Define and Print a Simple Tree Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Create a new tree with root and child nodes and print it. ```go t := tree.Root("."). Child("A", "B", "C") fmt.Println(t) // . // ├── A // ├── B // └── C ``` -------------------------------- ### Set All Margins - Style.Margin Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss A shorthand method for setting margins on all sides at once. The number of arguments determines how margins are applied: one for all sides, two for vertical/horizontal, three for top/horizontal/bottom, and four for clockwise starting from the top. More than four arguments result in no margin being added. ```go func (s Style) Margin(i ...int) Style ``` -------------------------------- ### Offset Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/list Sets the start and end offset for the list, determining which items are displayed. ```APIDOC ## Offset ### Description Offset sets the start and end offset for the list. ### Method func (*List) Offset(start, end int) *List ### Example ``` Example: l := list.New("A", "B", "C", "D"). Offset(1, -1) fmt.Println(l) • B • C • D ``` ``` -------------------------------- ### Get Renderer Output Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Returns the underlying termenv output object associated with the renderer. ```go func (r *Renderer) Output() *termenv.Output ``` -------------------------------- ### Print a Lip Gloss Tree Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Display the formatted tree structure to the console. ```go fmt.Println(t) ``` -------------------------------- ### Get Terminal Color Profile Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss ColorProfile returns the detected termenv color profile. ```go func ColorProfile() termenv.Profile ``` -------------------------------- ### Table String Method Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Returns the table as a string. This is the primary method for rendering the table. ```go func (t *Table) String() string ``` -------------------------------- ### Get Length of NodeChildren Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Returns the total number of child nodes in a NodeChildren slice. ```go func (n NodeChildren) Length() int ``` -------------------------------- ### Get Root Value of Tree Node Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/tree Value returns the root name of this node. ```go func (t *Tree) Value() string ``` -------------------------------- ### Get String Representation of Tree Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/tree String returns the string representation of the Tree node. ```go func (t *Tree) String() string ``` -------------------------------- ### Print Lip Gloss Table Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Render the configured table to standard output using `fmt.Println`. ```go fmt.Println(t) ``` -------------------------------- ### Get Number of Columns in StringData Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Returns the total number of columns present in the `StringData`. ```go func (m *StringData) Columns() int ``` -------------------------------- ### Get Border Bottom Status Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/table Check if the bottom border is currently enabled for the table. ```go func (t *Table) GetBorderBottom() bool ``` -------------------------------- ### Create New Renderer Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Creates a new lipgloss renderer. The writer determines the terminal's color capabilities. Options can be provided to customize output. ```go func NewRenderer(w io.Writer, opts ...termenv.OutputOption) *Renderer ``` -------------------------------- ### Set Table Rendering Offset Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Adjusts the starting row for rendering the table. This is useful for pagination or displaying specific sections of large tables. Note: This must be set after `Rows` for it to take effect. ```go func (t *Table) Offset(o int) *Table ``` -------------------------------- ### Create New Style Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Returns a new, empty Style. Recommended for creating styles to allow for future implementation changes. ```go func NewStyle() Style ``` -------------------------------- ### Get Thick Border Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 ThickBorder returns a Border struct with thicker lines compared to NormalBorder. ```go func ThickBorder() Border ``` -------------------------------- ### Get Normal Border Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 NormalBorder returns a Border struct with standard weight and 90-degree corners. ```go func NormalBorder() Border ``` -------------------------------- ### Get Italic Setting Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the italic setting for the style. Returns false if no value is set. ```go func (s Style) GetItalic() bool ``` -------------------------------- ### Get Inline Setting Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Checks if the style is set to inline. Returns false if no value is set. ```go func (s Style) GetInline() bool ``` -------------------------------- ### Create New Style Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Initializes a new, empty Style object. It's recommended to use this over direct struct initialization for future compatibility. ```go func (r *Renderer) NewStyle() Style ``` -------------------------------- ### Get Foreground Color Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the foreground color of the style. Returns NoColor{} if no value is set. ```go func (s Style) GetForeground() TerminalColor ``` -------------------------------- ### Render Styled String Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Render applies the defined style formatting to a given string. ```go func (s Style) Render(strs ...string) string ``` -------------------------------- ### Get Faint Setting Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the faint setting for the style. Returns false if no value is set. ```go func (s Style) GetFaint() bool ``` -------------------------------- ### Get Border Style Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the border style type. Returns Border{} if no value is set. ```go func (s Style) GetBorderStyle() Border ``` -------------------------------- ### Set Bold Formatting Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Sets a bold formatting rule for the style. ```go func (s Style) Bold(v bool) Style ``` -------------------------------- ### Get Leaf String Representation Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Returns the string representation of a Leaf node, typically its value. ```go func (s Leaf) String() string ``` -------------------------------- ### CompleteFunc and Complete Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Functions for color completion based on profiles. ```APIDOC ## CompleteFunc CompleteFunc is a function that returns the appropriate color based on the given color profile. ### Example usage ```go p := colorprofile.Detect(os.Stderr, os.Environ()) complete := lipgloss.Complete(p) color := complete( lipgloss.Color(1), // ANSI lipgloss.Color(124), // ANSI256 lipgloss.Color("#ff34ac"), // TrueColor ) fmt.Println("Ooh, pretty color: ", color) ``` ## Complete ### Description Complete returns a function that will return the appropriate color based on the given color profile. ### Method func Complete(p colorprofile.Profile) CompleteFunc ### Example usage ```go p := colorprofile.Detect(os.Stderr, os.Environ()) complete := lipgloss.Complete(p) color := complete( lipgloss.Color(1), // ANSI lipgloss.Color(124), // ANSI256 lipgloss.Color("#ff34ac"), // TrueColor ) fmt.Println("Ooh, pretty color: ", color) ``` ``` -------------------------------- ### Get Number of Rows from Filter Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Returns the total number of rows remaining after the filter has been applied. ```go func (m *Filter) Rows() int ``` -------------------------------- ### Print to Stdout with Lip Gloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Use Print to output formatted strings to stdout, with automatic color downsampling. ```go str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("Who wants marmalade?\n") Print(str) ``` -------------------------------- ### Get Number of Columns from Filter Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Returns the total number of columns available in the filtered data. ```go func (m *Filter) Columns() int ``` -------------------------------- ### Print a Lip Gloss List Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Print the string representation of a Lip Gloss list to the console. ```go fmt.Println(l) ``` -------------------------------- ### Inheriting Styles in Lip Gloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Demonstrates how styles can inherit rules from other styles. Only unset rules on the receiver are inherited, ensuring that explicitly set rules are preserved. ```go var styleA = lipgloss.NewStyle(). Foreground(lipgloss.Color("229")), Background(lipgloss.Color("63")) // Only the background color will be inherited here, because the foreground // color will have been already set: var styleB = lipgloss.NewStyle(). Foreground(lipgloss.Color("201")), Inherit(styleA) ``` -------------------------------- ### Get Number of Rows in StringData Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Returns the total number of rows currently stored in the `StringData`. ```go func (m *StringData) Rows() int ``` -------------------------------- ### Get Border Column Status Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2/table Check if the column border separator is currently enabled for the table. ```go func (t *Table) GetBorderColumn() bool ``` -------------------------------- ### Create an ASCII Table Border Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Generate a table with standard ASCII borders using `ASCIIBorder()`. This provides a classic text-based table appearance. ```go table.New().Border(lipgloss.ASCIIBorder()) ``` -------------------------------- ### TerminalColor Interface Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Represents a color intended to be rendered in the terminal. It includes a method to get RGBA values. ```go type TerminalColor interface { RGBA() (r, g, b, a uint32) // contains filtered or unexported methods } ``` -------------------------------- ### Get Horizontal Padding Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the sum of the left and right padding. Unset values are measured as 0. ```go func (s Style) GetHorizontalPadding() int ``` -------------------------------- ### Apply Shorthand Padding Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Uses shorthand syntax for applying padding, similar to CSS. ```go // 2 cells on all sides lipgloss.NewStyle().Padding(2) // 2 cells on the top and bottom, 4 cells on the left and right lipgloss.NewStyle().Margin(2, 4) // 1 cell on the top, 4 cells on the sides, 2 cells on the bottom lipgloss.NewStyle().Padding(1, 4, 2) // Clockwise, starting from the top: 2 cells on the top, 4 on the right, 3 on // the bottom, and 1 on the left lipgloss.NewStyle().Margin(2, 4, 3, 1) ``` -------------------------------- ### Get Horizontal Margins Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Retrieves the sum of the left and right margins. Unset values are measured as 0. ```go func (s Style) GetHorizontalMargins() int ``` -------------------------------- ### Applying Borders with Lip Gloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Demonstrates how to add standard, rounded, and custom borders to text styles. You can specify border characters, colors, and which sides to apply them to. ```go // Add a purple, rectangular border var style = lipgloss.NewStyle(). BorderStyle(lipgloss.NormalBorder()). BorderForeground(lipgloss.Color("63")) // Set a rounded, yellow-on-purple border to the top and left var anotherStyle = lipgloss.NewStyle(). BorderStyle(lipgloss.RoundedBorder()). BorderForeground(lipgloss.Color("228")), BorderBackground(lipgloss.Color("63")), BorderTop(true). BorderLeft(true) // Make your own border var myCuteBorder = lipgloss.Border{ Top: "._.:*:", Bottom: "._.:*:", Left: "|*", Right: "|*", TopLeft: "*", TopRight: "*", BottomLeft: "*", BottomRight: "*", } ``` -------------------------------- ### Custom Renderers for Adaptive Colors Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Create custom renderers to handle specific output targets, enabling correct detection of color profiles and dark background status, useful in server-client scenarios. ```go func myLittleHandler(sess ssh.Session) { // Create a renderer for the client. renderer := lipgloss.NewRenderer(sess) // Create a new style on the renderer. style := renderer.NewStyle().Background(lipgloss.AdaptiveColor{Light: "63", Dark: "228"}) // Render. The color profile and dark background state will be correctly detected. io.WriteString(sess, style.Render("Heyyyyyyy")) } ``` -------------------------------- ### Get Child at Index from NodeChildren Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Retrieves a specific child node from a NodeChildren slice based on its index. ```go func (n NodeChildren) At(i int) Node ``` -------------------------------- ### Define Table Data and Styles Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Prepare data as a slice of string slices and define Lip Gloss styles for headers, cells, and alternating rows. These styles will be applied to the rendered table. ```go rows := [][]string{ {"Chinese", "您好", "你好"}, {"Japanese", "こんにちは", "やあ"}, {"Arabic", "أهلين", "أهلا"}, {"Russian", "Здравствуйте", "Привет"}, {"Spanish", "Hola", "¿Qué tal?"}, } var ( purple = lipgloss.Color("99") gray = lipgloss.Color("245") lightGray = lipgloss.Color("241") headerStyle = lipgloss.NewStyle().Foreground(purple).Bold(true).Align(lipgloss.Center) cellStyle = lipgloss.NewStyle().Padding(0, 1).Width(14) oddRowStyle = cellStyle.Foreground(gray) evenRowStyle = cellStyle.Foreground(lightGray) ) ``` -------------------------------- ### Get Leaf Children Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Returns an empty collection of children for a Leaf node, as leaves do not have nested items. ```go func (Leaf) Children() Children ``` -------------------------------- ### Formatted Print to Stdout with Lip Gloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Use Printf to output formatted strings to stdout, with automatic color downsampling. ```go str := NewStyle(). Foreground(lipgloss.Color("#6a00ff")). Render("knuckle") Printf("Time for a %s sandwich!\n", str) ``` -------------------------------- ### Get ASCII Border Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 ASCIIBorder returns a Border struct configured with standard ASCII characters for table borders. ```go func ASCIIBorder() Border ``` -------------------------------- ### Apply Margins Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Sets margins on all sides of a style. ```go // Margins var style = lipgloss.NewStyle(). MarginTop(2). MarginRight(4). MarginBottom(2). MarginLeft(4) ``` -------------------------------- ### Get Whitespace Coloring Setting Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Checks if whitespace coloring is enabled for the style. Returns false if no value is set. ```go func (s Style) GetColorWhitespace() bool ``` -------------------------------- ### Render the Table Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/table Generates the string representation of the table, ready for display. This should typically be the last method called in a chain. ```go func (t *Table) Render() string ``` -------------------------------- ### Color Profile and Background Detection Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Functions to get the current terminal color profile and detect if the background is dark. ```APIDOC ## ColorProfile ### Description Gets the current terminal's color profile. ### Returns - termenv.Profile: The current color profile. ## HasDarkBackground ### Description Checks if the terminal has a dark background. ### Returns - bool: True if the background is dark, false otherwise. ## SetColorProfile ### Description Sets the current terminal's color profile. ### Parameters - p (termenv.Profile): The color profile to set. ## SetHasDarkBackground ### Description Sets whether the terminal has a dark background. ### Parameters - b (bool): True to indicate a dark background, false otherwise. ``` -------------------------------- ### Define True Color (24-bit) Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Illustrates how to define colors using the 24-bit True Color profile. ```go lipgloss.Color("#0000FF") // good ol' 100% blue lipgloss.Color("#04B575") // a green lipgloss.Color("#3C3C3C") // a dark gray ``` -------------------------------- ### Get Filtered Length Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Returns the number of children currently present in the tree after filtering. This is useful for pagination or iteration. ```go func (m *Filter) Length() int ``` -------------------------------- ### Apply Padding Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/v2 Sets padding on all sides of a style. ```go // Padding var style = lipgloss.NewStyle(). PaddingTop(2). PaddingRight(4). PaddingBottom(2). PaddingLeft(4) ``` -------------------------------- ### Get Node at Index Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss/tree Retrieves a node from the filtered results at a specific index. The index is relative to the filtered list. ```go func (m *Filter) At(index int) Node ``` -------------------------------- ### Style Creation Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Functions for creating and initializing Style objects. ```APIDOC ## func NewStyle ### Description NewStyle returns a new, empty Style. While it's syntactic sugar for the Style{} primitive, it's recommended to use this function for creating styles in case the underlying implementation changes. It takes an optional string value to be set as the underlying string value for this style. ### Method func NewStyle() Style ``` -------------------------------- ### Unsetting Rules in Lip Gloss Source: https://pkg.go.dev/github.com/charmbracelet/lipgloss Demonstrates how to unset specific style rules, such as bold text or background color, effectively reverting them. ```go var style = lipgloss.NewStyle(). Bold(true). // make it bold UnsetBold(). // jk don't make it bold Background(lipgloss.Color("227")). // yellow background UnsetBackground() // never mind ```