@boba-cli/chapstick 0.1.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +166 -0
- package/dist/index.cjs +719 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +348 -0
- package/dist/index.d.ts +348 -0
- package/dist/index.js +698 -0
- package/dist/index.js.map +1 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# @boba-cli/chapstick
|
|
2
|
+
|
|
3
|
+
TypeScript port of Charmbracelet Lip Gloss for styling terminal strings. Implements a fluent `Style` API with colors, padding/margin, borders, alignment, joins/placement, and ANSI-aware rendering.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pnpm add @boba-cli/chapstick
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quickstart
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { Style, borderStyles } from '@boba-cli/chapstick'
|
|
15
|
+
|
|
16
|
+
const card = new Style()
|
|
17
|
+
.padding(1)
|
|
18
|
+
.border(borderStyles.rounded)
|
|
19
|
+
.borderForeground('#7c3aed')
|
|
20
|
+
.alignHorizontal('center')
|
|
21
|
+
.render('Hello Boba')
|
|
22
|
+
|
|
23
|
+
console.log(card)
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
### Style Builder
|
|
29
|
+
|
|
30
|
+
The `Style` class provides a fluent, immutable API for building terminal styles:
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { Style } from '@boba-cli/chapstick'
|
|
34
|
+
|
|
35
|
+
const style = new Style()
|
|
36
|
+
.foreground('#ff0000') // Text color (hex, named, or rgb())
|
|
37
|
+
.background('#000000') // Background color
|
|
38
|
+
.bold() // Bold text
|
|
39
|
+
.italic() // Italic text
|
|
40
|
+
.underline() // Underlined text
|
|
41
|
+
.strikethrough() // Strikethrough text
|
|
42
|
+
.padding(1) // Padding on all sides
|
|
43
|
+
.padding(1, 2) // Vertical, horizontal padding
|
|
44
|
+
.padding(1, 2, 1, 2) // Top, right, bottom, left
|
|
45
|
+
.margin(1) // Margin (same overloads as padding)
|
|
46
|
+
.width(40) // Fixed width (truncates)
|
|
47
|
+
.maxWidth(80) // Max width (wraps)
|
|
48
|
+
.height(10) // Fixed height
|
|
49
|
+
.maxHeight(20) // Max height
|
|
50
|
+
.alignHorizontal('center') // left | center | right
|
|
51
|
+
.alignVertical('center') // top | center | bottom
|
|
52
|
+
.border(true) // Enable default border
|
|
53
|
+
.border(borderStyles.rounded) // Use specific border style
|
|
54
|
+
.borderForeground('#7c3aed') // Border color
|
|
55
|
+
.inline() // Strip newlines, skip padding/margin
|
|
56
|
+
.render('Your text here')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Style Inheritance
|
|
60
|
+
|
|
61
|
+
Styles can inherit properties from other styles (excluding padding and margin):
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const base = new Style().bold().foreground('#00ff00')
|
|
65
|
+
const derived = new Style().italic().inherit(base)
|
|
66
|
+
// derived has: bold, italic, foreground
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Adaptive Colors
|
|
70
|
+
|
|
71
|
+
Support for light/dark terminal backgrounds:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
const style = new Style().foreground({
|
|
75
|
+
light: '#000000', // Used on light backgrounds
|
|
76
|
+
dark: '#ffffff', // Used on dark backgrounds
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Composition
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
import { Style, joinHorizontal, joinVertical, place } from '@boba-cli/chapstick'
|
|
84
|
+
|
|
85
|
+
const label = new Style().foreground('#10b981').bold()
|
|
86
|
+
const left = label.render('Left')
|
|
87
|
+
const right = label.render('Right')
|
|
88
|
+
|
|
89
|
+
// Join blocks side-by-side with spacing
|
|
90
|
+
console.log(joinHorizontal(2, left, right))
|
|
91
|
+
|
|
92
|
+
// Join blocks vertically with blank line spacing
|
|
93
|
+
console.log(joinVertical(1, 'Top', 'Middle', 'Bottom'))
|
|
94
|
+
|
|
95
|
+
// Place content inside a 20x5 area, centered
|
|
96
|
+
console.log(place(20, 5, 'center', 'center', label.render('Centered')))
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Measurement Utilities
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { width, clampWidth, wrapWidth, padLines } from '@boba-cli/chapstick'
|
|
103
|
+
|
|
104
|
+
// Get display width (ANSI-aware)
|
|
105
|
+
width('\x1b[31mred\x1b[0m') // => 3
|
|
106
|
+
|
|
107
|
+
// Truncate to max width
|
|
108
|
+
clampWidth('hello world', 5) // => "hello"
|
|
109
|
+
|
|
110
|
+
// Word-wrap to max width
|
|
111
|
+
wrapWidth('hello world', 5) // => "hello\nworld"
|
|
112
|
+
|
|
113
|
+
// Pad lines with spaces
|
|
114
|
+
padLines('text', 2, 2) // => " text "
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Terminal Detection
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { getColorSupport, getTerminalBackground } from '@boba-cli/chapstick'
|
|
121
|
+
|
|
122
|
+
const support = getColorSupport()
|
|
123
|
+
// { level: 3, hasBasic: true, has256: true, has16m: true }
|
|
124
|
+
|
|
125
|
+
const bg = getTerminalBackground()
|
|
126
|
+
// "dark" | "light" | "unknown"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Border Styles
|
|
130
|
+
|
|
131
|
+
Built-in border styles:
|
|
132
|
+
|
|
133
|
+
```ts
|
|
134
|
+
import { borderStyles } from '@boba-cli/chapstick'
|
|
135
|
+
|
|
136
|
+
borderStyles.normal // ┌─┐│ │└─┘
|
|
137
|
+
borderStyles.rounded // ╭─╮│ │╰─╯
|
|
138
|
+
borderStyles.bold // ┏━┓┃ ┃┗━┛
|
|
139
|
+
borderStyles.double // ╔═╗║ ║╚═╝
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## API
|
|
143
|
+
|
|
144
|
+
### Types
|
|
145
|
+
|
|
146
|
+
- `HAlign` - `"left" | "center" | "right"`
|
|
147
|
+
- `VAlign` - `"top" | "center" | "bottom"`
|
|
148
|
+
- `Align` - Alias for `HAlign` (backwards compatibility)
|
|
149
|
+
- `ColorInput` - `string | { light?: string; dark?: string }`
|
|
150
|
+
- `BorderStyle` - Border character definitions
|
|
151
|
+
- `Spacing` - `{ top, right, bottom, left }`
|
|
152
|
+
- `StyleOptions` - All style configuration options
|
|
153
|
+
- `StyleKey` - Keys of `StyleOptions`
|
|
154
|
+
- `ColorSupport` - Color capability detection result
|
|
155
|
+
- `TerminalBackground` - `"dark" | "light" | "unknown"`
|
|
156
|
+
|
|
157
|
+
## Scripts
|
|
158
|
+
|
|
159
|
+
- `pnpm -C packages/chapstick build`
|
|
160
|
+
- `pnpm -C packages/chapstick test`
|
|
161
|
+
- `pnpm -C packages/chapstick lint`
|
|
162
|
+
- `pnpm -C packages/chapstick generate:api-report`
|
|
163
|
+
|
|
164
|
+
## License
|
|
165
|
+
|
|
166
|
+
MIT
|