feat: tabs own the panel header, a Termux key bar, and agent memory

- The panel's top row is now the tab group plus the close button; each tab
  keeps its own header: the files tab has the breadcrumb with new/more (or
  the name and edit/download while previewing), knowledge its search and
  refresh, the terminal its status.
- The key bar is Termux's two rows of seven: ESC / — HOME ↑ END PGUP, then
  TAB CTRL ALT ← ↓ → PGDN; the modifiers still apply to what the phone
  keyboard types.
- The panel is a dialog, so it gives the IME's height back itself
  (viewInsets.bottom). The key bar and the terminal stay above the
  keyboard, and the PTY reflows to the smaller terminal.
- Project knowledge gains the memory tab: both scopes from
  /api/agent-memory/all, absent when the server has memory switched off,
  with type, edit and delete.
- File preview editing passes minLines: null alongside expands.
- 0.3.12 (312).
This commit is contained in:
blumia committed 2026-11-21 11:09:44 +08:00
1 parent 5f95e2da97
commit 5a371e4faf
8 files changed
+675 -231

No files matched your search

+180 -168
View File
@@ -387,57 +387,198 @@ class _FilesPanelState extends State<FilesPanel> {
Widget build(BuildContext context) {
final theme = Theme.of(context);
return SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
child: Padding(
// The panel is a dialog, so it does not shrink for the keyboard on its
// own: give the IME's height back here, or it covers the terminal's
// key bar and its last lines.
padding:
EdgeInsets.only(bottom: MediaQuery.viewInsetsOf(context).bottom),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_tabs(theme),
const Divider(height: 1),
Expanded(child: _body(theme)),
],
),
),
);
}
/// The tab row is the panel's title now; the only global action left is
/// closing the panel. Everything else belongs to the tab's own header.
Widget _tabs(ThemeData theme) {
const labels = ['文件', '项目知识', '终端'];
return Padding(
padding: const EdgeInsets.fromLTRB(12, 6, 2, 6),
child: Row(
children: [
_header(theme),
_tabs(theme),
const Divider(height: 1),
Expanded(child: _body(theme)),
Expanded(
child: SegmentedButton<int>(
showSelectedIcon: false,
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: [
for (var i = 0; i < labels.length; i++)
ButtonSegment(value: i, label: Text(labels[i])),
],
selected: {_tab},
onSelectionChanged: (v) => setState(() => _tab = v.first),
),
),
IconButton(
icon: const Icon(Icons.close),
tooltip: '关闭侧栏',
onPressed: () => Navigator.of(context).maybePop(),
),
],
),
);
}
Widget _header(ThemeData theme) {
return Padding(
padding: const EdgeInsets.fromLTRB(6, 6, 6, 0),
child: Row(
children: [
if (_previewPath != null)
IconButton(
icon: const Icon(Icons.arrow_back),
tooltip: '返回',
onPressed: () => setState(() => _previewPath = null),
)
else
const SizedBox(width: 8),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
Widget _body(ThemeData theme) {
if (_root.isEmpty) {
return const Center(child: Text('这个会话没有关联目录'));
}
switch (_tab) {
case 1:
return KnowledgePanel(app: widget.app, directory: _root);
case 2:
return TerminalPanel(app: widget.app, directory: _root);
default:
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_pathBar(theme),
Expanded(
child: _previewPath != null
? _previewBody(theme)
: _browserBody(theme),
),
],
);
}
}
Widget _browserBody(ThemeData theme) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 6),
child: Row(
children: [
Expanded(
child: TextField(
controller: _search,
onChanged: (v) => setState(() {
_query = v;
_deepResults = [];
_deepDone = false;
}),
style: const TextStyle(fontSize: 14),
decoration: InputDecoration(
isDense: true,
prefixIcon: const Icon(Icons.search, size: 20),
hintText: '搜索当前目录…',
suffixIcon: _query.trim().isEmpty
? null
: IconButton(
icon: const Icon(Icons.travel_explore, size: 20),
tooltip: '搜索子目录',
onPressed: _searching ? null : _deepSearch,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12)),
contentPadding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
),
),
),
],
),
),
if (_searching)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
children: [
Text(_previewPath != null ? _previewName : '文件',
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 16, fontWeight: FontWeight.w600)),
if (_previewPath == null && _root.isNotEmpty)
Text(_rootName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 12, color: theme.hintColor)),
const SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(strokeWidth: 2)),
const SizedBox(width: 8),
Text('正在搜索子目录…(${_deepResults.length})',
style: TextStyle(fontSize: 12, color: theme.hintColor)),
],
),
),
if (_previewPath != null) ...[
Expanded(child: _list(theme)),
],
);
}
/// The tab's own header: where you are, plus what you can do here. The
/// panel's global actions (close) sit in the tab row above.
Widget _pathBar(ThemeData theme) {
final crumbs = _crumbs;
final preview = _previewPath != null;
return Padding(
padding: const EdgeInsets.fromLTRB(4, 0, 4, 4),
child: Row(
children: [
IconButton(
icon: Icon(preview ? Icons.arrow_back : Icons.arrow_upward,
size: 20),
tooltip: preview ? '返回' : '上一级',
onPressed: preview
? () => setState(() => _previewPath = null)
: (_path == _root ? null : _up),
),
Expanded(
child: preview
? Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(_previewName,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13.5, fontWeight: FontWeight.w600)),
Text(_previewPath!,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: TextStyle(
fontSize: 11, color: theme.hintColor)),
],
)
: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_crumb(theme, _rootName, () => _load(_root),
last: crumbs.isEmpty),
for (var i = 0; i < crumbs.length; i++) ...[
Text(' / ', style: TextStyle(color: theme.hintColor)),
_crumb(theme, crumbs[i], () => _goToCrumb(i),
last: i == crumbs.length - 1),
],
],
),
),
),
if (preview) ...[
if (_previewText != null)
IconButton(
icon: Icon(_editing ? Icons.visibility_outlined : Icons.edit_outlined),
icon: Icon(_editing
? Icons.visibility_outlined
: Icons.edit_outlined),
tooltip: _editing ? '预览' : '编辑',
onPressed: _saving
? null
: () => setState(() => _editing = !_editing),
onPressed:
_saving ? null : () => setState(() => _editing = !_editing),
),
if (_editing)
IconButton(
@@ -495,136 +636,6 @@ class _FilesPanelState extends State<FilesPanel> {
],
),
],
IconButton(
icon: const Icon(Icons.close),
tooltip: '关闭',
onPressed: () => Navigator.of(context).maybePop(),
),
],
),
);
}
Widget _tabs(ThemeData theme) {
const labels = ['文件', '项目知识', '终端'];
return Padding(
padding: const EdgeInsets.fromLTRB(12, 4, 12, 8),
child: SegmentedButton<int>(
showSelectedIcon: false,
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: [
for (var i = 0; i < labels.length; i++)
ButtonSegment(value: i, label: Text(labels[i])),
],
selected: {_tab},
onSelectionChanged: (v) => setState(() => _tab = v.first),
),
);
}
Widget _body(ThemeData theme) {
if (_root.isEmpty) {
return const Center(child: Text('这个会话没有关联目录'));
}
switch (_tab) {
case 1:
return KnowledgePanel(app: widget.app, directory: _root);
case 2:
return TerminalPanel(app: widget.app, directory: _root);
default:
if (_previewPath != null) return _previewBody(theme);
return _browser(theme);
}
}
Widget _browser(ThemeData theme) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
_pathBar(theme),
Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 6),
child: Row(
children: [
Expanded(
child: TextField(
controller: _search,
onChanged: (v) => setState(() {
_query = v;
_deepResults = [];
_deepDone = false;
}),
style: const TextStyle(fontSize: 14),
decoration: InputDecoration(
isDense: true,
prefixIcon: const Icon(Icons.search, size: 20),
hintText: '搜索当前目录…',
suffixIcon: _query.trim().isEmpty
? null
: IconButton(
icon: const Icon(Icons.travel_explore, size: 20),
tooltip: '搜索子目录',
onPressed: _searching ? null : _deepSearch,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12)),
contentPadding:
const EdgeInsets.symmetric(vertical: 10, horizontal: 12),
),
),
),
],
),
),
if (_searching)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
children: [
const SizedBox(
width: 14,
height: 14,
child: CircularProgressIndicator(strokeWidth: 2)),
const SizedBox(width: 8),
Text('正在搜索子目录…(${_deepResults.length})',
style: TextStyle(fontSize: 12, color: theme.hintColor)),
],
),
),
Expanded(child: _list(theme)),
],
);
}
Widget _pathBar(ThemeData theme) {
final crumbs = _crumbs;
return Padding(
padding: const EdgeInsets.fromLTRB(4, 0, 8, 4),
child: Row(
children: [
IconButton(
icon: const Icon(Icons.arrow_upward, size: 20),
tooltip: '上一级',
onPressed: _path == _root ? null : _up,
),
Expanded(
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: [
_crumb(theme, _rootName, () => _load(_root), last: crumbs.isEmpty),
for (var i = 0; i < crumbs.length; i++) ...[
Text(' / ', style: TextStyle(color: theme.hintColor)),
_crumb(theme, crumbs[i], () => _goToCrumb(i),
last: i == crumbs.length - 1),
],
],
),
),
),
],
),
);
@@ -800,6 +811,7 @@ class _FilesPanelState extends State<FilesPanel> {
child: TextField(
controller: _editor,
maxLines: null,
minLines: null,
expands: true,
style: const TextStyle(fontSize: 13, fontFamily: 'monospace', height: 1.4),
textAlignVertical: TextAlignVertical.top,
+316 -17
View File
@@ -18,9 +18,13 @@ class KnowledgePanel extends StatefulWidget {
class _KnowledgePanelState extends State<KnowledgePanel> {
ProjectContext? _context;
/// Null when the server has agent memory switched off, in which case the
/// memory section is not offered at all.
AgentMemorySnapshot? _memory;
bool _loading = true;
String? _error;
int _section = 0;
String _section = 'notes';
String _query = '';
final TextEditingController _search = TextEditingController();
@@ -53,11 +57,19 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
_error = null;
});
try {
final context = await client.projectContext(_projectId,
directory: widget.directory);
// Both reads in one go: the memory tab appears with the rest instead of
// popping in a moment later.
final results = await Future.wait([
client.projectContext(_projectId, directory: widget.directory),
client.agentMemory(_projectId, directory: widget.directory),
]);
if (!mounted) return;
final context = results[0] as ProjectContext;
final memory = results[1] as AgentMemorySnapshot?;
setState(() {
_context = context;
_memory = memory;
if (memory == null && _section == 'memory') _section = 'notes';
_loading = false;
});
} catch (error) {
@@ -93,7 +105,7 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
return Column(
children: [
Padding(
padding: const EdgeInsets.fromLTRB(12, 0, 4, 0),
padding: const EdgeInsets.fromLTRB(12, 6, 4, 0),
child: Row(
children: [
Expanded(
@@ -103,7 +115,9 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
style: const TextStyle(fontSize: 13),
decoration: InputDecoration(
isDense: true,
hintText: '搜索笔记、待办与计划',
hintText: _memory == null
? '搜索笔记、待办与计划'
: '搜索笔记、待办、计划与记忆',
prefixIcon: const Icon(Icons.search, size: 18),
suffixIcon: _query.isEmpty
? null
@@ -134,25 +148,31 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
);
}
Widget _sections(ThemeData theme) {
final context_ = _context;
final counts = [
context_?.notes.length ?? 0,
context_?.todos.length ?? 0,
context_?.plans.length ?? 0,
List<(String, String, int)> get _sectionsList {
final context = _context;
return [
('notes', '笔记', context?.notes.length ?? 0),
('todos', '待办', context?.todos.length ?? 0),
('plans', '计划', context?.plans.length ?? 0),
if (_memory != null)
('memory', '记忆',
(_memory!.global.length + _memory!.project.length)),
];
const names = ['笔记', '待办', '计划'];
}
Widget _sections(ThemeData theme) {
final sections = _sectionsList;
return Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 12, 6),
child: SegmentedButton<int>(
child: SegmentedButton<String>(
showSelectedIcon: false,
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: [
for (var i = 0; i < names.length; i++)
ButtonSegment(value: i, label: Text('${names[i]} ${counts[i]}')),
for (final (key, label, count) in sections)
ButtonSegment(value: key, label: Text('$label $count')),
],
selected: {_section},
onSelectionChanged: (value) => setState(() => _section = value.first),
@@ -180,10 +200,12 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
);
}
switch (_section) {
case 1:
case 'todos':
return _todos(theme);
case 2:
case 'plans':
return _plans(theme);
case 'memory':
return _memoryBody(theme);
default:
return _notes(theme);
}
@@ -480,6 +502,195 @@ class _KnowledgePanelState extends State<KnowledgePanel> {
);
}
// -------------------------------------------------------------- memory
Widget _memoryBody(ThemeData theme) {
final snapshot = _memory;
if (snapshot == null) {
return _empty(theme, Icons.psychology_outlined, '记忆功能未启用');
}
final global = snapshot.global
.where((m) => _matches([m.title, m.body]))
.toList();
final project = snapshot.project
.where((m) => _matches([m.title, m.body]))
.toList();
if (global.isEmpty && project.isEmpty) {
return _empty(
theme,
Icons.psychology_outlined,
_query.isEmpty ? '还没有记忆' : '没有匹配的记忆');
}
return ListView(
padding: const EdgeInsets.fromLTRB(12, 0, 12, 12),
children: [
_memoryGroup(theme, '全局记忆', global, 'global',
failed: snapshot.globalFailed),
const SizedBox(height: 8),
_memoryGroup(theme, '项目记忆', project, 'project',
failed: snapshot.projectFailed),
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
'记忆由 agent 在会话中记录;你可以在这里修改或删除它。',
style: TextStyle(fontSize: 11.5, color: theme.hintColor),
),
),
],
);
}
Widget _memoryGroup(
ThemeData theme, String title, List<AgentMemoryEntry> entries, String scope,
{required bool failed}) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('$title(${entries.length})',
style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
if (failed)
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('读取失败,请刷新',
style: TextStyle(
fontSize: 12, color: theme.colorScheme.error)),
)
else if (entries.isEmpty)
Padding(
padding: const EdgeInsets.only(bottom: 4),
child: Text('暂无', style: TextStyle(fontSize: 12, color: theme.hintColor)),
),
for (final entry in entries) _memoryCard(theme, entry, scope),
],
);
}
Widget _memoryCard(ThemeData theme, AgentMemoryEntry entry, String scope) {
final scheme = theme.colorScheme;
return Card(
margin: const EdgeInsets.only(bottom: 8),
child: InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () => _editMemory(entry, scope),
child: Padding(
padding: const EdgeInsets.fromLTRB(12, 8, 4, 8),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Flexible(
child: Text(entry.title,
maxLines: 1,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 13.5, fontWeight: FontWeight.w600)),
),
const SizedBox(width: 6),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 5, vertical: 1),
decoration: BoxDecoration(
color: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(4),
),
child: Text(entry.typeLabel,
style: TextStyle(
fontSize: 10, color: theme.hintColor)),
),
if (entry.flagged)
Padding(
padding: const EdgeInsets.only(left: 4),
child: Icon(Icons.flag_outlined,
size: 13, color: scheme.error),
),
],
),
const SizedBox(height: 3),
Text(entry.body,
maxLines: 4,
overflow: TextOverflow.ellipsis,
style: const TextStyle(fontSize: 12.5, height: 1.35)),
],
),
),
PopupMenuButton<String>(
icon: const Icon(Icons.more_vert, size: 18),
onSelected: (value) async {
if (value == 'edit') {
await _editMemory(entry, scope);
} else if (value == 'delete') {
await _deleteMemory(entry, scope);
}
},
itemBuilder: (_) => const [
PopupMenuItem(value: 'edit', child: Text('编辑')),
PopupMenuItem(value: 'delete', child: Text('删除')),
],
),
],
),
),
),
);
}
Future<void> _editMemory(AgentMemoryEntry entry, String scope) async {
final client = _client;
if (client == null) return;
final result = await showDialog<(String, String, String)>(
context: context,
builder: (_) => _MemoryDialog(entry: entry),
);
if (result == null) return;
try {
await client.updateMemory(entry.id,
scope: scope,
projectId: _projectId,
title: result.$1,
body: result.$2,
type: result.$3,
directory: widget.directory);
await _reloadMemory();
} catch (error) {
_fail(error);
}
}
Future<void> _deleteMemory(AgentMemoryEntry entry, String scope) async {
final client = _client;
if (client == null) return;
try {
await client.deleteMemory(entry.id,
scope: scope,
projectId: _projectId,
directory: widget.directory);
await _reloadMemory();
} catch (error) {
_fail(error);
}
}
Future<void> _reloadMemory() async {
final client = _client;
if (client == null) return;
try {
final memory = await client.agentMemory(_projectId,
directory: widget.directory);
if (!mounted) return;
setState(() => _memory = memory);
} catch (error) {
_fail(error);
}
}
// -------------------------------------------------------------- dialogs
Widget _sectionHeader(
@@ -840,3 +1051,91 @@ class _NewPlanDialogState extends State<_NewPlanDialog> {
);
}
}
/// Edit one memory entry: its title, its text, and what kind it is.
class _MemoryDialog extends StatefulWidget {
final AgentMemoryEntry entry;
const _MemoryDialog({required this.entry});
@override
State<_MemoryDialog> createState() => _MemoryDialogState();
}
class _MemoryDialogState extends State<_MemoryDialog> {
late final TextEditingController _title =
TextEditingController(text: widget.entry.title);
late final TextEditingController _body =
TextEditingController(text: widget.entry.body);
late String _type = widget.entry.type;
@override
void dispose() {
_title.dispose();
_body.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('编辑记忆'),
content: SizedBox(
width: double.maxFinite,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextField(
controller: _title,
autofocus: true,
maxLength: 120,
decoration: const InputDecoration(
labelText: '标题',
border: OutlineInputBorder(),
),
),
const SizedBox(height: 8),
SegmentedButton<String>(
showSelectedIcon: false,
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
segments: const [
ButtonSegment(value: 'fact', label: Text('事实')),
ButtonSegment(value: 'preference', label: Text('偏好')),
ButtonSegment(value: 'reference', label: Text('参考')),
],
selected: {_type},
onSelectionChanged: (value) =>
setState(() => _type = value.first),
),
const SizedBox(height: 8),
TextField(
controller: _body,
maxLength: 2000,
maxLines: 6,
minLines: 4,
decoration: const InputDecoration(
alignLabelWithHint: true,
labelText: '内容',
border: OutlineInputBorder(),
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context), child: const Text('取消')),
FilledButton(
onPressed: () {
final title = _title.text.trim();
if (title.isEmpty) return;
Navigator.pop(context, (title, _body.text.trim(), _type));
},
child: const Text('保存'),
),
],
);
}
}
+32 -42
View File
@@ -186,82 +186,74 @@ class _TerminalPanelState extends State<TerminalPanel> {
// ------------------------------------------------------------- key bar
static const _symbols = [
'/', '-', '|', '~', '*', r'$', '#', '_', '=', '+', ':', ';',
'"', "'", '(', ')', '[', ']', '{', '}', '<', '>', '?', '!',
'&', r'\', '^', '%', '@',
];
/// Two rows of seven, the way Termux lays them out: the keys a phone
/// keyboard cannot produce, all reachable with a thumb.
Widget _keyBar(ThemeData theme) {
return Container(
height: 46,
decoration: BoxDecoration(
color: theme.colorScheme.surfaceContainerHigh,
border: Border(top: BorderSide(color: theme.dividerColor, width: 0.5)),
),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
padding: const EdgeInsets.symmetric(horizontal: 6),
child: Row(
children: [
_key('CTRL', active: _t.ctrl, onTap: _t.toggleCtrl),
_key('ALT', active: _t.alt, onTap: _t.toggleAlt),
_key('SHIFT', active: _t.shift, onTap: _t.toggleShift),
_divider(theme),
padding: const EdgeInsets.fromLTRB(3, 3, 3, 3),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
_keyRow([
_key('ESC', onTap: () => _sendKey(TerminalKey.escape)),
_key('TAB', onTap: () => _sendKey(TerminalKey.tab)),
_divider(theme),
_key('←', onTap: () => _sendKey(TerminalKey.arrowLeft)),
_key('↑', onTap: () => _sendKey(TerminalKey.arrowUp)),
_key('↓', onTap: () => _sendKey(TerminalKey.arrowDown)),
_key('→', onTap: () => _sendKey(TerminalKey.arrowRight)),
_divider(theme),
_key('/', onTap: () => _sendText('/')),
_key('—', onTap: () => _sendText('-')),
_key('HOME', onTap: () => _sendKey(TerminalKey.home)),
_key('↑', big: true, onTap: () => _sendKey(TerminalKey.arrowUp)),
_key('END', onTap: () => _sendKey(TerminalKey.end)),
_key('PGUP', onTap: () => _sendKey(TerminalKey.pageUp)),
]),
_keyRow([
_key('TAB', onTap: () => _sendKey(TerminalKey.tab)),
_key('CTRL', active: _t.ctrl, onTap: _t.toggleCtrl),
_key('ALT', active: _t.alt, onTap: _t.toggleAlt),
_key('←', big: true, onTap: () => _sendKey(TerminalKey.arrowLeft)),
_key('↓', big: true, onTap: () => _sendKey(TerminalKey.arrowDown)),
_key('→', big: true, onTap: () => _sendKey(TerminalKey.arrowRight)),
_key('PGDN', onTap: () => _sendKey(TerminalKey.pageDown)),
_key('DEL', onTap: () => _sendKey(TerminalKey.delete)),
_divider(theme),
for (final symbol in _symbols)
_key(symbol, onTap: () => _sendText(symbol)),
],
),
]),
],
),
);
}
Widget _divider(ThemeData theme) => Container(
width: 1,
height: 20,
margin: const EdgeInsets.symmetric(horizontal: 4),
color: theme.dividerColor,
Widget _keyRow(List<Widget> keys) => Padding(
padding: const EdgeInsets.symmetric(vertical: 1.5),
child: Row(
children: [for (final key in keys) Expanded(child: key)],
),
);
/// [big] draws a single glyph (an arrow) larger than a word.
Widget _key(String label,
{bool active = false, required VoidCallback onTap}) {
{bool active = false, bool big = false, required VoidCallback onTap}) {
final theme = Theme.of(context);
final scheme = theme.colorScheme;
return GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: onTap,
child: Container(
margin: const EdgeInsets.symmetric(horizontal: 2, vertical: 8),
padding: const EdgeInsets.symmetric(horizontal: 10),
height: 30,
margin: const EdgeInsets.symmetric(horizontal: 1.5),
alignment: Alignment.center,
constraints: const BoxConstraints(minWidth: 34),
decoration: BoxDecoration(
color: active
? scheme.primary.withValues(alpha: 0.22)
: scheme.surfaceContainerHighest,
borderRadius: BorderRadius.circular(7),
borderRadius: BorderRadius.circular(6),
border: Border.all(
color: active ? scheme.primary : Colors.transparent, width: 1),
),
child: Text(
label,
maxLines: 1,
style: TextStyle(
fontFamily: 'monospace',
fontSize: 12,
fontSize: big ? 16 : 11,
fontWeight: active ? FontWeight.w700 : FontWeight.w500,
color: active ? scheme.primary : scheme.onSurface,
),
@@ -270,8 +262,6 @@ class _TerminalPanelState extends State<TerminalPanel> {
);
}
// The terminal state applies the pending modifiers (and clears them) as the
// text leaves for the PTY, so both the bar and the phone keyboard take them.
void _sendKey(TerminalKey key) =>
_t.model.keyInput(key, ctrl: _t.ctrl, alt: _t.alt, shift: _t.shift);