@@ -44,7 +44,7 @@ import org.aesh.readline.terminal.TerminalColorDetector;
4444import org.aesh.readline.tty.terminal.TerminalConnection ;
4545
4646TerminalConnection connection = new TerminalConnection ();
47- TerminalColorCapability cap = TerminalColorDetector . detect(connection);
47+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() );
4848
4949System . out. println(" Theme: " + cap. getTheme());
5050System . out. println(" Color depth: " + cap. getColorDepth());
@@ -56,15 +56,15 @@ For repeated access without re-detection overhead:
5656
5757``` java
5858// Detects once and caches for 5 minutes
59- TerminalColorCapability cap = TerminalColorDetector . detectCached(connection);
59+ TerminalColorCapability cap = TerminalColorDetector . detectCached(connection. terminal() );
6060```
6161
6262## TerminalColorCapability
6363
6464The ` TerminalColorCapability ` class encapsulates all detected information:
6565
6666``` java
67- TerminalColorCapability cap = TerminalColorDetector . detect(connection);
67+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() );
6868
6969// Theme detection
7070TerminalTheme theme = cap. getTheme(); // DARK, LIGHT, or UNKNOWN
@@ -100,7 +100,7 @@ The `detect()` method queries (in priority order):
100100Get ANSI color codes that work well with the detected theme:
101101
102102``` java
103- TerminalColorCapability cap = TerminalColorDetector . detect(connection);
103+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() );
104104
105105// These return appropriate codes for the detected background
106106int normalText = cap. getSuggestedForegroundCode(); // 30 (black) or 37 (white)
@@ -140,7 +140,7 @@ You can override the default suggested colors using the `Builder`:
140140
141141``` java
142142// Start with detected capability and customize specific colors
143- TerminalColorCapability detected = TerminalColorDetector . detect(connection);
143+ TerminalColorCapability detected = TerminalColorDetector . detect(connection. terminal() );
144144TerminalColorCapability custom = TerminalColorCapability . builder(detected)
145145 .errorCode(196 ) // Custom 256-color bright red
146146 .successCode(46 ) // Custom 256-color green
@@ -251,7 +251,7 @@ This is based on the [Contour VT extension](https://contour-terminal.org/vt-exte
251251
252252``` java
253253// One-shot query: returns DARK, LIGHT, or null (unsupported/timeout)
254- TerminalTheme theme = connection. queryThemeMode(500 );
254+ TerminalTheme theme = connection. terminal() . queryThemeMode(500 );
255255
256256if (theme != null ) {
257257 System . out. println(" Theme: " + theme);
@@ -264,8 +264,8 @@ if (theme != null) {
264264
265265``` java
266266// Check before querying (avoids timeout on unsupported terminals)
267- if (connection. supportsThemeQuery()) {
268- TerminalTheme theme = connection. queryThemeMode(500 );
267+ if (connection. terminal() . supportsThemeQuery()) {
268+ TerminalTheme theme = connection. terminal() . queryThemeMode(500 );
269269}
270270```
271271
@@ -301,21 +301,21 @@ You can also query colors directly using the `Connection` interface:
301301
302302``` java
303303// Query background color (OSC 11)
304- int [] bg = connection. queryBackgroundColor(500 );
304+ int [] bg = connection. terminal() . queryBackgroundColor(500 );
305305if (bg != null ) {
306306 int r = bg[0 ], g = bg[1 ], b = bg[2 ];
307307 boolean isDark = (r + g + b) / 3 < 128 ;
308308 System . out. println(" Background: RGB(" + r + " ," + g + " ," + b + " )" );
309309}
310310
311311// Query foreground color (OSC 10)
312- int [] fg = connection. queryForegroundColor(500 );
312+ int [] fg = connection. terminal() . queryForegroundColor(500 );
313313
314314// Query cursor color (OSC 12)
315- int [] cursor = connection. queryCursorColor(500 );
315+ int [] cursor = connection. terminal() . queryCursorColor(500 );
316316
317317// Generic OSC query for any code
318- String result = connection. queryOsc(oscCode, " ?" , 500 , responseParser);
318+ String result = connection. terminal() . queryOsc(oscCode, " ?" , 500 , responseParser);
319319```
320320
321321#### Batch Color Queries
@@ -327,18 +327,18 @@ import org.aesh.terminal.tty.TerminalColorDetector;
327327import org.aesh.terminal.utils.ANSI ;
328328
329329// Query foreground, background, and cursor in one operation (~50-100ms vs ~600ms)
330- Map<Integer , int[]> colors = TerminalColorDetector . queryColors(connection, 500 );
330+ Map<Integer , int[]> colors = TerminalColorDetector . queryColors(connection. terminal() , 500 );
331331
332332int [] fg = colors. get(ANSI. OSC_FOREGROUND ); // OSC 10
333333int [] bg = colors. get(ANSI. OSC_BACKGROUND ); // OSC 11
334334int [] cursor = colors. get(ANSI. OSC_CURSOR_COLOR ); // OSC 12
335335
336336// Query multiple palette colors at once
337337Map<Integer , int[]> palette = TerminalColorDetector . queryPaletteColors(
338- connection, 500 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 );
338+ connection. terminal() , 500 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 );
339339
340340// Query all 16 ANSI colors
341- Map<Integer , int[]> ansi16 = TerminalColorDetector . queryAnsi16Colors(connection, 500 );
341+ Map<Integer , int[]> ansi16 = TerminalColorDetector . queryAnsi16Colors(connection. terminal() , 500 );
342342```
343343
344344#### Fallback When OSC Not Supported
@@ -347,7 +347,7 @@ Not all terminals support OSC queries. Use `queryColorsWithFallback()` for grace
347347
348348``` java
349349// Always returns colors - actual or estimated based on environment
350- Map<Integer , int[]> colors = TerminalColorDetector . queryColorsWithFallback(connection, 500 );
350+ Map<Integer , int[]> colors = TerminalColorDetector . queryColorsWithFallback(connection. terminal() , 500 );
351351
352352int [] bg = colors. get(ANSI. OSC_BACKGROUND );
353353// bg is never null - will be estimated if OSC queries failed
@@ -360,17 +360,17 @@ You can also check support before querying:
360360
361361``` java
362362// Check if OSC queries are supported
363- if (TerminalColorDetector . isOscColorQuerySupported(connection)) {
363+ if (TerminalColorDetector . isOscColorQuerySupported(connection. terminal() )) {
364364 // OSC queries will work
365- Map<Integer , int[]> colors = TerminalColorDetector . queryColors(connection, 500 );
365+ Map<Integer , int[]> colors = TerminalColorDetector . queryColors(connection. terminal() , 500 );
366366} else {
367367 // Use environment-based detection
368368 TerminalTheme theme = TerminalColorDetector . detectThemeFromEnvironment();
369369}
370370
371371// Check palette query support specifically
372- if (connection. supportsPaletteQuery()) {
373- Map<Integer , int[]> palette = TerminalColorDetector . queryAnsi16Colors(connection, 500 );
372+ if (connection. terminal() . supportsPaletteQuery()) {
373+ Map<Integer , int[]> palette = TerminalColorDetector . queryAnsi16Colors(connection. terminal() , 500 );
374374}
375375```
376376
@@ -380,16 +380,16 @@ Use DA1 device attributes to determine if OSC queries are likely to work:
380380
381381``` java
382382// Query device attributes first
383- DeviceAttributes da = connection. queryPrimaryDeviceAttributes(500 );
383+ DeviceAttributes da = connection. terminal() . queryPrimaryDeviceAttributes(500 );
384384
385385// Check if OSC queries are likely supported
386- if (connection. supportsOscQueries(da)) {
387- int [] bgColor = connection. queryBackgroundColor(500 );
386+ if (connection. terminal() . supportsOscQueries(da)) {
387+ int [] bgColor = connection. terminal() . queryBackgroundColor(500 );
388388 // ...
389389}
390390
391391// Or use combined query-based check
392- if (connection. querySupportsOscQueries(500 )) {
392+ if (connection. terminal() . querySupportsOscQueries(500 )) {
393393 // Terminal likely supports OSC queries
394394}
395395```
@@ -401,7 +401,7 @@ Terminals that report modern features (ANSI color, Sixel graphics, device class
401401After querying RGB colors, you can convert them to ANSI color codes using the ` ANSI ` utility class:
402402
403403``` java
404- int [] bgColor = connection. queryBackgroundColor(500 );
404+ int [] bgColor = connection. terminal() . queryBackgroundColor(500 );
405405
406406if (bgColor != null ) {
407407 // Convert to 256-color palette index
@@ -533,7 +533,7 @@ The `EventDecoder` in the input pipeline automatically intercepts these unsolici
533533import org.aesh.terminal.utils.TerminalTheme ;
534534
535535// One-call setup: register handler and enable notifications
536- connection. enableThemeChangeNotification(theme - > {
536+ connection. terminal() . enableThemeChangeNotification(theme - > {
537537 System . out. println(" Theme changed to: " + theme);
538538 // Update your cached color capability
539539 capability = new TerminalColorCapability (capability. getColorDepth(), theme);
@@ -549,14 +549,14 @@ connection.setThemeChangeHandler(theme -> {
549549});
550550
551551// Then enable notifications
552- connection. enableThemeChangeNotification();
552+ connection. terminal() . enableThemeChangeNotification();
553553```
554554
555555### Unsubscribing
556556
557557``` java
558558// Stop the terminal from sending notifications
559- connection. disableThemeChangeNotification();
559+ connection. terminal() . disableThemeChangeNotification();
560560
561561// Optionally remove the handler
562562connection. setThemeChangeHandler(null );
@@ -586,7 +586,7 @@ public class AdaptiveColorApp {
586586
587587 public static void main (String [] args ) throws Exception {
588588 TerminalConnection connection = new TerminalConnection ();
589- TerminalColorCapability cap = TerminalColorDetector . detect(connection);
589+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() );
590590
591591 // Get theme-appropriate colors
592592 int error = cap. getSuggestedErrorCode();
@@ -637,7 +637,7 @@ public class MyApp {
637637
638638 public static void main (String [] args ) {
639639 TerminalConnection conn = new TerminalConnection ();
640- colors = TerminalColorDetector . detectCached(conn);
640+ colors = TerminalColorDetector . detectCached(conn. terminal() );
641641 // Use 'colors' throughout the application
642642 }
643643}
@@ -694,7 +694,7 @@ If detection seems to hang:
694694
695695``` java
696696// With custom timeout (milliseconds)
697- TerminalColorCapability cap = TerminalColorDetector . detect(connection, 100 );
697+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() , 100 );
698698```
699699
700700## Using TerminalColor with Detection
@@ -709,7 +709,7 @@ Use semantic factory methods that automatically adjust for the detected terminal
709709import org.aesh.readline.terminal.formatting.TerminalColor ;
710710import org.aesh.terminal.utils.TerminalColorCapability ;
711711
712- TerminalColorCapability cap = TerminalColorDetector . detect(connection);
712+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() );
713713
714714// These methods automatically choose appropriate colors for the theme
715715TerminalColor error = TerminalColor . forError(cap); // Red, bright on dark
@@ -727,7 +727,7 @@ On **dark themes**, these return bright variants for readability. On **light the
727727### Example: Adaptive Status Messages
728728
729729``` java
730- TerminalColorCapability cap = TerminalColorDetector . detectCached(connection);
730+ TerminalColorCapability cap = TerminalColorDetector . detectCached(connection. terminal() );
731731
732732// Create semantic colors once
733733TerminalColor errorColor = TerminalColor . forError(cap);
@@ -749,7 +749,7 @@ connection.write(infoMsg.toString() + "\n");
749749Use ` ANSIBuilder ` for rich log-style output with timestamps:
750750
751751``` java
752- TerminalColorCapability cap = TerminalColorDetector . detect(connection);
752+ TerminalColorCapability cap = TerminalColorDetector . detect(connection. terminal() );
753753ANSIBuilder builder = ANSIBuilder . builder(cap);
754754
755755// Log line with timestamp, level, and message
0 commit comments