2022-12-09 18:59:31 -05:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:xterm/xterm.dart';
|
2022-12-10 12:11:46 -05:00
|
|
|
import 'log.dart';
|
2022-12-10 17:07:52 -05:00
|
|
|
import 'veilid_theme.dart';
|
|
|
|
|
|
|
|
const kDefaultTerminalStyle = TerminalStyle(
|
|
|
|
fontSize: kDefaultMonoTerminalFontSize,
|
|
|
|
fontFamily: kDefaultMonoTerminalFontFamily);
|
2022-12-09 18:59:31 -05:00
|
|
|
|
2022-12-10 12:11:46 -05:00
|
|
|
class LogTerminal extends StatefulWidget {
|
2024-03-24 22:38:27 -04:00
|
|
|
const LogTerminal({super.key});
|
2022-12-09 18:59:31 -05:00
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: library_private_types_in_public_api
|
2024-04-30 17:43:09 -04:00
|
|
|
State<LogTerminal> createState() => _LogTerminalState();
|
2022-12-09 18:59:31 -05:00
|
|
|
}
|
|
|
|
|
2022-12-10 12:11:46 -05:00
|
|
|
class _LogTerminalState extends State<LogTerminal> {
|
2024-05-02 14:15:42 -04:00
|
|
|
final _terminal = Terminal(
|
2022-12-09 18:59:31 -05:00
|
|
|
maxLines: 10000,
|
|
|
|
);
|
|
|
|
|
2024-05-02 14:15:42 -04:00
|
|
|
final _terminalController = TerminalController();
|
2022-12-09 18:59:31 -05:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2024-05-02 14:15:42 -04:00
|
|
|
_terminal.setLineFeedMode(true);
|
2024-04-30 17:43:09 -04:00
|
|
|
globalTerminalPrinter.setCallback((log) {
|
2024-05-02 14:15:42 -04:00
|
|
|
_terminal.write('${log.pretty()}\n');
|
2024-04-30 17:43:09 -04:00
|
|
|
});
|
2022-12-09 18:59:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
2024-04-30 17:43:09 -04:00
|
|
|
Widget build(BuildContext context) => TerminalView(
|
2024-05-02 14:15:42 -04:00
|
|
|
_terminal,
|
2024-04-30 17:43:09 -04:00
|
|
|
textStyle: kDefaultTerminalStyle,
|
2024-05-02 14:15:42 -04:00
|
|
|
controller: _terminalController,
|
2024-04-30 17:43:09 -04:00
|
|
|
autofocus: true,
|
|
|
|
backgroundOpacity: 0.9,
|
|
|
|
onSecondaryTapDown: (details, offset) async {
|
2024-05-02 14:15:42 -04:00
|
|
|
final selection = _terminalController.selection;
|
2024-04-30 17:43:09 -04:00
|
|
|
if (selection != null) {
|
2024-05-02 14:15:42 -04:00
|
|
|
final text = _terminal.buffer.getText(selection);
|
|
|
|
_terminalController.clearSelection();
|
2024-04-30 17:43:09 -04:00
|
|
|
await Clipboard.setData(ClipboardData(text: text));
|
|
|
|
} else {
|
|
|
|
final data = await Clipboard.getData('text/plain');
|
|
|
|
final text = data?.text;
|
|
|
|
if (text != null) {
|
2024-05-02 14:15:42 -04:00
|
|
|
_terminal.paste(text);
|
2024-04-30 17:43:09 -04:00
|
|
|
}
|
2022-12-10 17:07:52 -05:00
|
|
|
}
|
2024-04-30 17:43:09 -04:00
|
|
|
},
|
|
|
|
);
|
2022-12-09 18:59:31 -05:00
|
|
|
}
|