Skip to content

Commit deaf4d8

Browse files
committed
clarification regarding hsl value ranges
1 parent 819740a commit deaf4d8

1 file changed

Lines changed: 32 additions & 4 deletions

File tree

content/docs/readline/terminal-colors.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,24 @@ HSL (Hue, Saturation, Lightness) is often more intuitive than RGB for color sele
121121
- **Generate harmonious colors** by rotating hue
122122
- **Control color intensity** via saturation
123123

124+
### HSL Value Ranges
125+
126+
| Parameter | Range | Description |
127+
|-----------|-------|-------------|
128+
| **Hue** | 0-360 | Degrees on the color wheel |
129+
| **Saturation** | 0-100 | Percentage (0 = gray, 100 = vivid) |
130+
| **Lightness** | 0-100 | Percentage (0 = black, 50 = pure color, 100 = white) |
131+
132+
**Important:** HSL values use **percentages (0-100)**, not decimal fractions (0-1). For example, use `80` for 80% lightness, not `0.8`.
133+
134+
```java
135+
// Correct - using percentages
136+
TerminalColor.fromHSL(120, 80, 65); // H=120°, S=80%, L=65%
137+
138+
// Wrong - using decimals will produce nearly black colors
139+
TerminalColor.fromHSL(120, 0.8f, 0.65f); // S=0.8%, L=0.65% ≈ black
140+
```
141+
124142
### HSL Color Wheel
125143

126144
| Hue (degrees) | Color |
@@ -135,9 +153,11 @@ HSL (Hue, Saturation, Lightness) is often more intuitive than RGB for color sele
135153

136154
### From HSL Values
137155

156+
**Remember:** Use percentages (0-100) for saturation and lightness, not decimals (0-1).
157+
138158
```java
139159
// Foreground only - pure red at full saturation
140-
TerminalColor red = TerminalColor.fromHSL(0, 100, 50);
160+
TerminalColor red = TerminalColor.fromHSL(0, 100, 50); // H=0°, S=100%, L=50%
141161

142162
// Both foreground and background
143163
TerminalColor custom = TerminalColor.fromHSL(
@@ -148,8 +168,8 @@ TerminalColor custom = TerminalColor.fromHSL(
148168
// Optimal lightness for different backgrounds:
149169
// - Dark terminals: use lightness 60-75 for visible colors
150170
// - Light terminals: use lightness 25-40 for visible colors
151-
int darkL = 65; // For dark backgrounds
152-
int lightL = 35; // For light backgrounds
171+
int darkL = 65; // 65% lightness for dark backgrounds
172+
int lightL = 35; // 35% lightness for light backgrounds
153173
```
154174

155175
### HSL Conversion Utilities
@@ -595,7 +615,9 @@ builder.bgHex("#1E1E1E").append("Dark background");
595615

596616
#### HSL Colors
597617

598-
HSL is ideal for generating readable colors that adapt to terminal themes:
618+
HSL is ideal for generating readable colors that adapt to terminal themes.
619+
620+
**Value ranges:** Hue is 0-360 degrees, Saturation and Lightness are 0-100 percentages (not 0-1 decimals).
599621

600622
```java
601623
// HSL foreground (hue 0-360, saturation 0-100, lightness 0-100)
@@ -612,8 +634,14 @@ builder.hsl(180, 80, 65, "Cyan text");
612634
boolean isDark = cap.getTheme() == TerminalTheme.DARK;
613635
int lightness = isDark ? 65 : 35;
614636
builder.hsl(0, 80, lightness).append("Theme-adaptive red");
637+
638+
// Override semantic colors with HSL
639+
builder.timestampHsl(200, 30, 70) // Light blue-gray for timestamps
640+
.messageHsl(280, 60, 65); // Light purple for messages
615641
```
616642

643+
**Common mistake:** Using decimal values like `0.8` instead of `80` will produce nearly black colors since `0.8%` lightness is almost black.
644+
617645
#### Bright Colors
618646

619647
```java

0 commit comments

Comments
 (0)