Skip to content

Commit c1edd8a

Browse files
committed
added documentation for da1/2 support and DeviceAttribute
1 parent d795dcd commit c1edd8a

6 files changed

Lines changed: 765 additions & 3 deletions

File tree

content/docs/readline/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Think of it this way: Æsh is built **on top of** Æsh Readline. Æsh provides t
4444
- **Remote Connectivity** - SSH, Telnet, and WebSocket terminal servers
4545
- **[Color Detection](color-detection)** - Automatic terminal theme and color depth detection
4646
- **[Terminal Colors](terminal-colors)** - RGB colors, theme-aware styling, and color depth adaptation
47+
- **[Device Attributes](device-attributes)** - DA1/DA2 terminal capability queries
48+
- **[Terminal Images](terminal-images)** - Sixel, Kitty, and iTerm2 inline image support
4749

4850
## Architecture
4951

content/docs/readline/color-detection.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,51 @@ This works with most modern terminal emulators including:
234234
- GNOME Terminal, Konsole, xterm
235235
- Windows Terminal
236236

237+
#### Direct Color Queries via Connection
238+
239+
You can also query colors directly using the `Connection` interface:
240+
241+
```java
242+
// Query background color (OSC 11)
243+
int[] bg = connection.queryBackgroundColor(500);
244+
if (bg != null) {
245+
int r = bg[0], g = bg[1], b = bg[2];
246+
boolean isDark = (r + g + b) / 3 < 128;
247+
System.out.println("Background: RGB(" + r + "," + g + "," + b + ")");
248+
}
249+
250+
// Query foreground color (OSC 10)
251+
int[] fg = connection.queryForegroundColor(500);
252+
253+
// Query cursor color (OSC 12)
254+
int[] cursor = connection.queryCursorColor(500);
255+
256+
// Generic OSC query for any code
257+
String result = connection.queryOsc(oscCode, "?", 500, responseParser);
258+
```
259+
260+
#### OSC Support Detection with Device Attributes
261+
262+
Use DA1 device attributes to determine if OSC queries are likely to work:
263+
264+
```java
265+
// Query device attributes first
266+
DeviceAttributes da = connection.queryPrimaryDeviceAttributes(500);
267+
268+
// Check if OSC queries are likely supported
269+
if (connection.supportsOscQueries(da)) {
270+
int[] bgColor = connection.queryBackgroundColor(500);
271+
// ...
272+
}
273+
274+
// Or use combined query-based check
275+
if (connection.querySupportsOscQueries(500)) {
276+
// Terminal likely supports OSC queries
277+
}
278+
```
279+
280+
Terminals that report modern features (ANSI color, Sixel graphics, device class >= 62) typically support OSC queries.
281+
237282
### 2. Environment Variables
238283

239284
Checks standard environment variables:

