Match chat terminal buttons to responsive UI
Remove the duplicate terminal action from narrow shell bars and expose the terminal in open chat bars only where appropriate. Use the shared plain bar-button styling and add focused light/dark responsive widget coverage.
This commit is contained in:
@@ -8,6 +8,7 @@ import '../features/terminal/terminal_machines.dart';
|
||||
import '../features/terminal/terminal_surface.dart';
|
||||
import '../features/terminal/terminal_toggle_button.dart';
|
||||
import '../features/terminal/terminal_window.dart';
|
||||
import '../shell/list_detail_policy.dart';
|
||||
import '../shell/windows/window_manager.dart';
|
||||
|
||||
/// The app's machine terminals: one hub over every connected machine (the
|
||||
@@ -66,6 +67,14 @@ class AppTerminals {
|
||||
/// The bar button showing or hiding the terminal.
|
||||
Widget toggle() => TerminalToggleButton(layout: layout);
|
||||
|
||||
/// The Chat tab's shell-bar button. Only a wide layout shows the shell bar
|
||||
/// over an open chat, so only there is it kept. A narrow layout has none:
|
||||
/// its open chat's own bar carries the terminal (see
|
||||
/// `terminalChatBarAction`), and a chat list's bar has none (the shortcut
|
||||
/// still shows the terminal).
|
||||
Widget? barToggle(BuildContext context) =>
|
||||
showsListBesideDetail(context) ? toggle() : null;
|
||||
|
||||
void dispose() {
|
||||
floating?.dispose();
|
||||
hub.dispose();
|
||||
|
||||
@@ -820,13 +820,14 @@ class _PipelinesAppState extends State<PipelinesApp>
|
||||
final runsRoute = tab(AppDestination.runs);
|
||||
final chatRoute = tab(AppDestination.chat);
|
||||
return AdaptiveShell(
|
||||
// The terminal button sits on the Chat tab only; the keyboard
|
||||
// The terminal button sits on the Chat tab's shell bar on wide layouts;
|
||||
// a narrow layout has it in the chat's own bar instead. The keyboard
|
||||
// shortcut still toggles the terminal everywhere.
|
||||
barActions: [
|
||||
// Shown on every tab while the app has floating windows.
|
||||
WindowsMenuButton(manager: _windows),
|
||||
if (_destinationOf(route.kind) == AppDestination.chat)
|
||||
_terminals.toggle(),
|
||||
?_terminals.barToggle(context),
|
||||
],
|
||||
attentionCount: counts.attention,
|
||||
runningRunCount: counts.running,
|
||||
|
||||
@@ -1476,6 +1476,9 @@ class _ChatThreadViewState extends State<ChatThreadView> {
|
||||
onPressed: _toggleFiles,
|
||||
materialIcon: _filesVisible ? Icons.folder : Icons.folder_outlined,
|
||||
),
|
||||
// A narrow layout's terminal button, beside Files; wide keeps the
|
||||
// shell bar's.
|
||||
?terminalChatBarAction(context),
|
||||
],
|
||||
moreActions: [
|
||||
?widget.sidebarControl,
|
||||
|
||||
@@ -3,9 +3,12 @@ import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../core/api_gateway.dart';
|
||||
import '../../shell/list_detail_policy.dart';
|
||||
import '../../ui/adaptive/segmented_bar_overflow.dart';
|
||||
import '../chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'terminal_hub.dart';
|
||||
import 'terminal_scope.dart';
|
||||
import 'terminal_toggle_button.dart';
|
||||
|
||||
/// The first time the terminal is shown in an app run it starts one
|
||||
/// terminal, as New terminal does (it shows the machine's login prompt),
|
||||
@@ -49,6 +52,23 @@ void openInTerminal(
|
||||
);
|
||||
}
|
||||
|
||||
/// The open chat's own bar button that shows or hides the terminal, on a
|
||||
/// narrow layout. It is a plain [ChatBarAction] like Files and More, so it
|
||||
/// matches them in style, size and states. A wide layout returns null: its
|
||||
/// shell bar keeps the terminal button over the list column. Null too with
|
||||
/// no terminal surface.
|
||||
Widget? terminalChatBarAction(BuildContext context) {
|
||||
if (showsListBesideDetail(context)) return null;
|
||||
final actions = TerminalScope.maybeOf(context);
|
||||
if (actions == null) return null;
|
||||
return ChatBarAction(
|
||||
label: TerminalToggleButton.label,
|
||||
identifier: 'chat-terminal-toggle',
|
||||
onPressed: actions.toggle,
|
||||
materialIcon: Icons.terminal,
|
||||
);
|
||||
}
|
||||
|
||||
/// The chat actions menu's "Open in terminal" for the chat's folder, or
|
||||
/// null when the app has no terminal surface or the chat no folder.
|
||||
Widget? terminalOpenMenuAction(
|
||||
|
||||
@@ -6,6 +6,9 @@ import 'terminal_shortcuts.dart';
|
||||
|
||||
/// The shell bar's Terminal button: shows or hides the terminal (also
|
||||
/// Alt+T, Ctrl+T, Cmd+T and Ctrl+`, where the platform delivers them).
|
||||
///
|
||||
/// It is a plain bar IconButton like Files and More: no selected tint, so
|
||||
/// its shown state is announced to assistive technology only.
|
||||
class TerminalToggleButton extends StatelessWidget {
|
||||
const TerminalToggleButton({super.key, required this.layout});
|
||||
|
||||
@@ -22,12 +25,14 @@ class TerminalToggleButton extends StatelessWidget {
|
||||
listenable: layout,
|
||||
builder: (context, _) {
|
||||
final shown = layout.visible;
|
||||
return IconButton(
|
||||
key: const ValueKey('shell.terminal'),
|
||||
tooltip: label,
|
||||
isSelected: shown,
|
||||
onPressed: actions.toggle,
|
||||
icon: const Icon(Icons.terminal),
|
||||
return Semantics(
|
||||
toggled: shown,
|
||||
child: IconButton(
|
||||
key: const ValueKey('shell.terminal'),
|
||||
tooltip: label,
|
||||
onPressed: actions.toggle,
|
||||
icon: const Icon(Icons.terminal),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
# Chat terminal buttons (narrow duplicate, bar styling)
|
||||
|
||||
## Findings (from the code and the ui-review captures)
|
||||
|
||||
- The terminal toggle is the shell's bar action, passed as `barActions` from
|
||||
`application/pipelines_app.dart` on the Chat tab. The shell draws that bar
|
||||
only where it is not covered:
|
||||
- Wide (>= 600, `kListDetailMinWidth`): the shell bar sits over the list
|
||||
column while a chat is open, so the terminal shows there beside New chat
|
||||
and Refresh (capture: `Terminal (Option+T)` at x 287). The chat's own bar
|
||||
holds only Files and More.
|
||||
- Narrow (< 600): the open chat is a pushed page with its own bar
|
||||
(`ShellBar(barless: true)`), which covers the shell bar. A shell-bar
|
||||
terminal button therefore never shows on a phone chat, even though it was
|
||||
listed in `barActions`. This is why the first attempt (keeping it in
|
||||
`barActions` for an open chat) rendered nothing on phone.
|
||||
- Narrow chat list: the shell bar shows the toggle beside New chat and
|
||||
Refresh (the duplicate this change removes).
|
||||
- The styling difference: `TerminalToggleButton` passed `isSelected: shown`,
|
||||
which tints the icon while the terminal is shown. Files and More
|
||||
(`ChatBarAction`, `SegmentedMoreButton`) are plain IconButtons with no
|
||||
selected state.
|
||||
|
||||
## Changes
|
||||
|
||||
- `lib/application/app_terminals.dart`: `barToggle(context)` returns the shell
|
||||
toggle only on a wide layout; null on narrow (chat list and open chat).
|
||||
- `lib/application/pipelines_app.dart`: the Chat tab's `barActions` uses
|
||||
`?_terminals.barToggle(context)`.
|
||||
- `lib/features/terminal/terminal_open_action.dart`: new
|
||||
`terminalChatBarAction(context)`: on narrow, with a terminal surface, a
|
||||
`ChatBarAction` (the same widget as Files) that toggles the terminal
|
||||
(identifier `chat-terminal-toggle`). Null on wide or without a surface.
|
||||
- `lib/features/chat/conversation/chat_thread_view.dart`: the chat header's
|
||||
actions are Files followed by `?terminalChatBarAction(context)`, so a
|
||||
narrow open chat shows the terminal beside Files.
|
||||
- `lib/features/terminal/terminal_toggle_button.dart`: drops `isSelected`; the
|
||||
shown state is exposed as `Semantics(toggled:)` only.
|
||||
|
||||
## Tests
|
||||
|
||||
- `test/application/app_terminals_test.dart`: wide 1000 px offers the shell
|
||||
toggle; narrow 390 px offers none.
|
||||
- `test/features/terminal/terminal_chat_bar_action_test.dart`, light and dark:
|
||||
phone 390 px: the chat bar's terminal button is present, the same size as
|
||||
Files, the same icon colour, not selected, and tapping it toggles the
|
||||
terminal; wide 1000 px and no terminal surface: no chat-bar terminal button.
|
||||
- `test/features/terminal/terminal_toggle_button_test.dart`, light and dark:
|
||||
the shell's terminal button has no `isSelected`, its icon colour equals
|
||||
Files' in hidden and shown states, both are 48 px, and the shown state is
|
||||
announced as toggled.
|
||||
- Affected users re-run: `terminal_first_open_test.dart`,
|
||||
`terminal_surface_test.dart`, `chat_floating_chrome_test.dart`,
|
||||
`chat_floating_pane_test.dart`.
|
||||
|
||||
## Focused results
|
||||
|
||||
`tool/memwatch/full.sh` with the seven paths above as one argument:
|
||||
57 passed, 0 failed (peak 1877 MB, 53 s; verdict names only those paths).
|
||||
`tool/analyze.sh`: clean.
|
||||
|
||||
## Expected states (from the code; not captured here)
|
||||
|
||||
- Phone chat list: no terminal in the bar; the shortcut bubble remains.
|
||||
- Phone open chat: the chat bar reads Files, terminal, More; the terminal is
|
||||
the same 48 px plain IconButton style as Files.
|
||||
- Wide chat list and wide open chat: placement unchanged; the shell bar's
|
||||
terminal button is plain (no selected tint).
|
||||
|
||||
## Not verified here
|
||||
|
||||
- Rendered states at phone and desktop sizes, light and dark, and hover and
|
||||
pressed states: not captured (ui-review owns captures).
|
||||
- `pipelines_app.dart` wiring has no direct test.
|
||||
`test/application/pipelines_app_test.dart` fails on untouched main (pending
|
||||
launch-update timer), so it was not run.
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/application/app_terminals.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
||||
|
||||
import '../features/terminal/terminal_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
late TerminalGateway gateway;
|
||||
late AppTerminals terminals;
|
||||
|
||||
setUp(() {
|
||||
gateway = TerminalGateway();
|
||||
terminals = AppTerminals(
|
||||
pool: null,
|
||||
connection: ValueNotifier<int>(0),
|
||||
connected: () => true,
|
||||
gateway: gateway,
|
||||
machineId: 'mac',
|
||||
machineName: 'Mac',
|
||||
layout: TerminalLayout(store: MemoryLayoutStore()),
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
terminals.dispose();
|
||||
gateway.close();
|
||||
});
|
||||
|
||||
/// Pumps [AppTerminals.barToggle] at [width] and returns what it built.
|
||||
Future<Widget?> barToggleAt(WidgetTester tester, double width) async {
|
||||
Widget? built;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: MediaQuery(
|
||||
data: MediaQueryData(size: Size(width, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
built = terminals.barToggle(context);
|
||||
return const SizedBox.shrink();
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
return built;
|
||||
}
|
||||
|
||||
testWidgets('the Chat shell bar offers the terminal toggle on a wide layout', (
|
||||
tester,
|
||||
) async {
|
||||
final built = await barToggleAt(tester, 1000);
|
||||
expect(built, isA<TerminalToggleButton>());
|
||||
});
|
||||
|
||||
testWidgets('a narrow layout has no terminal toggle in the shell bar', (
|
||||
tester,
|
||||
) async {
|
||||
// Covers both a narrow chat list and an open narrow chat: the open chat's
|
||||
// own bar carries the terminal (terminal_chat_bar_action_test.dart).
|
||||
final built = await barToggleAt(tester, 390);
|
||||
expect(built, isNull);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,149 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_open_action.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
||||
|
||||
class _Actions implements TerminalActions {
|
||||
int toggles = 0;
|
||||
|
||||
@override
|
||||
void toggle() => toggles++;
|
||||
|
||||
@override
|
||||
bool get claimsTabKeys => false;
|
||||
|
||||
@override
|
||||
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
|
||||
}
|
||||
|
||||
const _filesKey = ValueKey('files');
|
||||
const _terminalIdentifier = 'chat-terminal-toggle';
|
||||
|
||||
/// Pumps an open chat's bar at [width]: Files, then whatever
|
||||
/// [terminalChatBarAction] builds (null on wide or with no terminal surface).
|
||||
/// Returns what it built.
|
||||
Future<Widget?> _pumpBar(
|
||||
WidgetTester tester, {
|
||||
required double width,
|
||||
required ThemeData theme,
|
||||
_Actions? actions,
|
||||
}) async {
|
||||
Widget? built;
|
||||
final bar = MediaQuery(
|
||||
data: MediaQueryData(size: Size(width, 800)),
|
||||
child: Scaffold(
|
||||
body: Builder(
|
||||
builder: (context) {
|
||||
built = terminalChatBarAction(context);
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ChatBarAction(
|
||||
key: _filesKey,
|
||||
label: 'Files',
|
||||
onPressed: () {},
|
||||
materialIcon: Icons.folder_outlined,
|
||||
),
|
||||
?built,
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: actions == null
|
||||
? bar
|
||||
: TerminalScope(actions: actions, child: bar),
|
||||
),
|
||||
);
|
||||
await tester.pump();
|
||||
return built;
|
||||
}
|
||||
|
||||
/// The colour an icon inside [finder] resolves to in the current theme.
|
||||
Color? _iconColor(WidgetTester tester, Finder finder) {
|
||||
final icon = find.descendant(of: finder, matching: find.byType(Icon));
|
||||
final element = tester.element(icon);
|
||||
return tester.widget<Icon>(icon).color ?? IconTheme.of(element).color;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final theme in [
|
||||
ThemeData(brightness: Brightness.light, useMaterial3: true),
|
||||
ThemeData(brightness: Brightness.dark, useMaterial3: true),
|
||||
]) {
|
||||
final mode = theme.brightness.name;
|
||||
|
||||
testWidgets('$mode, phone: an open chat has a terminal button beside '
|
||||
'Files, styled as Files', (tester) async {
|
||||
final actions = _Actions();
|
||||
final built = await _pumpBar(
|
||||
tester,
|
||||
width: 390,
|
||||
theme: theme,
|
||||
actions: actions,
|
||||
);
|
||||
expect(built, isA<ChatBarAction>());
|
||||
|
||||
final terminal = find.bySemanticsIdentifier(_terminalIdentifier);
|
||||
final files = find.byKey(_filesKey);
|
||||
expect(terminal, findsOneWidget);
|
||||
expect(
|
||||
tester.getSize(terminal),
|
||||
tester.getSize(files),
|
||||
reason: 'the terminal button must be the same size as Files',
|
||||
);
|
||||
expect(
|
||||
_iconColor(tester, terminal),
|
||||
_iconColor(tester, files),
|
||||
reason: 'the terminal icon must share the colour of Files',
|
||||
);
|
||||
expect(
|
||||
tester
|
||||
.widget<IconButton>(
|
||||
find.descendant(of: terminal, matching: find.byType(IconButton)),
|
||||
)
|
||||
.isSelected,
|
||||
isNull,
|
||||
reason: 'the terminal must not be a selected (tinted) button',
|
||||
);
|
||||
expect(find.byTooltip(TerminalToggleButton.label), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('$mode, phone: tapping the terminal button toggles the '
|
||||
'terminal', (tester) async {
|
||||
final actions = _Actions();
|
||||
await _pumpBar(tester, width: 390, theme: theme, actions: actions);
|
||||
|
||||
await tester.tap(find.byTooltip(TerminalToggleButton.label));
|
||||
await tester.pump();
|
||||
expect(actions.toggles, 1);
|
||||
});
|
||||
|
||||
testWidgets('$mode, wide: the open chat bar has no terminal button (the '
|
||||
'shell bar keeps it)', (tester) async {
|
||||
final built = await _pumpBar(
|
||||
tester,
|
||||
width: 1000,
|
||||
theme: theme,
|
||||
actions: _Actions(),
|
||||
);
|
||||
expect(built, isNull);
|
||||
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('$mode, phone without a terminal surface: no terminal button', (
|
||||
tester,
|
||||
) async {
|
||||
final built = await _pumpBar(tester, width: 390, theme: theme);
|
||||
expect(built, isNull);
|
||||
expect(find.bySemanticsIdentifier(_terminalIdentifier), findsNothing);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import 'dart:ui' as ui;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/semantics.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_adaptive.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_layout.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_scope.dart';
|
||||
import 'package:pipelines_app/features/terminal/terminal_toggle_button.dart';
|
||||
|
||||
import 'terminal_fixtures.dart';
|
||||
|
||||
class _Actions implements TerminalActions {
|
||||
int toggles = 0;
|
||||
|
||||
@override
|
||||
void toggle() => toggles++;
|
||||
|
||||
@override
|
||||
bool get claimsTabKeys => false;
|
||||
|
||||
@override
|
||||
Future<String?> openAt(ApiGateway gateway, String cwd) async => null;
|
||||
}
|
||||
|
||||
const _filesKey = ValueKey('files');
|
||||
const _terminalKey = ValueKey('shell.terminal');
|
||||
|
||||
/// A chat's bar: Files beside the terminal toggle, as the shell shows them.
|
||||
Widget _bar(TerminalLayout layout, _Actions actions, ThemeData theme) =>
|
||||
MaterialApp(
|
||||
theme: theme,
|
||||
home: TerminalScope(
|
||||
actions: actions,
|
||||
child: Scaffold(
|
||||
body: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
ChatBarAction(
|
||||
key: _filesKey,
|
||||
label: 'Files',
|
||||
onPressed: () {},
|
||||
materialIcon: Icons.folder_outlined,
|
||||
),
|
||||
TerminalToggleButton(layout: layout),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
/// The colour an icon inside [finder] resolves to in the current theme.
|
||||
Color? _iconColor(WidgetTester tester, Finder finder) {
|
||||
final icon = find.descendant(of: finder, matching: find.byType(Icon));
|
||||
final element = tester.element(icon);
|
||||
return tester.widget<Icon>(icon).color ?? IconTheme.of(element).color;
|
||||
}
|
||||
|
||||
/// Whether the terminal button's semantics (or one of its merged parents)
|
||||
/// is announced as toggled on.
|
||||
bool _toggled(WidgetTester tester) {
|
||||
for (
|
||||
SemanticsNode? node = tester.getSemantics(
|
||||
find.byTooltip(TerminalToggleButton.label),
|
||||
);
|
||||
node != null;
|
||||
node = node.parent
|
||||
) {
|
||||
if (node.flagsCollection.isToggled == ui.Tristate.isTrue) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void main() {
|
||||
for (final theme in [
|
||||
ThemeData(brightness: Brightness.light, useMaterial3: true),
|
||||
ThemeData(brightness: Brightness.dark, useMaterial3: true),
|
||||
]) {
|
||||
final mode = theme.brightness.name;
|
||||
|
||||
testWidgets('$mode: the terminal button is a plain bar button, shown or '
|
||||
'hidden, like Files', (tester) async {
|
||||
final layout = TerminalLayout(store: MemoryLayoutStore());
|
||||
final actions = _Actions();
|
||||
await tester.pumpWidget(_bar(layout, actions, theme));
|
||||
await tester.pump();
|
||||
|
||||
final files = find.byKey(_filesKey);
|
||||
final terminal = find.byKey(_terminalKey);
|
||||
for (final shown in [false, true]) {
|
||||
if (shown) layout.show();
|
||||
await tester.pump();
|
||||
|
||||
final button = tester.widget<IconButton>(terminal);
|
||||
expect(button.isSelected, isNull, reason: 'shown: $shown');
|
||||
expect(
|
||||
_iconColor(tester, terminal),
|
||||
_iconColor(tester, files),
|
||||
reason: 'icon colour differs from Files (shown: $shown)',
|
||||
);
|
||||
expect(tester.getSize(terminal), tester.getSize(files));
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('$mode: the shown state is announced without a tint', (
|
||||
tester,
|
||||
) async {
|
||||
final handle = tester.ensureSemantics();
|
||||
final layout = TerminalLayout(store: MemoryLayoutStore());
|
||||
final actions = _Actions();
|
||||
await tester.pumpWidget(_bar(layout, actions, theme));
|
||||
await tester.pump();
|
||||
|
||||
expect(_toggled(tester), isFalse);
|
||||
layout.show();
|
||||
await tester.pump();
|
||||
expect(_toggled(tester), isTrue);
|
||||
await tester.tap(find.byKey(_terminalKey));
|
||||
expect(actions.toggles, 1);
|
||||
handle.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user