Skip to content

Commit 42a2ec3

Browse files
committed
More updates for ANSIBuilder and TerminalCapability
1 parent 0d51d1c commit 42a2ec3

2 files changed

Lines changed: 44 additions & 8 deletions

File tree

content/docs/readline/color-detection.md

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ int errorText = cap.getSuggestedErrorCode(); // 31 or 91 (red variants)
9393
int successText = cap.getSuggestedSuccessCode(); // 32 or 92 (green variants)
9494
int warningText = cap.getSuggestedWarningCode(); // 33 or 93 (yellow variants)
9595
int infoText = cap.getSuggestedInfoCode(); // 34 or 94 (blue variants)
96+
int debugText = cap.getSuggestedDebugCode(); // 90 or 37 (gray/white variants)
97+
int traceText = cap.getSuggestedTraceCode(); // 90 (gray - least prominent)
9698
int timestampText = cap.getSuggestedTimestampCode(); // 36 or 96 (cyan variants)
9799
int messageText = cap.getSuggestedMessageCode(); // 35 or 95 (magenta variants)
98100

@@ -109,9 +111,14 @@ connection.write("\u001B[" + errorText + "mError: Something went wrong\u001B[0m\
109111
| `getSuggestedSuccessCode()` | 92 (bright green) | 32 (green) | Success messages |
110112
| `getSuggestedWarningCode()` | 93 (bright yellow) | 33 (yellow) | Warnings |
111113
| `getSuggestedInfoCode()` | 94 (bright blue) | 34 (blue) | Info messages |
114+
| `getSuggestedDebugCode()` | 37 (white) | 90 (gray) | Debug messages |
115+
| `getSuggestedTraceCode()` | 90 (gray) | 90 (gray) | Trace messages (least prominent) |
112116
| `getSuggestedTimestampCode()` | 96 (bright cyan) | 36 (cyan) | Timestamps in logs |
113117
| `getSuggestedMessageCode()` | 95 (bright magenta) | 35 (magenta) | Highlighted messages |
114118

119+
The log level colors follow a prominence hierarchy from most to least visible:
120+
**ERROR > WARN > INFO > DEBUG > TRACE**
121+
115122
### Customizing Suggested Colors
116123

117124
You can override the default suggested colors using the `Builder`:
@@ -139,6 +146,8 @@ TerminalColorCapability custom = TerminalColorCapability.builder()
139146
.successCode(46)
140147
.warningCode(208)
141148
.infoCode(39)
149+
.debugCode(250) // 256-color light gray
150+
.traceCode(240) // 256-color dark gray
142151
.timestampCode(244)
143152
.messageCode(255)
144153
.foregroundCode(252)
@@ -480,8 +489,8 @@ ANSIBuilder builder = ANSIBuilder.builder(cap);
480489
// Log line with timestamp, level, and message
481490
connection.write(builder
482491
.timestamp("2024-01-15 10:30:45").append(" ")
483-
.success("[INFO]").append(" ")
484-
.message("Application started successfully")
492+
.error("[ERROR]").append(" ")
493+
.append("Connection to database failed")
485494
.toLine());
486495

487496
builder.reset();
@@ -494,12 +503,26 @@ connection.write(builder
494503
builder.reset();
495504
connection.write(builder
496505
.timestamp("2024-01-15 10:30:47").append(" ")
497-
.error("[ERROR]").append(" ")
498-
.append("Connection to database failed")
506+
.info("[INFO]").append(" ")
507+
.message("Application started successfully")
508+
.toLine());
509+
510+
builder.reset();
511+
connection.write(builder
512+
.timestamp("2024-01-15 10:30:48").append(" ")
513+
.debug("[DEBUG]").append(" ")
514+
.append("Configuration loaded from /etc/app.conf")
515+
.toLine());
516+
517+
builder.reset();
518+
connection.write(builder
519+
.timestamp("2024-01-15 10:30:49").append(" ")
520+
.trace("[TRACE]").append(" ")
521+
.append("Entering method processRequest()")
499522
.toLine());
500523
```
501524

502-
Output adapts automatically to the terminal theme - bright colors on dark backgrounds, normal colors on light backgrounds.
525+
Output adapts automatically to the terminal theme - bright colors on dark backgrounds, normal colors on light backgrounds. Debug and trace use subdued colors (white/gray) to be less prominent than the colored log levels.
503526

504527
### Color Depth Adaptation
505528

content/docs/readline/terminal-colors.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,15 @@ import org.aesh.terminal.utils.TerminalColorCapability;
126126
// Detect terminal capabilities
127127
TerminalColorCapability cap = TerminalColorDetector.detect(connection);
128128

129-
// Get theme-appropriate colors
129+
// Get theme-appropriate colors for log levels
130130
TerminalColor error = TerminalColor.forError(cap); // Red
131131
TerminalColor success = TerminalColor.forSuccess(cap); // Green
132132
TerminalColor warning = TerminalColor.forWarning(cap); // Yellow
133133
TerminalColor info = TerminalColor.forInfo(cap); // Cyan/Blue
134+
TerminalColor debug = TerminalColor.forDebug(cap); // White/Gray (subdued)
135+
TerminalColor trace = TerminalColor.forTrace(cap); // Gray (least prominent)
136+
137+
// Other semantic colors
134138
TerminalColor highlight = TerminalColor.forHighlight(cap); // Emphasized
135139
TerminalColor muted = TerminalColor.forMuted(cap); // Dimmed
136140
TerminalColor timestamp = TerminalColor.forTimestamp(cap); // Cyan (for log timestamps)
@@ -145,11 +149,15 @@ TerminalColor message = TerminalColor.forMessage(cap); // Magenta (for high
145149
| `forSuccess()` | Bright green | Normal green | Success messages |
146150
| `forWarning()` | Bright yellow | Normal yellow | Warnings |
147151
| `forInfo()` | Bright cyan | Normal blue | Info messages |
152+
| `forDebug()` | White | Gray | Debug messages (subdued) |
153+
| `forTrace()` | Gray | Gray | Trace messages (least prominent) |
148154
| `forHighlight()` | Bright white | Black | Emphasized text |
149155
| `forMuted()` | Normal white | Normal black | Secondary text |
150156
| `forTimestamp()` | Bright cyan | Normal cyan | Log timestamps |
151157
| `forMessage()` | Bright magenta | Normal magenta | Highlighted messages |
152158

159+
Log level colors follow a prominence hierarchy: **ERROR > WARN > INFO > DEBUG > TRACE**
160+
153161
These methods ensure readable colors on any background. On dark themes, bright colors stand out. On light themes, normal intensity prevents eye strain.
154162

155163
### Example: Status Messages
@@ -275,15 +283,20 @@ String output = builder
275283

276284
### Semantic Color Methods
277285

278-
The builder provides theme-aware semantic colors:
286+
The builder provides theme-aware semantic colors for log levels:
279287

280288
```java
281289
ANSIBuilder builder = ANSIBuilder.builder(cap);
282290

291+
// Log level colors (most to least prominent)
283292
builder.error("Error message"); // Red (bright on dark, normal on light)
284-
builder.success("Success message"); // Green
285293
builder.warning("Warning message"); // Yellow
294+
builder.success("Success message"); // Green
286295
builder.info("Info message"); // Blue
296+
builder.debug("Debug message"); // White/Gray (subdued)
297+
builder.trace("Trace message"); // Gray (least prominent)
298+
299+
// Other semantic colors
287300
builder.timestamp("10:30:45"); // Cyan (subdued, for log timestamps)
288301
builder.message("Highlighted"); // Magenta (for highlighted messages)
289302
```

0 commit comments

Comments
 (0)