https://github.com/charmbracelet/lipgloss Skip to content Sign up Sign up * Why GitHub? Features - + Mobile - + Actions - + Codespaces - + Packages - + Security - + Code review - + Project management - + Integrations - + GitHub Sponsors - + Customer stories- * Team * Enterprise * Explore + Explore GitHub - Learn and contribute + Topics - + Collections - + Trending - + Learning Lab - + Open source guides - Connect with others + The ReadME Project - + Events - + Community forum - + GitHub Education - + GitHub Stars program - * Marketplace * Pricing Plans - + Compare plans - + Contact Sales - + Education - [ ] [search-key] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this organization All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up Sign up {{ message }} charmbracelet / lipgloss * Notifications * Star 226 * Fork 1 Style definitions for nice terminal layouts MIT License 226 stars 1 fork Star Notifications * Code * Issues 0 * Pull requests 0 * Discussions * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Discussions * Actions * Projects * Security * Insights master Switch branches/tags [ ] Branches Tags Nothing to show {{ refName }} default View all branches Nothing to show {{ refName }} default View all tags 1 branch 1 tag Go to file Code Clone HTTPS GitHub CLI [https://github.com/c] Use Git or checkout with SVN using the web URL. [gh repo clone charmb] Work fast with our official CLI. Learn more. * Open with GitHub Desktop * Download ZIP Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Go back Launching Xcode If nothing happens, download Xcode and try again. Go back Launching Visual Studio If nothing happens, download the GitHub extension for Visual Studio and try again. Go back Latest commit @meowgorithm meowgorithm go mod tidy against example per termenv update ... e45d00a Apr 3, 2021 go mod tidy against example per termenv update e45d00a Git stats * 97 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Add GitHub workflows Mar 18, 2021 example go mod tidy against example per termenv update Apr 3, 2021 .golangci.yml Add GitHub workflows Mar 18, 2021 LICENSE Initial commit. Add the nuts and bolts. Mar 1, 2021 README.md Fix typo in README Apr 3, 2021 align.go Remove the gaps and add the periods that the linter wants Apr 2, 2021 borders.go Rename ColorType to TerminalColor Mar 31, 2021 color.go Whoops, fix infinite recursion and actualy implement Go Color Apr 2, 2021 get.go Rename ColorType to TerminalColor Mar 31, 2021 go.mod Bump termenv to v0.8.1 Apr 2, 2021 go.sum Bump termenv to v0.8.1 Apr 2, 2021 join.go Add utility for horizontally and vertically placing blocks in whitespace Mar 26, 2021 position.go Remove the gaps and add the periods that the linter wants Apr 2, 2021 set.go Just expose the API for setting the margin color. Apr 2, 2021 size.go Add utils for measuring paragraphs Mar 29, 2021 style.go Remove the gaps and add the periods that the linter wants Apr 2, 2021 unset.go Margins inherit background color Mar 31, 2021 whitespace.go Rename ColorType to TerminalColor Mar 31, 2021 View code Lip Gloss Colors ANSI 16 colors (4-bit) ANSI 256 Colors (8-bit) True Color (24-bit) Adaptive Colors Inline Formatting Block-Level Formatting Aligning Text Width and Height Copying Styles Inheritance Unsetting Rules Enforcing Rules Rendering Joining Paragraphs Placing Text in Whitespace What about Bubble Tea? Under the Hood Rendering Markdown License README.md Lip Gloss Lip Gloss Title Treatment Latest Release GoDoc Build Status Style definitions for nice terminal layouts. Built with TUIs in mind. Lip Gloss example Lip Gloss takes an expressive, declarative approach to terminal rendering. Users familiar with CSS will feel at home with Lip Gloss. 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.")) Colors Lip Gloss supports the following color profiles: ANSI 16 colors (4-bit) lipgloss.Color("5") // magenta lipgloss.Color("9") // red lipgloss.Color("12") // light blue ANSI 256 Colors (8-bit) lipgloss.Color("86") // aqua lipgloss.Color("201") // hot pink lipgloss.Color("202") // orange True Color (24-bit) lipgloss.Color("#0000FF") // good ol' 100% blue lipgloss.Color("#04B575") // a green lipgloss.Color("#3C3C3C") // a dark gray The terminal's color profile will be automatically detected, and colors outside the gamut of the current palette will be automatically coerced to their closest available value. Adaptive Colors You can also specify color options for light and dark backgrounds: lipgloss.AdaptiveColor{Light: "236", Dark: "248"} The terminal's background color will automatically be detected and the appropriate color will be chosen at runtime. Inline Formatting Lip Gloss supports the usual ANSI text formatting options: var style = lipgloss.NewStyle(). Bold(true). Italic(true). Faint(true). Blink(true). Strikethrough(true). Underline(true). Reverse(true) Block-Level Formatting Lip Gloss also supports rules for block-level formatting: // Padding var style = lipgloss.NewStyle(). PaddingTop(2). PaddingRight(4). PaddingBottom(2). PaddingLeft(4) // Margins var style = lipgloss.NewStyle(). MarginTop(2). RightMarginRight(4). MarginBottom(2). MarginLeft(4) There is also shorthand syntax for margins and padding, which follows the same format as CSS: // 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) Aligning Text You can align paragraphs of text to the left, right, or center. var style = lipgloss.NewStyle(). Width(24). Align(lipgloss.Left). // align it left Align(lipgloss.Right). // no wait, align it right Align(lipgloss.Center) // just kidding, align it in the center Width and Height Setting a minimim width and height is simple and straightforward. var str = lipgloss.NewStyle(). Width(24). Height(32). Foreground(lipgloss.Color("63")). Render("What's for lunch?") Copying Styles Just use Copy(): var style = lipgloss.NewStyle().Foreground(lipgloss.Color("219")) var wildStyle = style.Copy().Blink(true) Copy() performs a copy on the underlying data structure ensuring that you get a true, dereferenced copy of a style. Without copying it's possible to mutate styles. Inheritance Styles can inherit rules from other styles. When inheriting, only unset rules on the receiver are inherited. 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) Unsetting Rules All rules can be unset: 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 When a rule is unset, it won't be inherited or copied. Note that in the case of boolean values, unset values are different from falsey ones. That is, values explicitly set to false will be copied and inherited, whereas unset values will not. Enforcing Rules Sometimes, such as when developing a component, you want to make sure style definitions respect their intended purpose in the UI. This is where Inline and MaxWidth, and MaxHeight come in: // Force rendering onto a single line, ignoring margins, padding, and borders. someStyle.Inline().Render("yadda yadda") // Also limit rendering to five cells someStyle.Inline().MaxWidth(5).Render("yadda yadda") // Limit rendering to a 5x5 cell block someStyle.MaxWidth(5).MaxHeight(5).Render("yadda yadda") Rendering Generally, you just call the Render(string) method on a lipgloss.Style: fmt.Println(lipgloss.NewStyle().Bold(true).Render("Hello, kitty.")) But you could also use the Stringer interface: var style = lipgloss.NewStyle().String("Ni Hao ,Mao Mi . ").Bold(true) fmt.Printf("%s\n", style) Joining Paragraphs There are also some utility functions for horizontally and vertically joining paragraphs of text. // Horizontally join three paragraphs along their bottom edges lipgloss.HorizontalJoin(lipgloss.Bottom, paragraphA, paragraphB, paragraphC) // Vertically join two paragraphs along their center axes lipgloss.VerticalJoin(lipgloss.Center, paragraphA, paragraphB) // Horizontally join three paragraphs, with the shorter ones aligning 20% // from the top of the tallest lipgloss.HorizontalJoin(0.2, paragraphA, paragraphB, paragraphC) Placing Text in Whitespace Sometimes you simply want to place a block of text in whitespace. // Center a paragraph horizontally in a space 80 cells wide. The height of // the block returned will be as tall as the input paragraph. block := lipgloss.PlaceHorizontal(80, lipgloss.Center, fancyStyledParagraph) // Place a paragraph at the bottom of a space 30 cells tall. The width of // the text block returned will be as wide as the input paragraph. block := lipgloss.PlaceVertical(30, lipgloss.Bottom, fancyStyledParagraph) // Place a paragraph in the bottom right corner of a 30x80 cell space. block := lipgloss.Place(30, 80, lipgloss.Right, lipgloss.Bottom, fancyStyledParagraph) You can also style the whitespace. For details, see the docs. --------------------------------------------------------------------- What about Bubble Tea? Lip Gloss doesn't replace Bubble Tea. Rather, it is an excellent Bubble Tea companion. It was designed to make assembling terminal user interface views as simple and fun as possible so that you can focus on building your application instead of concerning yourself with low-level layout details. In simple terms, you can use Lip Gloss to help build your Bubble Tea views. Under the Hood Lip Gloss is built on the excellent Termenv and Reflow libraries which deal with color and ANSI-aware text operations, respectively. For many use cases Termenv and Reflow will be sufficient for your needs. Rendering Markdown For a more document-centric rendering solution with support for things like lists, tables, and syntax-highlighted code have a look at Glamour, the stylesheet-based Markdown renderer. License MIT --------------------------------------------------------------------- Part of Charm. The Charm logo CharmRe Ai Kai Yuan * Charm loves open source About Style definitions for nice terminal layouts Topics go cli golang layout style tui Resources Readme License MIT License Releases 1 v0.1.0 Latest Apr 3, 2021 Packages 0 No packages published Contributors 2 * @meowgorithm meowgorithm Christian Rocha * @muesli muesli Christian Muehlhaeuser Languages * Go 100.0% * (c) 2021 GitHub, Inc. * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time. You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.