content/docs/readline/connection.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,186 @@ Point position = connection.getCursorPosition();
161161
int row = position.getRow();
162162
int col = position.getColumn();
163163
```
164+
165+
## OSC Queries
166+
167+
OSC (Operating System Command) queries allow you to interrogate the terminal for information like colors, clipboard content, and more.
168+
169+
### Generic OSC Query
170+
171+
Send any OSC query with a custom response parser:
172+
173+
```java
174+
// Query palette color 4 with custom parser
175+
String result = connection.queryOsc(4, "?", 500, input -> {
176+
// Custom parsing logic
177+
return parseColorResponse(input);
178+
});
179+
```
180+
181+
### Color Queries
182+
183+
Query the terminal's current colors:
184+
185+
```java
186+
// Query foreground color (OSC 10)
187+
int[] fg = connection.queryForegroundColor(500);
188+
if (fg != null) {
189+
System.out.println("Foreground: RGB(" + fg[0] + "," + fg[1] + "," + fg[2] + ")");
190+
}
191+
192+
// Query background color (OSC 11)
193+
int[] bg = connection.queryBackgroundColor(500);
194+
if (bg != null) {
195+
System.out.println("Background: RGB(" + bg[0] + "," + bg[1] + "," + bg[2] + ")");
196+
}
197+
198+
// Query cursor color (OSC 12)
199+
int[] cursor = connection.queryCursorColor(500);
200+
```
201+
202+
### OSC Support Detection
203+
204+
Check if the terminal supports OSC queries:
205+
206+
```java
207+
// Basic heuristic check
208+
boolean supportsOsc = connection.supportsOscQueries();
209+
210+
// More accurate check using Device Attributes
211+
DeviceAttributes attrs = connection.queryPrimaryDeviceAttributes(500);
212+
boolean supportsOsc = connection.supportsOscQueries(attrs);
213+
214+
// Query-based check (sends DA1 query)
215+
boolean supportsOsc = connection.querySupportsOscQueries(500);
216+
```
217+
218+
## Device Attributes (DA1/DA2)
219+
220+
Device Attributes queries allow you to detect terminal capabilities that cannot be determined from terminfo alone.
221+
222+
### Primary Device Attributes (DA1)
223+
224+
Query the terminal's conformance level and supported features:
225+
226+
```java
227+
DeviceAttributes da = connection.queryPrimaryDeviceAttributes(500);
228+
229+
if (da != null) {
230+
// Device class (1=VT100, 62=VT220, 64=VT420, etc.)
231+
int deviceClass = da.getDeviceClass();
232+
233+
// Check specific features
234+
boolean hasSixel = da.supportsSixel();
235+
boolean hasAnsiColor = da.supportsAnsiColor();
236+
boolean hasMouse = da.supportsMouse();
237+
boolean has132Cols = da.supports132Columns();
238+
239+
// Check any feature by enum
240+
if (da.hasFeature(DeviceAttributes.Feature.RECTANGULAR_EDITING)) {
241+
// Terminal supports rectangular editing operations
242+
}
243+
}
244+
```
245+
246+
### Secondary Device Attributes (DA2)
247+
248+
Query terminal identification and version information:
249+
250+
```java
251+
DeviceAttributes da = connection.querySecondaryDeviceAttributes(500);
252+
253+
if (da != null) {
254+
// Terminal type (VT100, VT220, VT420, etc.)
255+
DeviceAttributes.TerminalType type = da.getTerminalType();
256+
257+
// Firmware/version number
258+
int version = da.getFirmwareVersion();
259+
260+
System.out.println("Terminal: " + type.getName() + " v" + version);
261+
}
262+
```
263+
264+
### Combined Query
265+
266+
Query both DA1 and DA2 and merge the results:
267+
268+
```java
269+
DeviceAttributes da = connection.queryDeviceAttributes(500);
270+
271+
if (da != null) {
272+
// Has both DA1 and DA2 data
273+
System.out.println("Class: " + da.getDeviceClass());
274+
System.out.println("Type: " + da.getTerminalType().getName());
275+
System.out.println("Features: " + da.getFeatures());
276+
}
277+
```
278+
279+
### Available Features
280+
281+
The `DeviceAttributes.Feature` enum includes:
282+
283+
| Feature | Code | Description |
284+
|---------|------|-------------|
285+
| `COLUMNS_132` | 1 | 132-column mode |
286+
| `PRINTER` | 2 | Printer port |
287+
| `REGIS_GRAPHICS` | 3 | ReGIS graphics |
288+
| `SIXEL` | 4 | Sixel graphics |
289+
| `SELECTIVE_ERASE` | 6 | Selective erase |
290+
| `DRCS` | 7 | Soft character set |
291+
| `USER_DEFINED_KEYS` | 8 | User-defined keys |
292+
| `NATIONAL_CHARSETS` | 9 | National character sets |
293+
| `LOCATOR` | 16 | DEC locator (mouse) |
294+
| `ANSI_COLOR` | 22 | ANSI color support |
295+
| `RECTANGULAR_EDITING` | 28 | Rectangular editing |
296+
| `ANSI_TEXT_LOCATOR` | 29 | ANSI text locator (mouse) |
297+
298+
## Image Protocol Detection
299+
300+
Detect the terminal's image protocol support using DA1 attributes:
301+
302+
```java
303+
// Query-based detection (most accurate)
304+
ImageProtocol protocol = connection.queryImageProtocol(500);
305+
306+
switch (protocol) {
307+
case KITTY:
308+
// Use Kitty graphics protocol
309+
break;
310+
case ITERM2:
311+
// Use iTerm2 inline images
312+
break;
313+
case SIXEL:
314+
// Use Sixel graphics
315+
break;
316+
case NONE:
317+
// No image support detected
318+
break;
319+
}
320+
```
321+
322+
For faster (but less accurate) detection without querying:
323+
324+
```java
325+
Device device = connection.device();
326+
ImageProtocol protocol = device.getImageProtocol();
327+
```
328+
329+
## Color Capabilities
330+
331+
Get terminal color information:
332+
333+
```java
334+
// Get color depth from terminfo or environment
335+
ColorDepth depth = connection.getColorDepth();
336+
337+
if (depth.supportsTrueColor()) {
338+
// Use 24-bit RGB colors
339+
} else if (depth.supports256Colors()) {
340+
// Use 256-color palette
341+
}
342+
343+
// Get full color capability info
344+
TerminalColorCapability cap = connection.getColorCapability();
345+
TerminalTheme theme = cap.getTheme();
346+
```

0 commit comments

Comments
 (0)