merge(app): land text-family previews and bundled monospace

This commit is contained in:
2026-10-23 14:56:17 +01:00
14 changed files with 144 additions and 62 deletions
+8
View File
@@ -0,0 +1,8 @@
# Bundled fonts
`RobotoMono-Regular.ttf` and `RobotoMono-Bold.ttf` are Roboto Mono by
Christian Robertson, licensed under the Apache License, Version 2.0
(https://www.apache.org/licenses/LICENSE-2.0). The files are copied unchanged
from the Flutter SDK's DevTools assets. They give monospace text (artifact text
previews, background task output) a real fixed-width face on every platform:
Flutter web does not resolve the generic `monospace` family.
Binary file not shown.
Binary file not shown.
@@ -196,21 +196,38 @@ bool isMarkdownArtifact(String contentType, String name) {
return _markdownExtensions.contains(_extensionOf(name)); return _markdownExtensions.contains(_extensionOf(name));
} }
/// Whether an artifact opens inside the viewer: images, videos, markdown/text /// How the viewer presents an artifact in-app, or [none] when it only offers
/// documents and any recorded `text/plain` file. The viewer draws text/plain as /// Open/Download.
/// selectable text; a CSV, source file or spreadsheet with its own type stays an enum ArtifactPreviewFormat { image, video, markdown, text, none }
/// external file because it is evidence, not prose. Videos are pageable but the
/// viewer reports that it cannot draw them rather than faking a player. /// The one rule for in-app previews, shared by the gallery's paging and the
bool isViewerArtifact(String contentType, String name) { /// viewer's fetch plan. Images and videos come from the content type; markdown
if (isImageContentType(contentType) || isVideoContentType(contentType)) { /// from `text/markdown` or an md/markdown name; plain text, logs, JSON and
return true; /// source/config files are shown as selectable monospace text.
} ArtifactPreviewFormat artifactPreviewFormat(String contentType, String name) {
if (isImageContentType(contentType)) return ArtifactPreviewFormat.image;
if (isVideoContentType(contentType)) return ArtifactPreviewFormat.video;
final mime = contentType.split(';').first.trim().toLowerCase(); final mime = contentType.split(';').first.trim().toLowerCase();
if (mime == 'text/plain') return true; final ext = _extensionOf(name);
return artifactKind(contentType, name) == ArtifactKind.document && if (mime == 'text/markdown' || ext == 'md' || ext == 'markdown') {
isMarkdownArtifact(contentType, name); return ArtifactPreviewFormat.markdown;
}
final kind = artifactKind(contentType, name);
if (kind == ArtifactKind.json ||
kind == ArtifactKind.log ||
kind == ArtifactKind.code ||
mime == 'text/plain' ||
ext == 'txt' ||
ext == 'rst') {
return ArtifactPreviewFormat.text;
}
return ArtifactPreviewFormat.none;
} }
/// Whether an artifact opens inside the viewer (see [artifactPreviewFormat]).
bool isViewerArtifact(String contentType, String name) =>
artifactPreviewFormat(contentType, name) != ArtifactPreviewFormat.none;
/// Human-readable byte size, matching the web client: whole bytes under 1 KiB, /// Human-readable byte size, matching the web client: whole bytes under 1 KiB,
/// otherwise one decimal with a binary unit (KiB/MiB/GiB/TiB/PiB/EiB). /// otherwise one decimal with a binary unit (KiB/MiB/GiB/TiB/PiB/EiB).
String humanBytes(num size) { String humanBytes(num size) {
@@ -56,9 +56,10 @@ const String artifactPreviewExternalUrl =
/// Classifies [artifact] against the configured server origin. /// Classifies [artifact] against the configured server origin.
/// ///
/// Images are drawn from the resolved bytes; a video plays from the resolved /// The format comes from [artifactPreviewFormat]: images are drawn from the
/// url; `text/plain` is selectable text; a `.md`/`.markdown` name or /// resolved bytes, a video plays from the resolved url, markdown goes to the
/// `text/markdown` is handed to the injected markdown builder. Everything else is explicitly unsupported rather than faked. /// injected builder and the text family is selectable monospace text.
/// Everything else is explicitly unsupported rather than faked.
ArtifactPreviewPlan planArtifactPreview({ ArtifactPreviewPlan planArtifactPreview({
required ArtifactRecord artifact, required ArtifactRecord artifact,
required String configuredEndpoint, required String configuredEndpoint,
@@ -85,34 +86,18 @@ ArtifactPreviewPlan planArtifactPreview({
message: artifactPreviewExternalUrl, message: artifactPreviewExternalUrl,
); );
} }
final mime = artifact.contentType.split(';').first.trim().toLowerCase(); final kind = switch (artifactPreviewFormat(
if (isImageContentType(mime)) { artifact.contentType,
return ArtifactPreviewPlan( artifact.name,
kind: ArtifactPreviewKind.image, )) {
resolved: resolved, ArtifactPreviewFormat.image => ArtifactPreviewKind.image,
message: '', ArtifactPreviewFormat.video => ArtifactPreviewKind.video,
); ArtifactPreviewFormat.markdown => ArtifactPreviewKind.markdown,
} ArtifactPreviewFormat.text => ArtifactPreviewKind.text,
if (isVideoContentType(mime)) { ArtifactPreviewFormat.none => null,
return ArtifactPreviewPlan( };
kind: ArtifactPreviewKind.video, if (kind != null) {
resolved: resolved, return ArtifactPreviewPlan(kind: kind, resolved: resolved, message: '');
message: '',
);
}
if (mime == 'text/markdown' || _isMarkdownName(artifact.name)) {
return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.markdown,
resolved: resolved,
message: '',
);
}
if (mime == 'text/plain') {
return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.text,
resolved: resolved,
message: '',
);
} }
return ArtifactPreviewPlan( return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.unsupported, kind: ArtifactPreviewKind.unsupported,
@@ -120,10 +105,3 @@ ArtifactPreviewPlan planArtifactPreview({
message: 'This file type cannot be previewed here.', message: 'This file type cannot be previewed here.',
); );
} }
bool _isMarkdownName(String name) {
final dot = name.lastIndexOf('.');
if (dot == -1) return false;
final extension = name.substring(dot + 1).toLowerCase();
return extension == 'md' || extension == 'markdown';
}
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import '../domain/artifact_preview.dart'; import '../domain/artifact_preview.dart';
import 'artifact_video_player.dart'; import 'artifact_video_player.dart';
import '../../../ui/text/monospace.dart';
/// Renders fetched markdown text for the viewer. It takes the build context so /// Renders fetched markdown text for the viewer. It takes the build context so
/// a themed markdown renderer can be supplied; the viewer's own default stays /// a themed markdown renderer can be supplied; the viewer's own default stays
@@ -68,7 +69,14 @@ class ArtifactPreviewBody extends StatelessWidget {
), ),
); );
case ArtifactPreviewKind.text: case ArtifactPreviewKind.text:
return _PreviewPadding(child: SelectableText(text ?? '')); // Logs, JSON and source keep their columns: a monospace body.
return _PreviewPadding(
child: SelectableText(
text ?? '',
key: const Key('artifact-text-preview'),
style: const TextStyle(fontFamily: appMonospaceFamily),
),
);
case ArtifactPreviewKind.markdown: case ArtifactPreviewKind.markdown:
return _PreviewPadding(child: markdownBuilder(context, text ?? '')); return _PreviewPadding(child: markdownBuilder(context, text ?? ''));
case ArtifactPreviewKind.video: case ArtifactPreviewKind.video:
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart'; import '../../../core/api_gateway.dart';
import '../domain/chat_shells.dart'; import '../domain/chat_shells.dart';
import '../ui/sessions/chat_adaptive.dart'; import '../ui/sessions/chat_adaptive.dart';
import '../../../ui/text/monospace.dart';
/// One bounded output page: the web's 220 px pane is twelve 18 px monospace /// One bounded output page: the web's 220 px pane is twelve 18 px monospace
/// lines (`web/chat.css`), so the bound is read from the host's own output type /// lines (`web/chat.css`), so the bound is read from the host's own output type
@@ -65,7 +66,7 @@ class ChatBackgroundTaskDetail extends StatelessWidget {
_label(context, cupertino, shellOutputTaskIdentityLabel), _label(context, cupertino, shellOutputTaskIdentityLabel),
Text( Text(
shellIdOf(shell), shellIdOf(shell),
style: const TextStyle(fontFamily: 'monospace'), style: const TextStyle(fontFamily: appMonospaceFamily),
), ),
Text(shellStatusRunningLabel), Text(shellStatusRunningLabel),
_outputArea(context, cupertino), _outputArea(context, cupertino),
@@ -101,7 +102,7 @@ class ChatBackgroundTaskDetail extends StatelessWidget {
? CupertinoTheme.of(context).textTheme.textStyle ? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodySmall ?? const TextStyle()) : Theme.of(context).textTheme.bodySmall ?? const TextStyle())
.copyWith( .copyWith(
fontFamily: 'monospace', fontFamily: appMonospaceFamily,
height: _outputLineHeight, height: _outputLineHeight,
// Cupertino's style is not inheriting; a selectable body needs a // Cupertino's style is not inheriting; a selectable body needs a
// baseline from its own style. // baseline from its own style.
@@ -5,6 +5,7 @@ import '../../../core/api_gateway.dart';
import 'run_detail_content.dart'; import 'run_detail_content.dart';
import 'run_detail_summary_fields.dart'; import 'run_detail_summary_fields.dart';
import 'run_detail_visit_facts.dart'; import 'run_detail_visit_facts.dart';
import '../../../ui/text/monospace.dart';
/// The Summary tab: the run's identity, the recorded facts as key/value rows, /// The Summary tab: the run's identity, the recorded facts as key/value rows,
/// the stored original prompt with its copy control and the collapsible Input /// the stored original prompt with its copy control and the collapsible Input
@@ -159,7 +160,9 @@ Widget _materialRow(BuildContext context, DetailSummaryRow row) {
), ),
subtitle: SelectableText( subtitle: SelectableText(
row.value, row.value,
style: row.monospace ? base?.copyWith(fontFamily: 'monospace') : base, style: row.monospace
? base?.copyWith(fontFamily: appMonospaceFamily)
: base,
), ),
); );
} }
@@ -188,7 +191,9 @@ Widget _materialBlock(BuildContext context, DetailSummaryRow row) {
), ),
child: SelectableText( child: SelectableText(
row.value, row.value,
style: theme.textTheme.bodySmall?.copyWith(fontFamily: 'monospace'), style: theme.textTheme.bodySmall?.copyWith(
fontFamily: appMonospaceFamily,
),
), ),
), ),
], ],
@@ -279,7 +284,9 @@ Widget _cupertinoRow(BuildContext context, DetailSummaryRow row) {
title: Text(row.label), title: Text(row.label),
subtitle: Text( subtitle: Text(
row.value, row.value,
style: row.monospace ? style.copyWith(fontFamily: 'monospace') : null, style: row.monospace
? style.copyWith(fontFamily: appMonospaceFamily)
: null,
), ),
); );
} }
@@ -308,7 +315,9 @@ Widget _cupertinoBlock(BuildContext context, DetailSummaryRow row) {
), ),
child: Text( child: Text(
row.value, row.value,
style: theme.textTheme.textStyle.copyWith(fontFamily: 'monospace'), style: theme.textTheme.textStyle.copyWith(
fontFamily: appMonospaceFamily,
),
), ),
), ),
], ],
+3
View File
@@ -0,0 +1,3 @@
/// The bundled fixed-width family (fonts/README.md). Flutter web does not
/// resolve the generic `monospace` family, so monospace text names this one.
const String appMonospaceFamily = 'RobotoMono';
+7
View File
@@ -63,6 +63,13 @@ flutter:
# the material Icons class. # the material Icons class.
uses-material-design: true uses-material-design: true
fonts:
- family: RobotoMono
fonts:
- asset: fonts/RobotoMono-Regular.ttf
- asset: fonts/RobotoMono-Bold.ttf
weight: 700
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets:
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
@@ -93,14 +93,26 @@ void main() {
('text/plain', 'memory.txt'), ('text/plain', 'memory.txt'),
('text/plain', 'run.log'), ('text/plain', 'run.log'),
('', 'output.md'), ('', 'output.md'),
// The text family previews as selectable text, not an external file.
('application/json', 'payload.json'),
('text/x-python', 'main.py'),
('application/octet-stream', 'config.yaml'),
('', 'build.log'),
]) { ]) {
expect(isViewerArtifact(contentType, name), isTrue, reason: name); expect(isViewerArtifact(contentType, name), isTrue, reason: name);
} }
expect(
artifactPreviewFormat('application/json', 'payload.json'),
ArtifactPreviewFormat.text,
);
expect(
artifactPreviewFormat('text/markdown', 'plan'),
ArtifactPreviewFormat.markdown,
);
for (final (contentType, name) in <(String, String)>[ for (final (contentType, name) in <(String, String)>[
('text/html', 'session.html'), ('text/html', 'session.html'),
('text/csv', 'rows.csv'), ('text/csv', 'rows.csv'),
('application/json', 'payload.json'), ('application/zip', 'bundle.zip'),
('text/x-python', 'main.py'),
('application/octet-stream', 'blob.bin'), ('application/octet-stream', 'blob.bin'),
('', ''), ('', ''),
]) { ]) {
@@ -39,6 +39,7 @@ void main() {
'input.md', 'input.md',
'run.log', 'run.log',
'shot.png', 'shot.png',
'main.py',
'clip.mp4', 'clip.mp4',
'memory.txt', 'memory.txt',
'output.md', 'output.md',
@@ -161,7 +162,7 @@ void main() {
sequence: 1, sequence: 1,
artifacts: <Map<String, dynamic>>[ artifacts: <Map<String, dynamic>>[
artifact('session.html', contentType: 'text/html'), artifact('session.html', contentType: 'text/html'),
artifact('main.py', contentType: 'text/x-python'), artifact('bundle.zip', contentType: 'application/zip'),
artifact('result.csv', contentType: 'text/csv'), artifact('result.csv', contentType: 'text/csv'),
], ],
), ),
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_preview.dart';
import 'package:pipelines_app/features/artifacts/domain/artifact_url.dart';
import 'package:pipelines_app/features/artifacts/ui/artifact_viewer_content.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
void main() {
testWidgets('a text-family preview is selectable bundled monospace', (
tester,
) async {
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: ArtifactPreviewBody(
plan: ArtifactPreviewPlan(
kind: ArtifactPreviewKind.text,
resolved: ResolvedArtifactUrl(
uri: Uri.parse('http://127.0.0.1:8080/artifacts/1/main.py'),
external: false,
),
message: '',
),
loading: false,
markdownBuilder: defaultArtifactMarkdown,
text: 'def main():\n return 0\n',
),
),
),
);
final text = tester.widget<SelectableText>(
find.byKey(const Key('artifact-text-preview')),
);
expect(text.data, 'def main():\n return 0\n');
expect(text.style?.fontFamily, appMonospaceFamily);
});
}
@@ -6,6 +6,7 @@ import 'package:pipelines_app/features/pipelines/pipeline_format.dart';
import 'package:pipelines_app/features/runs/ui/run_detail_summary_fields.dart'; import 'package:pipelines_app/features/runs/ui/run_detail_summary_fields.dart';
import 'run_detail_graph_support.dart'; import 'run_detail_graph_support.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
/// A run whose recorded facts fill every Summary row. /// A run whose recorded facts fill every Summary row.
JsonMap recordedRunFixture() => <String, dynamic>{ JsonMap recordedRunFixture() => <String, dynamic>{
@@ -156,12 +157,12 @@ void main() {
final hash = tester.widget<SelectableText>( final hash = tester.widget<SelectableText>(
find.widgetWithText(SelectableText, 'abc123def456'), find.widgetWithText(SelectableText, 'abc123def456'),
); );
expect(hash.style?.fontFamily, 'monospace'); expect(hash.style?.fontFamily, appMonospaceFamily);
} else { } else {
final tile = tester.widget<CupertinoListTile>( final tile = tester.widget<CupertinoListTile>(
find.byKey(const ValueKey('run-detail-summary-content-hash')), find.byKey(const ValueKey('run-detail-summary-content-hash')),
); );
expect((tile.subtitle! as Text).style?.fontFamily, 'monospace'); expect((tile.subtitle! as Text).style?.fontFamily, appMonospaceFamily);
} }
}); });