75a61dbd8c
Phase 3 of docs/plans/floating-windows.md. The terminal window kind reuses TerminalHub; TerminalWindows keeps the window in step with TerminalLayout (show opens or shows it, hide minimises it, Minimise and Close hide the terminal). The bottom panel stays a shell panel. The first window takes the frame and maximised state pipelines.terminal-layout.v1 saved. The terminal's own float chrome and FloatingLayer are deleted.
176 lines
5.1 KiB
Dart
176 lines
5.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/chat/shell/chat_shell_terminal_view.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_hub.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_surface.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
|
import 'package:pipelines_app/features/terminal/terminal_window.dart';
|
|
import 'package:pipelines_app/shell/windows/window_host.dart';
|
|
import 'package:pipelines_app/shell/windows/window_kind.dart';
|
|
import 'package:pipelines_app/shell/windows/window_layer.dart';
|
|
import 'package:pipelines_app/shell/windows/window_manager.dart';
|
|
|
|
const appField = Key('app-field');
|
|
|
|
/// An app with a text field under the terminal surface, [size] logical
|
|
/// pixels, optionally asking for reduced motion.
|
|
Future<void> pumpTerminalApp(
|
|
WidgetTester tester, {
|
|
required TerminalHub hub,
|
|
required TerminalLayout layout,
|
|
Size size = const Size(1200, 800),
|
|
bool reduceMotion = false,
|
|
}) async {
|
|
tester.view.physicalSize = size;
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.pumpWidget(
|
|
MaterialApp(
|
|
builder: (context, child) => MediaQuery(
|
|
data: MediaQuery.of(context).copyWith(disableAnimations: reduceMotion),
|
|
child: child!,
|
|
),
|
|
home: TerminalTestApp(hub: hub, layout: layout),
|
|
),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
|
|
/// The terminal surface around an app with a text field, with the app's
|
|
/// window system as the real app wires it: the terminal's floating mode is a
|
|
/// window in the host above the surface's stage.
|
|
class TerminalTestApp extends StatefulWidget {
|
|
const TerminalTestApp({
|
|
super.key,
|
|
required this.hub,
|
|
required this.layout,
|
|
this.shortcutHere = true,
|
|
});
|
|
|
|
final TerminalHub hub;
|
|
final TerminalLayout layout;
|
|
final bool shortcutHere;
|
|
|
|
@override
|
|
State<TerminalTestApp> createState() => TerminalTestAppState();
|
|
}
|
|
|
|
class TerminalTestAppState extends State<TerminalTestApp> {
|
|
final WindowManager manager = WindowManager(kinds: WindowKinds());
|
|
late final TerminalWindows floating = TerminalWindows(
|
|
manager: manager,
|
|
hub: widget.hub,
|
|
layout: widget.layout,
|
|
);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
floating
|
|
..start()
|
|
..ready();
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
floating.dispose();
|
|
manager.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) => TerminalSurface(
|
|
hub: widget.hub,
|
|
layout: widget.layout,
|
|
cupertino: false,
|
|
shortcutHere: widget.shortcutHere,
|
|
floating: floating,
|
|
windows: WindowHost(manager: manager),
|
|
child: Scaffold(
|
|
appBar: AppBar(
|
|
title: const Text('App'),
|
|
actions: [
|
|
TerminalToggleButton(layout: widget.layout, cupertino: false),
|
|
],
|
|
),
|
|
body: const TextField(key: appField),
|
|
),
|
|
);
|
|
}
|
|
|
|
/// The test app's window manager.
|
|
WindowManager terminalWindowManager(WidgetTester tester) =>
|
|
tester.state<TerminalTestAppState>(find.byType(TerminalTestApp)).manager;
|
|
|
|
/// Presses [key] with [modifiers] held, then lets the motion finish unless
|
|
/// [settle] is false.
|
|
Future<void> chord(
|
|
WidgetTester tester,
|
|
LogicalKeyboardKey key,
|
|
List<LogicalKeyboardKey> modifiers, {
|
|
bool settle = true,
|
|
}) async {
|
|
for (final modifier in modifiers) {
|
|
await tester.sendKeyDownEvent(modifier);
|
|
}
|
|
await tester.sendKeyEvent(key);
|
|
for (final modifier in modifiers.reversed) {
|
|
await tester.sendKeyUpEvent(modifier);
|
|
}
|
|
if (settle) {
|
|
await tester.pumpAndSettle();
|
|
} else {
|
|
await tester.pump();
|
|
}
|
|
}
|
|
|
|
Future<void> altT(WidgetTester tester, {bool settle = true}) => chord(
|
|
tester,
|
|
LogicalKeyboardKey.keyT,
|
|
[LogicalKeyboardKey.altLeft],
|
|
settle: settle,
|
|
);
|
|
|
|
Future<void> ctrlTab(WidgetTester tester, {bool reverse = false}) => chord(
|
|
tester,
|
|
LogicalKeyboardKey.tab,
|
|
[LogicalKeyboardKey.controlLeft, if (reverse) LogicalKeyboardKey.shiftLeft],
|
|
);
|
|
|
|
/// The terminal whose emulator has the keyboard, or null.
|
|
ChatShellTerminalView? focusedTerminal() => FocusManager
|
|
.instance
|
|
.primaryFocus
|
|
?.context
|
|
?.findAncestorWidgetOfExactType<ChatShellTerminalView>();
|
|
|
|
/// Whether [tab]'s emulator has the keyboard.
|
|
bool terminalFocused(String key) =>
|
|
focusedTerminal()?.key == ValueKey('terminal-view-$key');
|
|
|
|
/// Whether the app's text field has the keyboard.
|
|
bool appFieldFocused(WidgetTester tester) => tester
|
|
.widget<EditableText>(
|
|
find.descendant(
|
|
of: find.byKey(appField),
|
|
matching: find.byType(EditableText),
|
|
),
|
|
)
|
|
.focusNode
|
|
.hasFocus;
|
|
|
|
final Finder panelFinder = find.byKey(const ValueKey('terminal-panel'));
|
|
|
|
/// The terminal's floating window, shown or hiding.
|
|
final Finder floatLayer = find.byWidgetPredicate(
|
|
(w) => w is WindowLayer && w.entry.kind == terminalWindowKind,
|
|
skipOffstage: false,
|
|
);
|
|
|
|
/// The terminal's floating window while it is shown.
|
|
final Finder floatFinder = find.byWidgetPredicate(
|
|
(w) => w is WindowLayer && w.entry.kind == terminalWindowKind && w.visible,
|
|
);
|