Skip to content

Commit d06f385

Browse files
committed
Add terminal color detection documentation
1 parent c5aab21 commit d06f385

3 files changed

Lines changed: 484 additions & 2 deletions

File tree

content/docs/aesh/renderers.md

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,65 @@ public class LoginCommand implements Command<CommandInvocation> {
5959
## Colorized Output
6060

6161
```java
62+
import org.aesh.readline.terminal.formatting.TerminalColor;
63+
import org.aesh.readline.terminal.formatting.TerminalString;
64+
import org.aesh.readline.terminal.formatting.TerminalTextStyle;
65+
import org.aesh.readline.terminal.formatting.CharacterType;
66+
import org.aesh.readline.terminal.formatting.Color;
67+
6268
public class ColorizedRenderer implements OptionRenderer<ProcessedOption> {
6369

6470
@Override
6571
public String render(ProcessedOption option) {
6672
TerminalString colorized = new TerminalString(
6773
option.getValue(),
68-
TerminalColor.DEFAULT_TEXT,
69-
TerminalTextStyle.INTENSITY_BOLD
74+
new TerminalColor(Color.CYAN, Color.DEFAULT),
75+
new TerminalTextStyle(CharacterType.BOLD)
7076
);
7177
return colorized.toString();
7278
}
7379
}
7480
```
7581

82+
### Theme-Aware Rendering
83+
84+
For colors that adapt to the terminal's light or dark theme, use the semantic color methods with detected terminal capabilities:
85+
86+
```java
87+
import org.aesh.readline.terminal.TerminalColorDetector;
88+
import org.aesh.readline.terminal.formatting.TerminalColor;
89+
import org.aesh.readline.terminal.formatting.TerminalString;
90+
import org.aesh.terminal.utils.TerminalColorCapability;
91+
92+
public class AdaptiveRenderer implements OptionRenderer<ProcessedOption> {
93+
private final TerminalColorCapability capability;
94+
95+
public AdaptiveRenderer(TerminalColorCapability capability) {
96+
this.capability = capability;
97+
}
98+
99+
@Override
100+
public String render(ProcessedOption option) {
101+
// Use theme-aware colors that work on both light and dark backgrounds
102+
TerminalColor color = TerminalColor.forHighlight(capability);
103+
return new TerminalString(option.getValue(), color).toString();
104+
}
105+
}
106+
```
107+
108+
The semantic color methods automatically choose appropriate brightness:
109+
110+
| Method | Dark Theme | Light Theme | Use For |
111+
|--------|------------|-------------|---------|
112+
| `forError()` | Bright red | Normal red | Error messages |
113+
| `forSuccess()` | Bright green | Normal green | Success confirmations |
114+
| `forWarning()` | Bright yellow | Normal yellow | Warnings |
115+
| `forInfo()` | Bright cyan | Normal blue | Informational text |
116+
| `forHighlight()` | Bright white | Black | Emphasized text |
117+
| `forMuted()` | Normal white | Normal black | Secondary text |
118+
119+
See the Readline [Terminal Colors](/docs/readline/terminal-colors) documentation for more details on RGB colors and color depth adaptation.
120+
76121
## Conditional Rendering
77122

78123
```java

content/docs/readline/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ Think of it this way: Æsh is built **on top of** Æsh Readline. Æsh provides t
4242
- **Stream Support** - Standard out and standard error handling
4343
- **Shell Features** - Redirect, alias, and pipeline support
4444
- **Remote Connectivity** - SSH, Telnet, and WebSocket terminal servers
45+
- **[Color Detection](color-detection)** - Automatic terminal theme and color depth detection
46+
- **[Terminal Colors](terminal-colors)** - RGB colors, theme-aware styling, and color depth adaptation
4547

4648
## Architecture
4749

0 commit comments

Comments
 (0)