Files
pipelines/app/lib/features/terminal/terminal_tab_chip.dart
T

129 lines
4.4 KiB
Dart

import 'package:flutter/material.dart';
/// The widest a tab's title is drawn before it ends in an ellipsis (the
/// tooltip has it whole).
const double terminalTabTitleMaxWidth = 220;
/// One terminal's tab: its [title] (ellipsised, italic once the terminal
/// ended), a bell dot, and a close button, with the whole title and
/// [tooltip] (machine and folder) on hover or long press.
///
/// The selected tab is filled with the secondary container and outlined in
/// the accent, its title bold, so it reads as selected in either theme
/// without relying on colour alone. The close button is a standard
/// [IconButton]: at least 48 px square on touch platforms and 40 px on
/// desktops (the platform's visual density).
class TerminalTabChip extends StatelessWidget {
const TerminalTabChip({
super.key,
required this.title,
required this.tooltip,
required this.selected,
required this.running,
required this.bell,
required this.onSelect,
required this.onClose,
});
final String title;
final String tooltip;
final bool selected;
final bool running;
final bool bell;
final VoidCallback onSelect;
final VoidCallback onClose;
@override
Widget build(BuildContext context) {
final scheme = Theme.of(context).colorScheme;
final foreground = selected
? scheme.onSecondaryContainer
: scheme.onSurfaceVariant;
final label = Text(
title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
softWrap: false,
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: foreground,
fontWeight: selected ? FontWeight.w700 : FontWeight.w500,
fontStyle: running ? null : FontStyle.italic,
),
);
final shape = RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
side: BorderSide(
color: selected ? scheme.primary : scheme.outlineVariant,
width: selected ? 2 : 1,
),
);
return Semantics(
selected: selected,
child: Material(
shape: shape,
color: selected ? scheme.secondaryContainer : Colors.transparent,
clipBehavior: Clip.antiAlias,
// The title's ink fills the tab's height (the close button's).
child: IntrinsicHeight(
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Tooltip(
message: tooltip,
child: InkWell(
onTap: onSelect,
child: Semantics(
button: true,
child: Padding(
padding: const EdgeInsetsDirectional.only(
start: 12,
end: 4,
),
child: ConstrainedBox(
// A short title such as `~` still leaves a select
// target wider than the close button beside it.
constraints: const BoxConstraints(
minWidth: kMinInteractiveDimension,
maxWidth: terminalTabTitleMaxWidth,
),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Flexible(child: label),
if (bell)
Padding(
padding: const EdgeInsetsDirectional.only(
start: 6,
),
// The bell rang while the terminal was not
// shown.
child: Semantics(
label: 'Bell',
child: Badge(
key: const ValueKey('terminal-tab-bell'),
),
),
),
],
),
),
),
),
),
),
IconButton(
tooltip: 'Close terminal',
onPressed: onClose,
color: foreground,
iconSize: 18,
icon: const Icon(Icons.close),
),
],
),
),
),
);
}
}