@@ -127,24 +127,28 @@ import org.aesh.terminal.utils.TerminalColorCapability;
127127TerminalColorCapability cap = TerminalColorDetector . detect(connection);
128128
129129// Get theme-appropriate colors
130- TerminalColor error = TerminalColor . forError(cap); // Red
131- TerminalColor success = TerminalColor . forSuccess(cap); // Green
132- TerminalColor warning = TerminalColor . forWarning(cap); // Yellow
133- TerminalColor info = TerminalColor . forInfo(cap); // Cyan/Blue
130+ TerminalColor error = TerminalColor . forError(cap); // Red
131+ TerminalColor success = TerminalColor . forSuccess(cap); // Green
132+ TerminalColor warning = TerminalColor . forWarning(cap); // Yellow
133+ TerminalColor info = TerminalColor . forInfo(cap); // Cyan/Blue
134134TerminalColor highlight = TerminalColor . forHighlight(cap); // Emphasized
135- TerminalColor muted = TerminalColor . forMuted(cap); // Dimmed
135+ TerminalColor muted = TerminalColor . forMuted(cap); // Dimmed
136+ TerminalColor timestamp = TerminalColor . forTimestamp(cap); // Cyan (for log timestamps)
137+ TerminalColor message = TerminalColor . forMessage(cap); // Magenta (for highlighted messages)
136138```
137139
138140### How Theme Adaptation Works
139141
140- | Method | Dark Theme | Light Theme |
141- | --------| ------------| -------------|
142- | ` forError() ` | Bright red | Normal red |
143- | ` forSuccess() ` | Bright green | Normal green |
144- | ` forWarning() ` | Bright yellow | Normal yellow |
145- | ` forInfo() ` | Bright cyan | Normal blue |
146- | ` forHighlight() ` | Bright white | Black |
147- | ` forMuted() ` | Normal white | Normal black |
142+ | Method | Dark Theme | Light Theme | Use Case |
143+ | --------| ------------| -------------| ----------|
144+ | ` forError() ` | Bright red | Normal red | Error messages |
145+ | ` forSuccess() ` | Bright green | Normal green | Success messages |
146+ | ` forWarning() ` | Bright yellow | Normal yellow | Warnings |
147+ | ` forInfo() ` | Bright cyan | Normal blue | Info messages |
148+ | ` forHighlight() ` | Bright white | Black | Emphasized text |
149+ | ` forMuted() ` | Normal white | Normal black | Secondary text |
150+ | ` forTimestamp() ` | Bright cyan | Normal cyan | Log timestamps |
151+ | ` forMessage() ` | Bright magenta | Normal magenta | Highlighted messages |
148152
149153These methods ensure readable colors on any background. On dark themes, bright colors stand out. On light themes, normal intensity prevents eye strain.
150154
@@ -235,22 +239,166 @@ connection.write(colored.toString());
235239
236240## Using with ANSIBuilder
237241
238- For more complex formatting, use ` ANSIBuilder ` :
242+ For more complex formatting, use ` ANSIBuilder ` . It provides a fluent API for building ANSI-formatted strings with support for basic colors, 256-color palette, true color RGB, and theme-aware semantic colors.
243+
244+ ### Basic Usage
239245
240246``` java
241- import org.aesh.readline.util .ANSIBuilder ;
247+ import org.aesh.terminal.utils .ANSIBuilder ;
242248
243249String output = ANSIBuilder . builder()
244- .red() . text( " Error: " ) . reset( )
245- .text (" Something went wrong" )
250+ .redText( " Error: " )
251+ .append (" Something went wrong" )
246252 .toString();
247253
248- // With RGB (where supported)
249- String rgbOutput = ANSIBuilder . builder()
250- .trueColor( 255 , 87 , 51 ) . text( " Orange text" ) . reset( )
254+ // Bold and colors
255+ String styled = ANSIBuilder . builder()
256+ .bold( " Title: " ) . append( " Some text" )
251257 .toString();
252258```
253259
260+ ### Theme-Aware Builder
261+
262+ Create a builder with detected terminal capabilities for automatic theme adaptation:
263+
264+ ``` java
265+ TerminalColorCapability cap = TerminalColorDetector . detect(connection);
266+ ANSIBuilder builder = ANSIBuilder . builder(cap);
267+
268+ // Semantic colors adapt to the terminal theme
269+ String output = builder
270+ .timestamp(" 2024-01-15 10:30:45" ). append(" " )
271+ .success(" [INFO]" ). append(" " )
272+ .message(" Application started" )
273+ .toString();
274+ ```
275+
276+ ### Semantic Color Methods
277+
278+ The builder provides theme-aware semantic colors:
279+
280+ ``` java
281+ ANSIBuilder builder = ANSIBuilder . builder(cap);
282+
283+ builder. error(" Error message" ); // Red (bright on dark, normal on light)
284+ builder. success(" Success message" ); // Green
285+ builder. warning(" Warning message" ); // Yellow
286+ builder. info(" Info message" ); // Blue
287+ builder. timestamp(" 10:30:45" ); // Cyan (subdued, for log timestamps)
288+ builder. message(" Highlighted" ); // Magenta (for highlighted messages)
289+ ```
290+
291+ ### Extended Color Support
292+
293+ #### 256-Color Palette
294+
295+ ``` java
296+ // Foreground color from 256-color palette
297+ builder. color256(208 ). append(" Orange text" );
298+
299+ // Background color from 256-color palette
300+ builder. bg256(17 ). append(" Blue background" );
301+
302+ // With text directly
303+ builder. color256(196 , " Red text" );
304+ ```
305+
306+ #### True Color (24-bit RGB)
307+
308+ ``` java
309+ // RGB foreground
310+ builder. rgb(255 , 87 , 51 ). append(" Orange text" );
311+
312+ // RGB background
313+ builder. bgRgb(30 , 30 , 30 ). append(" Dark background" );
314+
315+ // From hex string
316+ builder. hex(" #FF5733" ). append(" Coral text" );
317+ builder. bgHex(" #1E1E1E" ). append(" Dark background" );
318+ ```
319+
320+ #### Bright Colors
321+
322+ ``` java
323+ // Enable bright mode for the next color
324+ builder. bright(). redText(). append(" Bright red" );
325+
326+ // Turn off bright mode
327+ builder. brightOff();
328+ ```
329+
330+ ### Convenience Methods
331+
332+ ``` java
333+ // toLine() - returns string with newline appended
334+ connection. write(builder. error(" Error occurred" ). toLine());
335+
336+ // appendLine() - appends text with newline, returns builder
337+ builder. appendLine(" Line 1" ). appendLine(" Line 2" );
338+
339+ // reset() or clear() - clears builder for reuse
340+ builder. reset();
341+ builder. success(" New content" );
342+ ```
343+
344+ ### Reusing the Builder
345+
346+ For efficiency, reuse a single builder instance:
347+
348+ ``` java
349+ ANSIBuilder builder = ANSIBuilder . builder(cap);
350+
351+ // First message
352+ connection. write(builder. error(" Error occurred" ). toLine());
353+
354+ // Reset and reuse for next message
355+ builder. reset();
356+ connection. write(builder. success(" Operation completed" ). toLine());
357+
358+ // Reset and reuse again
359+ builder. reset();
360+ connection. write(builder
361+ .timestamp(" 10:30:45" ). append(" " )
362+ .info(" [INFO]" ). append(" " )
363+ .message(" Processing..." )
364+ .toLine());
365+ ```
366+
367+ ### Complete Example
368+
369+ ``` java
370+ TerminalColorCapability cap = TerminalColorDetector . detect(connection);
371+ ANSIBuilder builder = ANSIBuilder . builder(cap);
372+
373+ // Log-style output with timestamps
374+ connection. write(builder
375+ .timestamp(" 2024-01-15 10:30:45" ). append(" " )
376+ .success(" [INFO]" ). append(" " )
377+ .message(" Application started" )
378+ .toLine());
379+
380+ builder. reset();
381+ connection. write(builder
382+ .timestamp(" 2024-01-15 10:30:46" ). append(" " )
383+ .warning(" [WARN]" ). append(" " )
384+ .append(" Low memory condition" )
385+ .toLine());
386+
387+ builder. reset();
388+ connection. write(builder
389+ .timestamp(" 2024-01-15 10:30:47" ). append(" " )
390+ .error(" [ERROR]" ). append(" " )
391+ .append(" Connection failed" )
392+ .toLine());
393+
394+ // Using 256-color for custom branding
395+ builder. reset();
396+ connection. write(builder
397+ .color256(208 , " MyApp" ). append(" : " )
398+ .append(" Custom colored branding" )
399+ .toLine());
400+ ```
401+
254402## Complete Example
255403
256404``` java
@@ -327,6 +475,8 @@ public class ColorfulApp {
327475| ` forInfo(cap) ` | Theme-aware cyan/blue for info |
328476| ` forHighlight(cap) ` | Theme-aware emphasis color |
329477| ` forMuted(cap) ` | Theme-aware secondary text color |
478+ | ` forTimestamp(cap) ` | Theme-aware cyan for log timestamps |
479+ | ` forMessage(cap) ` | Theme-aware magenta for highlighted messages |
330480
331481### Instance Methods
332482
0 commit comments