Skip to content

Commit 4678dcd

Browse files
committed
added docs to describe the improvement for device and terminal detection
1 parent bad05d9 commit 4678dcd

7 files changed

Lines changed: 640 additions & 12 deletions

File tree

content/docs/readline/_index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Think of it this way: Æsh is built **on top of** Æsh Readline. Æsh provides t
4242
- **Stream Support** - Standard out and standard error handling
4343
- **Shell Features** - Redirect, alias, and pipeline support
4444
- **Remote Connectivity** - SSH, Telnet, and WebSocket terminal servers
45+
- **[Terminal Environment](terminal-environment)** - Centralized terminal detection (type, color depth, multiplexers)
4546
- **[Color Detection](color-detection)** - Automatic terminal theme and color depth detection
4647
- **[Terminal Colors](terminal-colors)** - RGB colors, theme-aware styling, and color depth adaptation
4748
- **[Device Attributes](device-attributes)** - DA1/DA2 terminal capability queries

content/docs/readline/color-detection.md

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,20 @@ See [Terminal Colors](terminal-colors#ansi-color-utilities) for complete documen
305305

306306
### 2. Environment Variables
307307

308-
Checks standard environment variables:
308+
Checks standard environment variables via [`TerminalEnvironment`](terminal-environment):
309309

310310
| Variable | Example | Meaning |
311311
|----------|---------|---------|
312312
| `COLORFGBG` | `15;0` | Foreground;Background color indices |
313313
| `COLORTERM` | `truecolor` | Color depth hint |
314314
| `APPLE_INTERFACE_STYLE` | `Dark` | macOS dark mode |
315+
| `TERM_PROGRAM` | `iTerm.app` | Terminal program identifier |
316+
| `KITTY_WINDOW_ID` | `1` | Kitty terminal indicator |
317+
| `ITERM_SESSION_ID` | `w0t0p0` | iTerm2 session indicator |
318+
| `WEZTERM_PANE` | `0` | WezTerm terminal indicator |
319+
| `GHOSTTY_RESOURCES_DIR` | `/path` | Ghostty terminal indicator |
320+
321+
The `TerminalEnvironment` class parses these once and caches the results. See [Terminal Environment](terminal-environment) for details on all supported environment variables and terminal types.
315322

316323
### 3. Terminal-Specific Detection
317324

@@ -346,17 +353,31 @@ Queries the Windows registry for `AppsUseLightTheme`.
346353

347354
## Multiplexer Support (tmux/screen)
348355

349-
When running inside tmux or GNU Screen, color detection requires special handling:
356+
When running inside tmux or GNU Screen, color detection requires special handling. The [`TerminalEnvironment`](terminal-environment) class provides centralized multiplexer detection:
350357

351358
```java
359+
import org.aesh.terminal.utils.TerminalEnvironment;
360+
361+
TerminalEnvironment env = TerminalEnvironment.getInstance();
362+
352363
// Check if running in a multiplexer
353-
if (TerminalColorDetector.isRunningInTmux()) {
364+
if (env.isInTmux()) {
354365
System.out.println("Running inside tmux");
355366
}
356367

357-
if (TerminalColorDetector.isRunningInMultiplexer()) {
368+
if (env.isInMultiplexer()) {
358369
System.out.println("Running inside tmux or screen");
359370
}
371+
372+
// Check if passthrough is enabled
373+
if (env.isTmuxPassthroughEnabled()) {
374+
System.out.println("OSC passthrough is enabled");
375+
}
376+
377+
// Legacy static methods still work
378+
if (TerminalColorDetector.isRunningInTmux()) {
379+
System.out.println("Running inside tmux");
380+
}
360381
```
361382

362383
### tmux Passthrough

content/docs/readline/connection.md

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -235,20 +235,53 @@ int[] rgb = connection.queryOsc(4, 1, "?", 500,
235235
236236
### OSC Support Detection
237237
238-
Check if the terminal supports OSC queries:
238+
Not all terminals support all OSC queries. For example, JetBrains IDE terminals
239+
don't support OSC 4 (palette queries). Use the `Device` enums to check
240+
terminal capabilities before querying:
239241

240242
```java
241-
// Basic heuristic check
242-
boolean supportsOsc = connection.supportsOscQueries();
243+
import org.aesh.terminal.Device.TerminalType;
244+
import org.aesh.terminal.Device.OscCode;
243245

244-
// More accurate check using Device Attributes
245-
DeviceAttributes attrs = connection.queryPrimaryDeviceAttributes(500);
246-
boolean supportsOsc = connection.supportsOscQueries(attrs);
246+
// Detect terminal type from environment
247+
TerminalType termType = connection.getTerminalType();
248+
System.out.println("Terminal: " + termType.getIdentifier());
247249

248-
// Query-based check (sends DA1 query)
249-
boolean supportsOsc = connection.querySupportsOscQueries(500);
250+
// Check specific OSC support
251+
if (connection.supportsPaletteQuery()) {
252+
int[] color = connection.queryPaletteColor(1, 500);
253+
// Use color...
254+
}
255+
256+
// Or use the convenience method that checks support first
257+
int[] color = connection.queryPaletteColorIfSupported(1, 500);
258+
if (color != null) {
259+
// Terminal supports OSC 4 and returned a color
260+
}
261+
262+
// Check for OSC 10/11 support
263+
if (connection.supportsColorQuery()) {
264+
int[] fg = connection.queryForegroundColor(500);
265+
int[] bg = connection.queryBackgroundColor(500);
266+
}
267+
268+
// Check if running in JetBrains IDE
269+
Device device = connection.device();
270+
if (device != null && device.isJetBrainsTerminal()) {
271+
// Use fallback approach for palette colors
272+
}
273+
274+
// Check for any OSC code support
275+
if (connection.supportsOscCode(OscCode.CLIPBOARD)) {
276+
// Terminal supports clipboard access via OSC 52
277+
}
250278
```
251279

280+
Known terminal limitations:
281+
- **JetBrains IDEs**: No OSC 4 (palette) support
282+
- **Linux console**: No OSC query support
283+
- **Alacritty**: No OSC 52 (clipboard) support
284+
252285
## Device Attributes (DA1/DA2)
253286

254287
Device Attributes queries allow you to detect terminal capabilities that cannot be determined from terminfo alone.

content/docs/readline/device-attributes.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,95 @@ if (da != null) {
282282
}
283283
```
284284

285+
## Synergy with Terminal Environment
286+
287+
The `DeviceAttributes` class provides synergy methods that work with [`TerminalEnvironment`](terminal-environment) and `Device.TerminalType` for comprehensive terminal detection:
288+
289+
### Inferring Terminal Type from DA
290+
291+
```java
292+
import org.aesh.terminal.Device;
293+
import org.aesh.terminal.utils.TerminalEnvironment;
294+
295+
// Heuristic detection (fast, always available)
296+
Device.TerminalType heuristicType = TerminalEnvironment.detectTerminalType();
297+
298+
// Authoritative detection from DA1/DA2
299+
DeviceAttributes da = connection.queryDeviceAttributes(500);
300+
if (da != null) {
301+
Device.TerminalType authType = da.inferTerminalType();
302+
System.out.println("Inferred type: " + authType.getIdentifier());
303+
}
304+
```
305+
306+
### Validating Terminal Type
307+
308+
Verify that heuristic detection matches actual capabilities:
309+
310+
```java
311+
Device.TerminalType envType = TerminalEnvironment.detectTerminalType();
312+
DeviceAttributes da = connection.queryDeviceAttributes(500);
313+
314+
if (da != null && !da.matchesTerminalType(envType)) {
315+
System.out.println("Warning: Terminal capabilities differ from expected for " +
316+
envType.getIdentifier());
317+
}
318+
```
319+
320+
### Inferring Color Depth
321+
322+
Get authoritative color depth from DA1:
323+
324+
```java
325+
DeviceAttributes da = connection.queryDeviceAttributes(500);
326+
if (da != null) {
327+
ColorDepth depth = da.inferColorDepth();
328+
System.out.println("Color depth: " + depth);
329+
}
330+
```
331+
332+
### Capability Summary
333+
334+
Generate a comprehensive capabilities report:
335+
336+
```java
337+
Device.TerminalType envType = TerminalEnvironment.detectTerminalType();
338+
DeviceAttributes da = connection.queryDeviceAttributes(500);
339+
340+
if (da != null) {
341+
String summary = da.getCapabilitySummary(envType);
342+
System.out.println(summary);
343+
}
344+
```
345+
346+
Output example:
347+
```
348+
Terminal: kitty
349+
DA1 Class: 64
350+
DA2 Type: VT420
351+
352+
Capabilities:
353+
Color Depth: COLORS_256
354+
Sixel Graphics: Yes
355+
ANSI Color: Yes
356+
Mouse Support: Yes
357+
OSC Queries: Likely
358+
```
359+
360+
### Expected Features by Terminal Type
361+
362+
Each `Device.TerminalType` knows its expected DA1 features:
363+
364+
```java
365+
// Get expected features for a terminal type
366+
Set<DeviceAttributes.Feature> expected = Device.TerminalType.KITTY.getExpectedFeatures();
367+
// Contains: SIXEL, ANSI_COLOR, ANSI_TEXT_LOCATOR
368+
369+
// Convenience methods
370+
boolean expectsSixel = Device.TerminalType.KITTY.expectsSixel(); // true
371+
boolean expectsMouse = Device.TerminalType.XTERM.expectsMouse(); // true
372+
```
373+
285374
## Common DA1 Response Patterns
286375

287376
Different terminals return different DA1 responses:

0 commit comments

Comments
 (0)