Skip to content

Commit dd0dc93

Browse files
committed
Document Connection sub-interface architecture
Updated connection.md to reflect the extraction of Connection into TerminalQueryable, TerminalCapabilities, and TerminalWriter sub-interfaces. Added architecture diagram and annotated section headers with their corresponding sub-interface.
1 parent bfb9885 commit dd0dc93

1 file changed

Lines changed: 47 additions & 9 deletions

File tree

content/docs/readline/connection.md

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,44 @@ weight: 9
77

88
The `Connection` interface represents a connection to a terminal (local, direct, or remote).
99

10+
## Interface Structure
11+
12+
`Connection` extends three focused sub-interfaces, each covering a distinct area of responsibility:
13+
14+
```
15+
┌─────────────────────────────────────────────┐
16+
│ Connection │
17+
│ (Core I/O, handlers, write) │
18+
│ │
19+
│ extends ┌────────────────────────────────┐ │
20+
│ │ TerminalQueryable │ │
21+
│ │ queryTerminal(), queryOsc(), │ │
22+
│ │ queryColors(), DA1/DA2, ... │ │
23+
│ └────────────────────────────────┘ │
24+
│ │
25+
│ extends ┌────────────────────────────────┐ │
26+
│ │ TerminalCapabilities │ │
27+
│ │ supports*(), getColorDepth(), │ │
28+
│ │ getTerminalType(), ... │ │
29+
│ └────────────────────────────────┘ │
30+
│ │
31+
│ extends ┌────────────────────────────────┐ │
32+
│ │ TerminalWriter │ │
33+
│ │ writePrompt*(), writeHyper- │ │
34+
│ │ link(), writeClipboard(), │ │
35+
│ │ enable/disable modes, ... │ │
36+
│ └────────────────────────────────┘ │
37+
└─────────────────────────────────────────────┘
38+
```
39+
40+
| Sub-Interface | Responsibility | Methods |
41+
|---------------|---------------|---------|
42+
| `TerminalQueryable` | Terminal queries (OSC, DA1/DA2, DECRQM, batch queries) | `queryTerminal()`, `queryOsc()`, `queryColors()`, `queryThemeMode()`, `getCursorPosition()`, ... |
43+
| `TerminalCapabilities` | Heuristic capability detection (no queries sent) | `supports*()`, `getTerminalType()`, `getColorDepth()`, `getColorCapability()` |
44+
| `TerminalWriter` | Semantic output and mode management | `writePromptStart()`, `writeHyperlink()`, `writeClipboard()`, `enableSynchronizedOutput()`, ... |
45+
46+
All methods remain accessible through `Connection` — the sub-interfaces simply provide clearer organization. Existing code that uses `Connection` does not need to change.
47+
1048
## Creating Connections
1149

1250
### Local Terminal Connection
@@ -196,9 +234,9 @@ int row = position.getRow();
196234
int col = position.getColumn();
197235
```
198236

199-
## OSC Queries
237+
## OSC Queries (`TerminalQueryable`)
200238

201-
OSC (Operating System Command) queries allow you to interrogate the terminal for information like colors, clipboard content, and more.
239+
OSC (Operating System Command) queries allow you to interrogate the terminal for information like colors, clipboard content, and more. These methods are defined in the `TerminalQueryable` sub-interface.
202240

203241
### Generic OSC Query
204242

@@ -267,7 +305,7 @@ int[] rgb = connection.queryOsc(4, 1, "?", 500,
267305
input -> ANSI.parseOscColorResponse(input, 4, 1));
268306
```
269307
270-
### OSC Support Detection
308+
### OSC Support Detection (`TerminalCapabilities`)
271309
272310
Not all terminals support all OSC queries. For example, JetBrains IDE terminals
273311
don't support OSC 4 (palette queries). Use the `Device` enums to check
@@ -349,7 +387,7 @@ Map<Integer, int[]> colors = TerminalColorDetector.queryColorsWithFallback(conne
349387
// Always returns colors - actual if OSC works, estimated if not
350388
```
351389

352-
## Theme Mode Queries
390+
## Theme Mode Queries (`TerminalQueryable` + `TerminalWriter`)
353391

354392
The `Connection` interface provides methods for querying and subscribing to terminal theme changes using the `CSI ? 996 n` protocol. This is simpler and faster than OSC 10/11 RGB queries — it returns a direct `DARK` or `LIGHT` answer.
355393

@@ -452,7 +490,7 @@ connection.setThemeChangeHandler(null);
452490
connection.close();
453491
```
454492

455-
## Synchronized Output (Mode 2026)
493+
## Synchronized Output (`TerminalWriter` + `TerminalCapabilities`)
456494

457495
Synchronized output prevents screen tearing by telling the terminal to buffer all output until the frame is complete. See [Synchronized Output](synchronized-output) for full documentation.
458496

@@ -471,7 +509,7 @@ Boolean supported = connection.querySynchronizedOutput(500);
471509

472510
Synchronized output is automatically managed by `Readline` for supporting terminals. Use the `ReadlineFlag.NO_SYNCHRONIZED_OUTPUT` flag to opt out.
473511

474-
## Device Attributes (DA1/DA2)
512+
## Device Attributes (`TerminalQueryable`)
475513

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

@@ -551,7 +589,7 @@ The `DeviceAttributes.Feature` enum includes:
551589
| `RECTANGULAR_EDITING` | 28 | Rectangular editing |
552590
| `ANSI_TEXT_LOCATOR` | 29 | ANSI text locator (mouse) |
553591
554-
## Image Protocol Detection
592+
## Image Protocol Detection (`TerminalQueryable`)
555593
556594
Detect the terminal's image protocol support using DA1 attributes:
557595

@@ -582,7 +620,7 @@ Device device = connection.device();
582620
ImageProtocol protocol = device.getImageProtocol();
583621
```
584622

585-
## Clipboard (OSC 52)
623+
## Clipboard (`TerminalWriter` + `TerminalCapabilities`)
586624

587625
Copy text to the system clipboard using OSC 52. This is a write-only operation. See [Clipboard](clipboard) for full documentation.
588626

@@ -595,7 +633,7 @@ if (connection.supportsClipboard()) {
595633

596634
Clipboard writing is automatically managed by `Readline` for supporting terminals. Use the `ReadlineFlag.NO_CLIPBOARD` flag to opt out.
597635

598-
## Color Capabilities
636+
## Color Capabilities (`TerminalCapabilities` + `TerminalQueryable`)
599637

600638
Get terminal color information:
601639

0 commit comments

Comments
 (0)