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