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));
}
/// Whether an artifact opens inside the viewer: images, videos, markdown/text
/// documents and any recorded `text/plain` file. The viewer draws text/plain as
/// selectable text; a CSV, source file or spreadsheet with its own type stays an
/// 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.
bool isViewerArtifact(String contentType, String name) {
if (isImageContentType(contentType) || isVideoContentType(contentType)) {
return true;
}
/// How the viewer presents an artifact in-app, or [none] when it only offers
/// Open/Download.
enum ArtifactPreviewFormat { image, video, markdown, text, none }
/// The one rule for in-app previews, shared by the gallery's paging and the
/// viewer's fetch plan. Images and videos come from the content type; markdown
/// from `text/markdown` or an md/markdown name; plain text, logs, JSON and
/// 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();
if (mime == 'text/plain') return true;
return artifactKind(contentType, name) == ArtifactKind.document &&
isMarkdownArtifact(contentType, name);
final ext = _extensionOf(name);
if (mime == 'text/markdown' || ext == 'md' || ext == 'markdown') {
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,
/// otherwise one decimal with a binary unit (KiB/MiB/GiB/TiB/PiB/EiB).
String humanBytes(num size) {
@@ -56,9 +56,10 @@ const String artifactPreviewExternalUrl =
/// Classifies [artifact] against the configured server origin.
///
/// Images are drawn from the resolved bytes; a video plays from the resolved
/// url; `text/plain` is selectable text; a `.md`/`.markdown` name or
/// `text/markdown` is handed to the injected markdown builder. Everything else is explicitly unsupported rather than faked.
/// The format comes from [artifactPreviewFormat]: images are drawn from the
/// resolved bytes, a video plays from the resolved url, markdown goes to the
/// injected builder and the text family is selectable monospace text.
/// Everything else is explicitly unsupported rather than faked.
ArtifactPreviewPlan planArtifactPreview({
required ArtifactRecord artifact,
required String configuredEndpoint,
@@ -85,34 +86,18 @@ ArtifactPreviewPlan planArtifactPreview({
message: artifactPreviewExternalUrl,
);
}
final mime = artifact.contentType.split(';').first.trim().toLowerCase();
if (isImageContentType(mime)) {
return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.image,
resolved: resolved,
message: '',
);
}
if (isVideoContentType(mime)) {
return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.video,
resolved: resolved,
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: '',
);
final kind = switch (artifactPreviewFormat(
artifact.contentType,
artifact.name,
)) {
ArtifactPreviewFormat.image => ArtifactPreviewKind.image,
ArtifactPreviewFormat.video => ArtifactPreviewKind.video,
ArtifactPreviewFormat.markdown => ArtifactPreviewKind.markdown,
ArtifactPreviewFormat.text => ArtifactPreviewKind.text,
ArtifactPreviewFormat.none => null,
};
if (kind != null) {
return ArtifactPreviewPlan(kind: kind, resolved: resolved, message: '');
}
return ArtifactPreviewPlan(
kind: ArtifactPreviewKind.unsupported,
@@ -120,10 +105,3 @@ ArtifactPreviewPlan planArtifactPreview({
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 'artifact_video_player.dart';
import '../../../ui/text/monospace.dart';
/// 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
@@ -68,7 +69,14 @@ class ArtifactPreviewBody extends StatelessWidget {
),
);
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:
return _PreviewPadding(child: markdownBuilder(context, text ?? ''));
case ArtifactPreviewKind.video:
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../domain/chat_shells.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
/// 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),
Text(
shellIdOf(shell),
style: const TextStyle(fontFamily: 'monospace'),
style: const TextStyle(fontFamily: appMonospaceFamily),
),
Text(shellStatusRunningLabel),
_outputArea(context, cupertino),
@@ -101,7 +102,7 @@ class ChatBackgroundTaskDetail extends StatelessWidget {
? CupertinoTheme.of(context).textTheme.textStyle
: Theme.of(context).textTheme.bodySmall ?? const TextStyle())
.copyWith(
fontFamily: 'monospace',
fontFamily: appMonospaceFamily,
height: _outputLineHeight,
// Cupertino's style is not inheriting; a selectable body needs a
// baseline from its own style.
@@ -5,6 +5,7 @@ import '../../../core/api_gateway.dart';
import 'run_detail_content.dart';
import 'run_detail_summary_fields.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 stored original prompt with its copy control and the collapsible Input
@@ -159,7 +160,9 @@ Widget _materialRow(BuildContext context, DetailSummaryRow row) {
),
subtitle: SelectableText(
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(
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),
subtitle: Text(
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(
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.
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:
# assets:
# - images/a_dot_burr.jpeg
@@ -93,14 +93,26 @@ void main() {
('text/plain', 'memory.txt'),
('text/plain', 'run.log'),
('', '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(
artifactPreviewFormat('application/json', 'payload.json'),
ArtifactPreviewFormat.text,
);
expect(
artifactPreviewFormat('text/markdown', 'plan'),
ArtifactPreviewFormat.markdown,
);
for (final (contentType, name) in <(String, String)>[
('text/html', 'session.html'),
('text/csv', 'rows.csv'),
('application/json', 'payload.json'),
('text/x-python', 'main.py'),
('application/zip', 'bundle.zip'),
('application/octet-stream', 'blob.bin'),
('', ''),
]) {
@@ -39,6 +39,7 @@ void main() {
'input.md',
'run.log',
'shot.png',
'main.py',
'clip.mp4',
'memory.txt',
'output.md',
@@ -161,7 +162,7 @@ void main() {
sequence: 1,
artifacts: <Map<String, dynamic>>[
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'),
],
),
@@ -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 'run_detail_graph_support.dart';
import 'package:pipelines_app/ui/text/monospace.dart';
/// A run whose recorded facts fill every Summary row.
JsonMap recordedRunFixture() => <String, dynamic>{
@@ -156,12 +157,12 @@ void main() {
final hash = tester.widget<SelectableText>(
find.widgetWithText(SelectableText, 'abc123def456'),
);
expect(hash.style?.fontFamily, 'monospace');
expect(hash.style?.fontFamily, appMonospaceFamily);
} else {
final tile = tester.widget<CupertinoListTile>(
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);
}
});