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,
|
|
|
|
height: kDefaultMonoTerminalFontHeight,
|
|
|
|
fontFamily: kDefaultMonoTerminalFontFamily);
|
2022-12-09 18:59:31 -05:00
|
|
|
|
2022-12-10 12:11:46 -05:00
|
|
|
class LogTerminal extends StatefulWidget {
|
|
|
|
const LogTerminal({Key? key}) : super(key: key);
|
2022-12-09 18:59:31 -05:00
|
|
|
|
|
|
|
@override
|
|
|
|
// ignore: library_private_types_in_public_api
|
2022-12-10 12:11:46 -05:00
|
|
|
_LogTerminalState createState() => _LogTerminalState();
|
2022-12-09 18:59:31 -05:00
|
|
|
}
|
|
|
|
|
2022-12-10 12:11:46 -05:00
|
|
|
class _LogTerminalState extends State<LogTerminal> {
|
2022-12-09 18:59:31 -05:00
|
|
|
final terminal = Terminal(
|
|
|
|
maxLines: 10000,
|
|
|
|
);
|
|
|
|
|
|
|
|
final terminalController = TerminalController();
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-12-10 12:11:46 -05:00
|
|
|
terminal.setLineFeedMode(true);
|
|
|
|
globalTerminalPrinter
|
|
|
|
.setCallback((log) => {terminal.write("${log.pretty()}\n")});
|
2022-12-09 18:59:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-12-10 17:07:52 -05:00
|
|
|
return TerminalView(
|
|
|
|
terminal,
|
|
|
|
textStyle: kDefaultTerminalStyle,
|
|
|
|
controller: terminalController,
|
|
|
|
autofocus: true,
|
2022-12-10 19:11:58 -05:00
|
|
|
backgroundOpacity: 0.9,
|
2022-12-10 17:07:52 -05: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 18:59:31 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|