@charmland/lipgloss
v2.0.0-beta.3-0e280f3
Published
Style definitions for nice terminal layouts π
Readme
LipGloss.js
The lipgloss that you know and love, now in JavaScript.
[!WARNING] LipGloss.js is stll experimental.
Installation
npm i @charmland/lipglossExample
const { Table, TableData, Style, Color, List, Tree, Leaf, Bullet, RoundedEnumerator } = require("@charmland/lipgloss");
var s = new Style().foreground(Color("240")).render;
console.log(
new Table()
.wrap(false)
.headers("Drink", "Description")
.row("Bubble Tea", s("Milky"))
.row("Milk Tea", s("Also milky"))
.row("Actual milk", s("Milky as well"))
.render(),
);
// TableData example - for more complex data management
const employeeData = new TableData(
["Employee ID", "Name", "Department"],
["001", "John Doe", "Engineering"],
["002", "Jane Smith", "Marketing"],
["003", "Mike Johnson", "Sales"]
);
console.log(
new Table()
.data(employeeData)
.styleFunc((row, col) => {
if (row === -1) {
return new Style().foreground(Color("99")).bold(true);
}
return new Style().padding(0, 1);
})
.render()
);
// List example
const groceries = new List("Bananas", "Barley", "Cashews", "Milk")
.enumerator(Bullet)
.itemStyle(new Style().foreground(Color("255")));
console.log(groceries.render());
// Tree example with Leaf nodes
const makeupTree = new Tree()
.root("β Makeup")
.child(
"Glossier",
"Fenty Beauty",
new Tree().child(
new Leaf("Gloss Bomb Universal Lip Luminizer"),
new Leaf("Hot Cheeks Velour Blushlighter")
),
new Leaf("Nyx"),
new Leaf("Mac"),
"Milk"
)
.enumerator(RoundedEnumerator)
.enumeratorStyle(new Style().foreground(Color("63")).marginRight(1))
.rootStyle(new Style().foreground(Color("35")))
.itemStyle(new Style().foreground(Color("212")));
console.log(makeupTree.render());TableData
The TableData class provides a more structured way to manage table data compared to using individual rows. It's particularly useful when you need to:
- Build tables dynamically
- Access individual cells programmatically
- Manage large datasets
- Separate data logic from presentation
Basic Usage
const { Table, TableData, Style, Color } = require("@charmland/lipgloss");
// Create TableData with initial rows
const data = new TableData(
["Name", "Age", "City"],
["Alice", "25", "New York"],
["Bob", "30", "San Francisco"]
);
// Or build it incrementally
const data2 = new TableData()
.append(["Product", "Price"])
.append(["Laptop", "$999"])
.append(["Mouse", "$25"]);
// Use with Table
const table = new Table()
.data(data)
.styleFunc((row, col) => {
if (row === -1) return new Style().bold(true); // Header
return new Style().padding(0, 1);
})
.render();TableData Methods
new TableData(...rows)- Create with optional initial rows.append(row)- Add a single row (array of strings).rows(...rows)- Add multiple rows at once.at(row, col)- Get value at specific position.rowCount()- Get number of rows.columnCount()- Get number of columns
See examples/table-data.js for more comprehensive examples.
Environment Variables
You can control debug output using environment variables:
LIPGLOSS_DEBUG=true- Enable all lipgloss debug outputDEBUG=lipgloss- Enable lipgloss debug output (standard debug pattern)DEBUG=*- Enable all debug output
Example:
node your-script.jsCompability
Lipgloss in JavaScript it's experimental and a lot of existing functionalities are not still ported to JavaScript.
Size (100%)
| Function | Status |
| --- | --- |
| Width | β
|
| Height | β
|
| Size | β
|
Color (100%)
| Function | Status |
| --- | --- |
| Color | β
|
| NoColor | β
|
| Complete | β
|
| LightDark | β
|
| RGBA | β
|
Borders (100%)
| Function | Status |
| --- | --- |
| NormalBorder | β
|
| RoundedBorder | β
|
| BlockBorder | β
|
| OuterHalfBlockBorder | β
|
| InnerHalfBlockBorder | β
|
| ThickBorder | β
|
| DoubleBorder | β
|
| HiddenBorder | β
|
| MarkdownBorder | β
|
| ASCIIBorder | β
|
Style (97.62%)
| Function | Status |
| --- | --- |
| Foreground | β
|
| Background | β
|
| Width | β
|
| Height | β
|
| Align | β
|
| AlignHorizontal | β
|
| AlignVertical | β
|
| Padding | β
|
| PaddingLeft | β
|
| PaddingRight | β
|
| PaddingTop | β
|
| PaddingBottom | β
|
| ColorWhitespace | β
|
| Margin | β
|
| MarginLeft | β
|
| MarginRight | β
|
| MarginTop | β
|
| MarginBottom | β
|
| MarginBackground | β
|
| Border | β
|
| BorderStyle | β
|
| SetBorderRight | β
|
| SetBorderLeft | β
|
| SetBorderTop | β
|
| SetBorderBottom | β
|
| BorderForeground | β
|
| BorderTopForeground | β
|
| BorderRightForeground | β
|
| BorderBottomForeground | β
|
| BorderLeftForeground | β
|
| BorderBackground | β
|
| BorderTopBackground | β
|
| BorderRightBackground | β
|
| BorderBottomBackground | β
|
| BorderLeftBackground | β
|
| Inline | β
|
| MaxWidth | β
|
| MaxHeight | β
|
| TabWidth | β
|
| UnderlineSpaces | β
|
| Underline | β
|
| Reverse | β
|
| SetString | β
|
| Inherit | β
|
| Faint | β
|
| Italic | β
|
| Strikethrough | β
|
| StrikethroughSpaces | β
|
| Transform | β³ |
Table (100%)
| Function | Status |
| --- | --- |
| table.New | β
|
| table.Rows | β
|
| table.Headers | β
|
| table.Render | β
|
| table.ClearRows | β
|
| table.BorderTop | β
|
| table.BorderBottom | β
|
| table.BorderLeft | β
|
| table.BorderRight | β
|
| table.BorderHeader | β
|
| table.BorderColumn | β
|
| table.BorderRow | β
|
| table.Width | β
|
| table.Height | β
|
| table.Offset | β
|
| table.String | β
|
| table.StyleFunc | β
|
| table.Data | β
|
| table.Border | β
|
| table.BorderStyle | β
|
List (100%)
| Function | Status |
| --- | --- |
| Hidden | β
|
| Hide | β
|
| Offset | β
|
| Value | β
|
| String | β
|
| Indenter | β
|
| ItemStyle | β
|
| ItemStyleFunc | β
|
| EnumeratorStyle | β
|
| EnumeratorStyleFunc | β
|
| Item | β
|
| Items | β
|
| Enumerator | β
|
Tree (95%)
| Function | Status |
| --- | --- |
| tree.New | β
|
| tree.Root | β
|
| tree.Child | β
|
| tree.Hidden | β
|
| tree.Hide | β
|
| tree.SetHidden | β
|
| tree.Offset | β
|
| tree.Value | β
|
| tree.SetValue | β
|
| tree.String | β
|
| tree.Render | β
|
| tree.EnumeratorStyle | β
|
| tree.EnumeratorStyleFunc | β
|
| tree.ItemStyle | β
|
| tree.ItemStyleFunc | β
|
| tree.RootStyle | β
|
| tree.Enumerator | β
|
| tree.Indenter | β
|
| tree.DefaultEnumerator | β
|
| tree.RoundedEnumerator | β
|
| tree.DefaultIndenter | β
|
| NewLeaf | β
|
| Leaf.Value | β
|
| Leaf.SetValue | β
|
| Leaf.Hidden | β
|
| Leaf.SetHidden | β
|
| Leaf.String | β
|
| Custom Enumerators | β³ |
| Custom Indenters | β³ |
Join (100%)
| Function | Status |
| --- | --- |
| JoinHorizontal | β
|
| JoinVertical | β
|
Position (100%)
| Function | Status |
| --- | --- |
| Center | β
|
| Right | β
|
| Bottom | β
|
| Top | β
|
| Left | β
|
| Place | β
|
Query (50%)
| Function | Status |
| --- | --- |
| BackgroundColor | β³ |
| HasDarkBackground | β
|
Align (0%)
| Function | Status |
| --- | --- |
| EnableLegacyWindowsANSI | β³ |
Contributing
We'd love to have you contribute! Please see the contributing guidelines for more information.
Testing
The JavaScript bindings include a comprehensive test suite:
# From bindings directory
npm test # Run all tests
npm run test:simple # Basic table functionality
npm run test:comprehensive # Complete TableData tests
npm run examples # Showcase functionality
# Or from examples directory
cd examples && npm testTests are located in examples/tests/ and cover:
- Basic table functionality
- TableData operations
- Style functions
- Unicode handling (with known limitations)
See contributing.
Feedback
Weβd love to hear your thoughts on this project. Feel free to drop us a note!
License
Part of Charm.
Charmηη±εΌζΊ β’ Charm loves open source
