@@ -161,3 +161,186 @@ Point position = connection.getCursorPosition();
161161int row = position. getRow();
162162int 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