Toggle the terminal with Alt/Ctrl/Cmd+T, animate it, focus it, and cycle its tabs with Ctrl+Tab

Alt+T, Ctrl+T and Cmd+T join Ctrl+` as early focus-manager key handlers, so
they toggle the panel, window or narrow page from anywhere without reaching
the shell or a text field. Opening with no terminal starts one. The shown
terminal takes the keyboard (also on reload and tab changes) and hiding gives
it back. The panel slides from the bottom edge as the app shrinks, the window
scales and fades, both on Motion.standard and off under reduced motion.
While shown, Ctrl+Tab/Ctrl+Shift+Tab move between terminal tabs instead of
chat panes. The tooltip and menu list the shortcuts the platform delivers.
This commit is contained in:
2026-11-09 23:43:56 +00:00
parent 371d29224c
commit 30934aa71c
22 changed files with 1139 additions and 158 deletions
+37 -47
View File
@@ -5,30 +5,17 @@ import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'terminal_body.dart';
import 'terminal_float_frame.dart';
import 'terminal_hub.dart';
import 'terminal_layout.dart';
import 'terminal_tab_strip.dart';
/// Margin a maximised window keeps from the edges of the app.
const double terminalFloatMargin = 8;
/// [rect] moved and shrunk to fit inside [bounds], at least the minimum
/// window size where the bounds allow it.
Rect fitTerminalFloat(Rect rect, Size bounds) {
final width = rect.width
.clamp(terminalFloatMinSize.width, double.infinity)
.clamp(0.0, bounds.width);
final height = rect.height
.clamp(terminalFloatMinSize.height, double.infinity)
.clamp(0.0, bounds.height);
final left = rect.left.clamp(0.0, bounds.width - width);
final top = rect.top.clamp(0.0, bounds.height - height);
return Rect.fromLTWH(left, top, width, height);
}
export 'terminal_float_frame.dart' show fitTerminalFloat, terminalFloatMargin;
/// The terminal as a window over the app: moved by its title bar, resized
/// from its lower right corner, minimised to its title bar or maximised to
/// the app. Its frame is kept in [layout].
/// the app. Its frame is kept in [layout]. It grows and fades in from its
/// place as [reveal] runs forward, and shrinks and fades out in reverse.
class TerminalFloat extends StatelessWidget {
const TerminalFloat({
super.key,
@@ -36,12 +23,25 @@ class TerminalFloat extends StatelessWidget {
required this.layout,
required this.cupertino,
required this.bounds,
this.reveal = kAlwaysCompleteAnimation,
this.focus,
this.hiding = false,
});
final TerminalHub hub;
final TerminalLayout layout;
final bool cupertino;
final Size bounds;
final Animation<double> reveal;
/// The terminal's focus scope (see [TerminalBody.focus]).
final FocusScopeNode? focus;
/// While the window hides it takes no input.
final bool hiding;
/// The scale the window grows from as it shows.
static const double revealScale = 0.92;
/// Where the window is drawn now.
Rect get frame => layout.maximized
@@ -91,7 +91,11 @@ class TerminalFloat extends StatelessWidget {
cupertino: cupertino,
),
Expanded(
child: TerminalBody(hub: hub, cupertino: cupertino),
child: TerminalBody(
hub: hub,
cupertino: cupertino,
focus: focus,
),
),
],
),
@@ -104,36 +108,22 @@ class TerminalFloat extends StatelessWidget {
return Positioned(
left: rect.left,
top: rect.top,
child: Semantics(
container: true,
label: 'Terminal window',
child: _chrome(context, window),
),
);
}
Widget _chrome(BuildContext context, Widget child) {
if (!cupertino) {
return Material(
elevation: 8,
clipBehavior: Clip.antiAlias,
borderRadius: BorderRadius.circular(12),
color: Theme.of(context).colorScheme.surfaceContainer,
child: child,
);
}
return DecoratedBox(
decoration: BoxDecoration(
color: CupertinoColors.secondarySystemBackground.resolveFrom(context),
borderRadius: BorderRadius.circular(12),
border: Border.all(
color: CupertinoColors.separator.resolveFrom(context),
child: IgnorePointer(
ignoring: hiding,
child: ExcludeFocus(
excluding: hiding,
child: FadeTransition(
opacity: reveal,
child: ScaleTransition(
scale: Tween<double>(begin: revealScale, end: 1).animate(reveal),
child: Semantics(
container: true,
label: 'Terminal window',
child: terminalFloatChrome(context, cupertino, window),
),
),
),
),
boxShadow: const [BoxShadow(blurRadius: 16, color: Color(0x33000000))],
),
child: ClipRRect(
borderRadius: BorderRadius.circular(12),
child: Material(type: MaterialType.transparency, child: child),
),
);
}