Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

feat(desktop): open terminal hyperlinks and underline them on hover (#333)

Dev at Autonomousc1f8f6683082
diff --git a/desktop/lib/terminal/terminal_links.dart b/desktop/lib/terminal/terminal_links.dart
index be6594d34..20685c82a 100644
--- a/desktop/lib/terminal/terminal_links.dart
+++ b/desktop/lib/terminal/terminal_links.dart
@@ -336,6 +336,18 @@ String? terminalLinkAt(Terminal terminal, CellOffset cell) {
cell.x >= lines[cell.y].length) {
return null;
}
+ // An OSC 8 hyperlink names its target outright — Claude Code prints a
+ // markdown link `[!125](https://…)` as just `!125` and hides the address
+ // there — so it wins over anything read off the visible text.
+ final hyperlink = lines[cell.y].getHyperlink(cell.x);
+ if (hyperlink != null) {
+ final uri = Uri.tryParse(hyperlink);
+ if (uri != null &&
+ (uri.scheme == 'http' || uri.scheme == 'https') &&
+ uri.host.isNotEmpty) {
+ return hyperlink;
+ }
+ }
final own = _logicalLine(terminal, cell.y, cell);
if (own == null || own.offset == null) return null;
final single = terminalLinkInText(own.text, own.offset!);
@@ -392,3 +404,70 @@ String? terminalLinkAt(Terminal terminal, CellOffset cell) {
final scheme = Uri.tryParse(target)?.scheme;
return scheme == 'http' || scheme == 'https' ? target : single;
}
+
+/// One row's run of cells, [start] to [end] inclusive, that opens a link.
+typedef TerminalLinkSpan = ({int row, int start, int end});
+
+/// The cells that open [target], walked out from [cell] — what a hover
+/// underlines. An OSC 8 link is exactly the cells that carry it; a link read
+/// off the text is the run of cells [terminalLinkAt] resolves to [target],
+/// followed onto the rows above and below when it reaches their edge (a
+/// wrapped address continues at the next row's indent).
+List<TerminalLinkSpan> terminalLinkSpans(
+ Terminal terminal,
+ CellOffset cell,
+ String target,
+) {
+ final lines = terminal.buffer.lines;
+ if (cell.y < 0 || cell.y >= lines.length) return const [];
+ final osc8 = lines[cell.y].getHyperlink(cell.x) == target;
+ bool hit(int x, int y) => osc8
+ ? lines[y].getHyperlink(x) == target
+ : terminalLinkAt(terminal, CellOffset(x, y)) == target;
+ TerminalLinkSpan? walk(int y, int x) {
+ if (y < 0 || y >= lines.length || x < 0 || !hit(x, y)) return null;
+ final width = lines[y].length;
+ var start = x;
+ var end = x;
+ while (start > 0 && hit(start - 1, y)) {
+ start--;
+ }
+ while (end + 1 < width && hit(end + 1, y)) {
+ end++;
+ }
+ return (row: y, start: start, end: end);
+ }
+
+ int firstVisible(BufferLine line) {
+ for (var x = 0; x < line.length; x++) {
+ final codePoint = line.getCodePoint(x);
+ if (codePoint != 0 && codePoint != 0x20) return x;
+ }
+ return line.length;
+ }
+
+ final own = walk(cell.y, cell.x);
+ if (own == null) return const [];
+ final spans = [own];
+ var head = own;
+ while (spans.length < _hardWrapRows &&
+ head.start <= firstVisible(lines[head.row])) {
+ final above = head.row - 1;
+ if (above < 0) break;
+ final span = walk(above, _visibleWidth(lines[above]) - 1);
+ if (span == null) break;
+ spans.insert(0, span);
+ head = span;
+ }
+ var tail = own;
+ while (spans.length < _hardWrapRows * 2 &&
+ tail.end >= _visibleWidth(lines[tail.row]) - 1) {
+ final below = tail.row + 1;
+ if (below >= lines.length) break;
+ final span = walk(below, firstVisible(lines[below]));
+ if (span == null) break;
+ spans.add(span);
+ tail = span;
+ }
+ return spans;
+}
diff --git a/desktop/lib/widgets/terminal_panel.dart b/desktop/lib/widgets/terminal_panel.dart
index d319df0ae..3f0106174 100644
--- a/desktop/lib/widgets/terminal_panel.dart
+++ b/desktop/lib/widgets/terminal_panel.dart
@@ -241,6 +241,9 @@ class _TerminalPanelState extends State<TerminalPanel>
late final TerminalLinkOpener _linkOpener;
Offset? _linkPointerPosition;
String? _hoveredLink;
+ List<TerminalLinkSpan> _hoveredLinkSpans = const [];
+ Rect? _hoveredLinkAnchor;
+ final _linkUnderlineKey = GlobalKey();
String? _pressedLink;
bool _openingLink = false;
bool _linkRefreshPending = false;
@@ -399,6 +402,7 @@ class _TerminalPanelState extends State<TerminalPanel>
_viewTerminal.addListener(_onPassageOutput);
_pressedLink = null;
_hoveredLink = null;
+ _hoveredLinkSpans = const [];
_observeLinkModifiers(false);
_terminalViewKey = GlobalKey<TerminalViewState>();
_followTail = true;
@@ -414,6 +418,7 @@ class _TerminalPanelState extends State<TerminalPanel>
_cancelDialInertia();
_linkPointerPosition = null;
_hoveredLink = null;
+ _hoveredLinkSpans = const [];
_pressedLink = null;
_observeLinkModifiers(false);
}
@@ -657,6 +662,7 @@ class _TerminalPanelState extends State<TerminalPanel>
_viewTerminal.addListener(_onPassageOutput);
_pressedLink = null;
_hoveredLink = null;
+ _hoveredLinkSpans = const [];
_observeLinkModifiers(false);
_cancelDialInertia();
_alternateScrollRemainder = 0;
@@ -1930,22 +1936,74 @@ class _TerminalPanelState extends State<TerminalPanel>
_scheduleLinkRefresh();
}
- String? _linkAtPointer(Offset globalPosition) {
+ CellOffset? _cellAtPointer(Offset globalPosition) {
final view = _laidOutTerminalView();
if (view == null) return null;
final render = view.renderTerminal;
final local = render.globalToLocal(globalPosition);
if (!(Offset.zero & render.size).contains(local)) return null;
- return terminalLinkAt(_viewTerminal, render.getCellOffset(local));
+ return render.getCellOffset(local);
+ }
+
+ /// Puts the link tooltip under the link itself (over it near the bottom
+ /// edge). The tooltip wraps the whole pane, so Flutter's default would
+ /// centre it on the pane, however far that is from the pointer.
+ Offset _linkTooltipPosition(TooltipPositionContext context) {
+ final anchor = _hoveredLinkAnchor;
+ return positionDependentBox(
+ size: context.overlaySize,
+ childSize: context.tooltipSize,
+ target: anchor?.center ?? context.target,
+ verticalOffset: anchor == null
+ ? context.verticalOffset
+ : anchor.height / 2 + 4,
+ preferBelow: context.preferBelow,
+ );
+ }
+
+ /// The global rect of the hovered link's last row. Measured on hover, as
+ /// the tooltip positions itself mid-layout, when nothing may be measured.
+ Rect? _linkAnchor(List<TerminalLinkSpan> spans) {
+ final render = _laidOutTerminalView()?.renderTerminal;
+ if (render == null || !render.attached || spans.isEmpty) return null;
+ final last = spans.last;
+ final cell = render.cellSize;
+ return render.localToGlobal(
+ render.getOffset(CellOffset(last.start, last.row)),
+ ) &
+ Size((last.end - last.start + 1) * cell.width, cell.height);
+ }
+
+ String? _linkAtPointer(Offset globalPosition) {
+ final cell = _cellAtPointer(globalPosition);
+ return cell == null ? null : terminalLinkAt(_viewTerminal, cell);
}
void _hoverLink(Offset? globalPosition) {
_linkPointerPosition = widget.visible ? globalPosition : null;
- final target = _linkPointerPosition == null
+ final cell = _linkPointerPosition == null
? null
- : _linkAtPointer(_linkPointerPosition!);
+ : _cellAtPointer(_linkPointerPosition!);
+ final target = cell == null ? null : terminalLinkAt(_viewTerminal, cell);
_observeLinkModifiers(target != null);
- if (target != _hoveredLink) setState(() => _hoveredLink = target);
+ // Walking the link's extent costs a lookup per cell, so it runs when the
+ // pointer reaches a new link, not on every move along the same one.
+ final onSpans =
+ cell != null &&
+ _hoveredLinkSpans.any(
+ (s) => s.row == cell.y && s.start <= cell.x && cell.x <= s.end,
+ );
+ if (target == _hoveredLink && (target == null || onSpans)) {
+ _hoveredLinkAnchor = _linkAnchor(_hoveredLinkSpans); // it may scroll
+ return;
+ }
+ setState(() {
+ _hoveredLink = target;
+ _hoveredLinkSpans = target == null
+ ? const []
+ : terminalLinkSpans(_viewTerminal, cell!, target);
+ _hoveredLinkAnchor = _linkAnchor(_hoveredLinkSpans);
+ });
}
bool _onLinkTapDown(TapDownDetails details, CellOffset cell) {
@@ -2136,46 +2194,64 @@ class _TerminalPanelState extends State<TerminalPanel>
onHover: (event) => _hoverLink(event.position),
onExit: (_) => _hoverLink(null),
child: Tooltip(
+ // With the address: an OSC 8 label such as `!125`
+ // does not say where it leads.
message: _hoveredLink == null
? ''
: '${defaultTargetPlatform == TargetPlatform.macOS ? '⌘' : 'Ctrl'}-click to open\n$_hoveredLink',
- child: TerminalView(
- session.terminal,
- key: _terminalViewKey,
- controller: _controller,
- autoResize: widget.visible && !session.readOnly,
- resizeBuffer: false,
- renderingEnabled: widget.visible,
- outputRepaintInterval: widget.outputRepaintInterval,
- scrollController: _scrollController,
- focusNode: _focusNode,
- autofocus: widget.focused && !showComposer,
- readOnly: widget.readOnly || !session.acceptsInput,
- theme: terminalScreenThemeFor(
- grid.AppTheme.palette.value,
- terminalThemeStore.value,
+ positionDelegate: _linkTooltipPosition,
+ child: CustomPaint(
+ key: _linkUnderlineKey,
+ foregroundPainter: _LinkUnderlinePainter(
+ spans: _hoveredLinkSpans,
+ source: session.terminal,
+ terminal: _laidOutTerminalView,
+ host: () =>
+ _linkUnderlineKey.currentContext
+ ?.findRenderObject()
+ as RenderBox?,
+ repaint: _scrollController,
+ ),
+ child: TerminalView(
+ session.terminal,
+ key: _terminalViewKey,
+ controller: _controller,
+ autoResize: widget.visible && !session.readOnly,
+ resizeBuffer: false,
+ renderingEnabled: widget.visible,
+ outputRepaintInterval:
+ widget.outputRepaintInterval,
+ scrollController: _scrollController,
+ focusNode: _focusNode,
+ autofocus: widget.focused && !showComposer,
+ readOnly:
+ widget.readOnly || !session.acceptsInput,
+ theme: terminalScreenThemeFor(
+ grid.AppTheme.palette.value,
+ terminalThemeStore.value,
+ ),
+ padding: const EdgeInsets.all(10),
+ textStyle: terminalFontStore.value,
+ // The chosen point size already sizes each terminal cell.
+ // Applying the OS text scale again would change rows/cols
+ // and resize the remote terminal unexpectedly.
+ textScaler: TextScaler.noScaling,
+ onKeyEvent: _onTerminalKey,
+ onTapDown: _onLinkTapDown,
+ onTapUp: _onLinkTapUp,
+ mouseCursor:
+ _hoveredLink != null && _linkModifierPressed
+ ? SystemMouseCursors.click
+ // An I-beam invites typing; a blocked pane does not.
+ : _inputBlocked
+ ? SystemMouseCursors.basic
+ : SystemMouseCursors.text,
+ onSecondaryTapDown: (_, _) => _copyOrPaste(),
+
+ onAltBufferScroll: session.scrollViaTmuxCopyMode
+ ? (up) => session.sendScrollCommand(up, 1)
+ : null,
),
- padding: const EdgeInsets.all(10),
- textStyle: terminalFontStore.value,
- // The chosen point size already sizes each terminal cell.
- // Applying the OS text scale again would change rows/cols
- // and resize the remote terminal unexpectedly.
- textScaler: TextScaler.noScaling,
- onKeyEvent: _onTerminalKey,
- onTapDown: _onLinkTapDown,
- onTapUp: _onLinkTapUp,
- mouseCursor:
- _hoveredLink != null && _linkModifierPressed
- ? SystemMouseCursors.click
- // An I-beam invites typing; a blocked pane does not.
- : _inputBlocked
- ? SystemMouseCursors.basic
- : SystemMouseCursors.text,
- onSecondaryTapDown: (_, _) => _copyOrPaste(),
-
- onAltBufferScroll: session.scrollViaTmuxCopyMode
- ? (up) => session.sendScrollCommand(up, 1)
- : null,
),
),
),
@@ -2951,6 +3027,56 @@ class _TerminalHeader extends StatelessWidget {
/// The three shapes describe one hop, an intermediate hop, and a central server respectively. That
/// makes the modes distinguishable without colour while keeping the badge small enough for a four-pane
/// layout. The wire name `relay` still means the backend WebSocket; only its human-facing label is WS.
+/// Underlines the link under the pointer, in each span's own text colour —
+/// the terminal's cells carry no underline for it, so this paints on top.
+class _LinkUnderlinePainter extends CustomPainter {
+ _LinkUnderlinePainter({
+ required this.spans,
+ required this.source,
+ required this.terminal,
+ required this.host,
+ super.repaint,
+ });
+
+ final List<TerminalLinkSpan> spans;
+ final Terminal source;
+ final TerminalViewState? Function() terminal;
+ final RenderBox? Function() host;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ if (spans.isEmpty) return;
+ final render = terminal()?.renderTerminal;
+ final box = host();
+ if (render == null || box == null || !render.attached) return;
+ final lines = source.buffer.lines;
+ final cell = render.cellSize;
+ final thickness = math.max(1.0, cell.height / 16).roundToDouble();
+ final paint = Paint()..strokeWidth = thickness;
+ for (final span in spans) {
+ if (span.row >= lines.length) continue;
+ final from = box.globalToLocal(
+ render.localToGlobal(
+ render.getOffset(CellOffset(span.start, span.row)),
+ ),
+ );
+ final y = from.dy + cell.height - thickness;
+ if (y < 0 || y > size.height) continue;
+ paint.color = render.resolveForegroundColor(
+ lines[span.row].getForeground(span.start),
+ );
+ canvas.drawLine(
+ Offset(from.dx, y),
+ Offset(from.dx + (span.end - span.start + 1) * cell.width, y),
+ paint,
+ );
+ }
+ }
+
+ @override
+ bool shouldRepaint(_LinkUnderlinePainter old) => !identical(old.spans, spans);
+}
+
class _LinkModeMark extends StatelessWidget {
final String mode;
diff --git a/desktop/test/terminal_links_test.dart b/desktop/test/terminal_links_test.dart
index abeaf2d50..eaadf1186 100644
--- a/desktop/test/terminal_links_test.dart
+++ b/desktop/test/terminal_links_test.dart
@@ -109,6 +109,78 @@ void main() {
);
});
+ group('OSC 8 hyperlinks', () {
+ // Claude Code's table cell for `[!125](…/merge_requests/125)`, as tmux
+ // hands it over: the label is shown, the address rides in OSC 8.
+ const mr = 'https://git.example.com/group/project/-/merge_requests/125';
+
+ test('opens the hidden target from any cell of the label', () {
+ final terminal = Terminal()..resize(60, 4);
+ terminal.write(
+ '| MR | \x1b[94m\x1b]8;id=1a8pnbt;$mr\x1b\\!125\x1b[39m\x1b]8;;\x1b\\ | x',
+ );
+ for (var x = 7; x < 11; x++) {
+ expect(terminalLinkAt(terminal, CellOffset(x, 0)), mr);
+ }
+ expect(terminalLinkAt(terminal, const CellOffset(6, 0)), isNull);
+ expect(terminalLinkAt(terminal, const CellOffset(11, 0)), isNull);
+ });
+
+ test('BEL-terminated, with semicolons kept in the URI', () {
+ const url = 'https://example.com/a;b?c=1';
+ final terminal = Terminal()..resize(40, 4);
+ terminal.write('\x1b]8;;$url\x07here\x1b]8;;\x07 after');
+ expect(terminalLinkAt(terminal, const CellOffset(1, 0)), url);
+ expect(terminalLinkAt(terminal, const CellOffset(7, 0)), isNull);
+ });
+
+ test('survives an SGR reset and clears when the cell is rewritten', () {
+ const url = 'https://example.com/x';
+ final terminal = Terminal()..resize(40, 4);
+ terminal.write('\x1b]8;;$url\x1b\\ab\x1b[0mcd\x1b]8;;\x1b\\');
+ expect(terminalLinkAt(terminal, const CellOffset(3, 0)), url);
+ terminal.write('\r\x1b[2Kplain');
+ expect(terminalLinkAt(terminal, const CellOffset(1, 0)), isNull);
+ });
+
+ test('moves with inserted and deleted characters', () {
+ const url = 'https://example.com/y';
+ final terminal = Terminal()..resize(40, 4);
+ terminal.write('ab\x1b]8;;$url\x1b\\LINK\x1b]8;;\x1b\\');
+ terminal.write('\r\x1b[2@');
+ expect(terminalLinkAt(terminal, const CellOffset(4, 0)), url);
+ expect(terminalLinkAt(terminal, const CellOffset(2, 0)), isNull);
+ terminal.write('\r\x1b[3P');
+ expect(terminalLinkAt(terminal, const CellOffset(1, 0)), url);
+ expect(terminalLinkAt(terminal, const CellOffset(0, 0)), isNull);
+ });
+
+ test('spans exactly the linked cells for the hover underline', () {
+ final terminal = Terminal()..resize(60, 4);
+ terminal.write(
+ '| MR | \x1b[94m\x1b]8;id=1a8pnbt;$mr\x1b\\!125\x1b[39m\x1b]8;;\x1b\\ | x',
+ );
+ expect(terminalLinkSpans(terminal, const CellOffset(8, 0), mr), [
+ (row: 0, start: 7, end: 10),
+ ]);
+ });
+
+ test('a link never closed ends at a full reset', () {
+ const url = 'https://example.com/leak';
+ final terminal = Terminal()..resize(40, 4);
+ terminal.write('\x1b]8;;$url\x1b\\cut off');
+ terminal.write('\x1bc\r\nprompt');
+ expect(terminalLinkAt(terminal, const CellOffset(0, 0)), url);
+ expect(terminalLinkAt(terminal, const CellOffset(1, 1)), isNull);
+ });
+
+ test('ignores non-web schemes', () {
+ final terminal = Terminal()..resize(40, 4);
+ terminal.write('\x1b]8;;javascript:alert(1)\x1b\\x\x1b]8;;\x1b\\');
+ expect(terminalLinkAt(terminal, const CellOffset(0, 0)), isNull);
+ });
+ });
+
group('hard-wrapped web URLs', () {
// What Claude Code (Ink) writes for a long address in a narrow pane: rows
// with their own newlines, cut at the box width, each indented by the box.
@@ -119,6 +191,17 @@ void main() {
return terminal;
}
+ test('spans every row of a cut URL for the hover underline', () {
+ final terminal = ink([
+ ' Command Code here: https://commandc',
+ ' ode.ai/0xkongamoto/settings/billing',
+ ]);
+ expect(terminalLinkSpans(terminal, const CellOffset(5, 1), url), [
+ (row: 0, start: 21, end: 36),
+ (row: 1, start: 2, end: 36),
+ ]);
+ });
+
test('reads the whole URL from either row', () {
final terminal = ink([
' Command Code here: https://commandc',
diff --git a/desktop/test/terminal_panel_links_test.dart b/desktop/test/terminal_panel_links_test.dart
index d46006fc9..88c58283e 100644
--- a/desktop/test/terminal_panel_links_test.dart
+++ b/desktop/test/terminal_panel_links_test.dart
@@ -410,6 +410,27 @@ void main() {
await tester.pump(const Duration(milliseconds: 350));
},
);
+ testOnPlatform('the link tooltip sits under the link, not mid-pane', (
+ tester,
+ ) async {
+ await mount(tester);
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ await mouse.addPointer(location: Offset.zero);
+ await mouse.moveTo(point(tester));
+ await tester.pump();
+ await tester.pump(const Duration(seconds: 1));
+ final render = tester
+ .state<TerminalViewState>(find.byType(TerminalView))
+ .renderTerminal;
+ final linkBottom = render
+ .localToGlobal(render.getOffset(const CellOffset(0, 1)))
+ .dy;
+ final tip = tester.getRect(find.textContaining('-click to open'));
+ expect(tip.top, greaterThanOrEqualTo(linkBottom));
+ expect(tip.top, lessThan(linkBottom + render.cellSize.height * 3));
+ await mouse.removePointer();
+ await tester.pump(const Duration(milliseconds: 350));
+ });
testOnPlatform(
'hover shows the shortcut and refreshes after streamed output changes',
(tester) async {
diff --git a/desktop/third_party/xterm/README.autonomous.md b/desktop/third_party/xterm/README.autonomous.md
index 9aeba298a..962adcdb4 100644
--- a/desktop/third_party/xterm/README.autonomous.md
+++ b/desktop/third_party/xterm/README.autonomous.md
@@ -13,6 +13,15 @@ fix and the regression in `test/terminal_session_test.dart` passes against it.
## Local patches
+- **OSC 8 hyperlinks are kept per cell** (`lib/src/core/escape/parser.dart`,
+ `lib/src/core/cursor.dart`, `lib/src/core/buffer/line.dart`,
+ `lib/src/core/buffer/buffer.dart`, `lib/src/terminal.dart`). Upstream drops
+ OSC 8, so a Claude Code markdown link printed as just its label (`!125`)
+ had no address to open. The target rides on `CursorStyle.hyperlink`, which
+ SGR resets leave alone, and `BufferLine.getHyperlink` reads it back; the
+ per-line array is allocated only once a linked cell is written. Regressions:
+ the `OSC 8 hyperlinks` group in `test/terminal_links_test.dart`.
+
- **Pane-local wheel coordinates** (`lib/src/terminal_view.dart`). Convert the
pointer's global position to renderer-local coordinates before constructing
alternate-screen mouse-wheel reports. Offset panes otherwise report the
diff --git a/desktop/third_party/xterm/lib/src/core/buffer/buffer.dart b/desktop/third_party/xterm/lib/src/core/buffer/buffer.dart
index 5481c3f26..5e6d479e0 100644
--- a/desktop/third_party/xterm/lib/src/core/buffer/buffer.dart
+++ b/desktop/third_party/xterm/lib/src/core/buffer/buffer.dart
@@ -333,6 +333,7 @@ class Buffer {
_savedCursorStyle.foreground = terminal.cursor.foreground;
_savedCursorStyle.background = terminal.cursor.background;
_savedCursorStyle.attrs = terminal.cursor.attrs;
+ _savedCursorStyle.hyperlink = terminal.cursor.hyperlink;
charset.save();
}
@@ -343,6 +344,7 @@ class Buffer {
terminal.cursor.foreground = _savedCursorStyle.foreground;
terminal.cursor.background = _savedCursorStyle.background;
terminal.cursor.attrs = _savedCursorStyle.attrs;
+ terminal.cursor.hyperlink = _savedCursorStyle.hyperlink;
charset.restore();
}
diff --git a/desktop/third_party/xterm/lib/src/core/buffer/line.dart b/desktop/third_party/xterm/lib/src/core/buffer/line.dart
index a7070e0d6..19d513c5c 100644
--- a/desktop/third_party/xterm/lib/src/core/buffer/line.dart
+++ b/desktop/third_party/xterm/lib/src/core/buffer/line.dart
@@ -71,6 +71,28 @@ class BufferLine with IndexedItem {
_paintVersion++;
}
+ /// The OSC 8 target of each cell, parallel to [_data]. Allocated on the
+ /// first linked cell written, so a line with no links costs nothing.
+ List<String?>? _links;
+
+ /// The OSC 8 hyperlink target of the cell at [index], or null.
+ String? getHyperlink(int index) {
+ final links = _links;
+ return links == null || index >= links.length ? null : links[index];
+ }
+
+ @pragma('vm:prefer-inline')
+ void _storeLink(int index, String? uri) {
+ var links = _links;
+ if (links == null) {
+ if (uri == null) return;
+ links = _links = List<String?>.filled(_data.length ~/ _cellSize, null);
+ }
+ if (links[index] == uri) return;
+ links[index] = uri;
+ _paintVersion++;
+ }
+
final _anchors = <CellAnchor>[];
List<CellAnchor> get anchors => _anchors;
@@ -112,6 +134,7 @@ class BufferLine with IndexedItem {
final cellData = CellData.empty();
_store(index * _cellSize, cellData.foreground, cellData.background,
cellData.flags, cellData.content);
+ _storeLink(index, null);
return cellData;
}
@@ -141,22 +164,27 @@ class BufferLine with IndexedItem {
_textVersion++;
_store(index * _cellSize, style.foreground, style.background, style.attrs,
char | (witdh << CellContent.widthShift));
+ _storeLink(index, style.hyperlink);
}
void setCellData(int index, CellData cellData) {
_textVersion++;
_store(index * _cellSize, cellData.foreground, cellData.background,
cellData.flags, cellData.content);
+ _storeLink(index, null);
}
void eraseCell(int index, CursorStyle style) {
_textVersion++;
- _store(index * _cellSize, style.foreground, style.background, style.attrs, 0);
+ _store(
+ index * _cellSize, style.foreground, style.background, style.attrs, 0);
+ _storeLink(index, null);
}
void resetCell(int index) {
_textVersion++;
_store(index * _cellSize, 0, 0, 0, 0);
+ _storeLink(index, null);
}
/// Erase cells whose index satisfies [start] <= index < [end]. Erased cells
@@ -194,6 +222,12 @@ class BufferLine with IndexedItem {
for (var i = moveStart; i < moveEnd; i++) {
_data[i] = _data[i + moveOffset];
}
+ final links = _links;
+ if (links != null) {
+ for (var i = start; i < _length - count; i++) {
+ links[i] = links[i + count];
+ }
+ }
}
for (var i = _length - count; i < _length; i++) {
@@ -233,6 +267,12 @@ class BufferLine with IndexedItem {
for (var i = moveEnd - 1; i >= moveStart; i--) {
_data[i + moveOffset] = _data[i];
}
+ final links = _links;
+ if (links != null) {
+ for (var i = _length - count - 1; i >= start; i--) {
+ links[i + count] = links[i];
+ }
+ }
}
final end = min(start + count, _length);
@@ -272,6 +312,11 @@ class BufferLine with IndexedItem {
final newBuffer = Uint32List(newBufferSize);
newBuffer.setRange(0, _data.length, _data);
_data = newBuffer;
+ final links = _links;
+ if (links != null) {
+ _links = List<String?>.filled(newBufferSize ~/ _cellSize, null)
+ ..setRange(0, links.length, links);
+ }
}
}
@@ -334,6 +379,9 @@ class BufferLine with IndexedItem {
for (var i = 0; i < len * _cellSize; i++) {
_data[dstOffset++] = src._data[srcOffset++];
}
+ for (var i = 0; i < len; i++) {
+ _storeLink(dstCol + i, src.getHyperlink(srcCol + i));
+ }
}
static int _calcCapacity(int length) {
diff --git a/desktop/third_party/xterm/lib/src/core/cursor.dart b/desktop/third_party/xterm/lib/src/core/cursor.dart
index ce08610d8..e40ed4f6e 100644
--- a/desktop/third_party/xterm/lib/src/core/cursor.dart
+++ b/desktop/third_party/xterm/lib/src/core/cursor.dart
@@ -7,7 +7,16 @@ class CursorStyle {
int attrs;
- CursorStyle({this.foreground = 0, this.background = 0, this.attrs = 0});
+ /// The OSC 8 hyperlink target the next printed cells carry, or null. SGR
+ /// resets leave it alone; only another OSC 8 changes it.
+ String? hyperlink;
+
+ CursorStyle({
+ this.foreground = 0,
+ this.background = 0,
+ this.attrs = 0,
+ this.hyperlink,
+ });
static final empty = CursorStyle();
diff --git a/desktop/third_party/xterm/lib/src/core/escape/handler.dart b/desktop/third_party/xterm/lib/src/core/escape/handler.dart
index 166fb485c..bec7921a9 100644
--- a/desktop/third_party/xterm/lib/src/core/escape/handler.dart
+++ b/desktop/third_party/xterm/lib/src/core/escape/handler.dart
@@ -211,5 +211,8 @@ abstract class EscapeHandler {
void setIconName(String name);
+ /// OSC 8: cells printed from now on link to [uri]; null ends the link.
+ void setHyperlink(String? uri);
+
void unknownOSC(String code, List<String> args);
}
diff --git a/desktop/third_party/xterm/lib/src/core/escape/parser.dart b/desktop/third_party/xterm/lib/src/core/escape/parser.dart
index 7571a9e18..bf634d2b3 100644
--- a/desktop/third_party/xterm/lib/src/core/escape/parser.dart
+++ b/desktop/third_party/xterm/lib/src/core/escape/parser.dart
@@ -100,11 +100,12 @@ class EscapeParser {
'E'.charCode: _escHandleNextLine,
'H'.charCode: _escHandleTabSet,
'M'.charCode: _escHandleReverseIndex,
- 'P'.charCode: _escHandleStringSequence, // DCS (incl. Sixel, tmux passthrough)
+ 'P'.charCode:
+ _escHandleStringSequence, // DCS (incl. Sixel, tmux passthrough)
'_'.charCode: _escHandleStringSequence, // APC
'^'.charCode: _escHandleStringSequence, // PM
'X'.charCode: _escHandleStringSequence, // SOS
- // 'c'.charCode: _unsupportedHandler,
+ 'c'.charCode: _escHandleFullReset,
// '#'.charCode: _unsupportedHandler,
'('.charCode: _escHandleDesignateCharset0, // SCS - G0
')'.charCode: _escHandleDesignateCharset1, // SCS - G1
@@ -184,6 +185,14 @@ class EscapeParser {
return true;
}
+ /// `ESC c` Full Reset (RIS) — only the part a leaked OSC 8 needs: an open
+ /// hyperlink ends, so a link whose close never arrived stops at `reset`.
+ /// The rest of a full reset remains unsupported, as before.
+ bool _escHandleFullReset() {
+ handler.setHyperlink(null);
+ return true;
+ }
+
/// `ESC M` Reverse Index (RI)
///
/// https://terminalguide.namepad.de/seq/a_esc_cm/
@@ -1117,6 +1126,11 @@ class EscapeParser {
case '2':
handler.setTitle(pt);
return true;
+ case '8':
+ // OSC 8 ; params ; URI — the URI is the rest, semicolons included.
+ final uri = _osc.length > 2 ? _osc.sublist(2).join(';') : '';
+ handler.setHyperlink(uri.isEmpty ? null : uri);
+ return true;
}
}
diff --git a/desktop/third_party/xterm/lib/src/terminal.dart b/desktop/third_party/xterm/lib/src/terminal.dart
index 0c174438e..c0cb3b628 100644
--- a/desktop/third_party/xterm/lib/src/terminal.dart
+++ b/desktop/third_party/xterm/lib/src/terminal.dart
@@ -913,6 +913,11 @@ class Terminal with Observable implements TerminalState, EscapeHandler {
onIconChange?.call(name);
}
+ @override
+ void setHyperlink(String? uri) {
+ _cursorStyle.hyperlink = uri;
+ }
+
@override
void unknownOSC(String ps, List<String> pt) {
onPrivateOSC?.call(ps, pt);
diff --git a/desktop/third_party/xterm/lib/src/ui/render.dart b/desktop/third_party/xterm/lib/src/ui/render.dart
index 03553319d..f9033a613 100644
--- a/desktop/third_party/xterm/lib/src/ui/render.dart
+++ b/desktop/third_party/xterm/lib/src/ui/render.dart
@@ -544,6 +544,11 @@ class RenderTerminal extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
return _painter.cellSize;
}
+ /// The colour a cell's foreground word paints in under the current theme.
+ Color resolveForegroundColor(int cellColor) {
+ return _painter.resolveForegroundColor(cellColor);
+ }
+
@override
void paint(PaintingContext context, Offset offset) {
_paint(context, offset);
diff --git a/desktop/third_party/xterm/lib/src/utils/debugger.dart b/desktop/third_party/xterm/lib/src/utils/debugger.dart
index 303bbbbe8..fa8aeeca1 100644
--- a/desktop/third_party/xterm/lib/src/utils/debugger.dart
+++ b/desktop/third_party/xterm/lib/src/utils/debugger.dart
@@ -588,6 +588,11 @@ class _TerminalDebuggerHandler implements EscapeHandler {
onCommand('setIconName($name)');
}
+ @override
+ void setHyperlink(String? uri) {
+ onCommand('setHyperlink($uri)');
+ }
+
@override
void unknownOSC(String code, List<String> args) {
onCommand('unknownOSC($code, $args)', error: true);