Merge branch 'worktree-agent-a9a25296deadb0eaa'
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ui' as ui;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:xterm/xterm.dart';
|
||||
|
||||
import '../../../ui/text/monospace.dart';
|
||||
import '../../../ui/text/terminal_symbols_font.dart';
|
||||
import '../conversation/chat_card_styles.dart';
|
||||
|
||||
/// The terminal's colours from the host theme: the card's inset surface as
|
||||
@@ -54,12 +56,24 @@ TerminalTheme chatShellTerminalTheme(BuildContext context) {
|
||||
}
|
||||
|
||||
/// The terminal's text: the host's monospace family at [fontSize] (the
|
||||
/// terminal text size setting), else a little under the card body size.
|
||||
/// terminal text size setting), else a little under the card body size, with
|
||||
/// the bundled symbols font first among the fallbacks for Powerline and Nerd
|
||||
/// Font icons (registered on first use).
|
||||
///
|
||||
/// Line height 1.1: the emulator rounds a row up to whole pixels (about
|
||||
/// 1.13 at the default size), close to other terminals' 1.0-1.2. Box
|
||||
/// drawing, block and Powerline characters fill the whole row whatever the
|
||||
/// height, so frames and bars join across rows.
|
||||
TerminalStyle chatShellTerminalStyle(BuildContext context, {double? fontSize}) {
|
||||
unawaited(ensureTerminalSymbolsFont());
|
||||
return TerminalStyle(
|
||||
fontFamily: appMonospaceFamily,
|
||||
fontFamilyFallback: const [
|
||||
terminalSymbolsFamily,
|
||||
...kTerminalDefaultFontFamilyFallback,
|
||||
],
|
||||
fontSize: fontSize ?? chatShellTerminalDefaultFontSize(context),
|
||||
height: 1.3,
|
||||
height: 1.1,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,7 +92,11 @@ Size chatShellTerminalCellSize(BuildContext context, TerminalStyle style) {
|
||||
..addText('mmmmmmmmmm');
|
||||
final paragraph = builder.build()
|
||||
..layout(const ui.ParagraphConstraints(width: double.infinity));
|
||||
final size = Size(paragraph.maxIntrinsicWidth / 10, paragraph.height);
|
||||
// Rows are whole pixels, as the emulator's painter rounds them.
|
||||
final size = Size(
|
||||
paragraph.maxIntrinsicWidth / 10,
|
||||
paragraph.height.ceilToDouble(),
|
||||
);
|
||||
paragraph.dispose();
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
/// The bundled icon font terminals fall back to for Powerline and Nerd Font
|
||||
/// glyphs (fonts/README.md): a subset of Symbols Nerd Font Mono.
|
||||
const String terminalSymbolsFamily = 'SymbolsNerdFontMono';
|
||||
|
||||
const String terminalSymbolsAsset =
|
||||
'fonts/symbols-nerd-font/SymbolsNerdFontMono-Subset.ttf';
|
||||
|
||||
const String terminalSymbolsLicenseAsset = 'fonts/symbols-nerd-font/LICENSE';
|
||||
|
||||
Future<void>? _loading;
|
||||
|
||||
/// Registers [terminalSymbolsFamily] the first time a terminal is drawn. It
|
||||
/// is a plain asset, not a `fonts:` family, so the web build does not
|
||||
/// download it at startup. Once registered the engine reports a font change
|
||||
/// and terminal views draw again with it. A failed load is logged; the
|
||||
/// glyphs then stay as the platform's fallback draws them.
|
||||
Future<void> ensureTerminalSymbolsFont() => _loading ??= _load();
|
||||
|
||||
Future<void> _load() async {
|
||||
try {
|
||||
final loader = FontLoader(terminalSymbolsFamily)
|
||||
..addFont(rootBundle.load(terminalSymbolsAsset));
|
||||
await loader.load();
|
||||
} catch (error) {
|
||||
debugPrint('Terminal symbols font did not load: $error');
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,13 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../text/terminal_symbols_font.dart';
|
||||
import 'app_font.dart';
|
||||
|
||||
bool _registered = false;
|
||||
|
||||
/// Adds each bundled interface font's SIL Open Font License to the
|
||||
/// Adds each bundled interface font's SIL Open Font License, and the
|
||||
/// terminal symbols font's MIT licence, to the
|
||||
/// [LicenseRegistry]. The texts are read from the bundle only when a licence
|
||||
/// page asks for them.
|
||||
void registerAppFontLicenses() {
|
||||
@@ -19,5 +21,8 @@ void registerAppFontLicenses() {
|
||||
font.label,
|
||||
], await rootBundle.loadString(asset));
|
||||
}
|
||||
yield LicenseEntryWithLineBreaks(<String>[
|
||||
'Symbols Nerd Font Mono',
|
||||
], await rootBundle.loadString(terminalSymbolsLicenseAsset));
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user