xterm_dump.dart 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // import 'dart:convert';
  2. // import 'dart:io';
  3. // import 'dart:typed_data';
  4. // import 'package:xterm/core/escape/handler.dart';
  5. // import 'package:xterm/core/escape/parser.dart';
  6. // final handler = DebugTerminalHandler();
  7. // final protocol = EscapeParser(handler);
  8. // final input = BytesBuilder(copy: true);
  9. // void main(List<String> args) async {
  10. // final inputStream = args.isNotEmpty ? File(args.first).openRead() : stdin;
  11. // await for (var chunk in inputStream.transform(Utf8Decoder())) {
  12. // input.add(chunk);
  13. // protocol.write(chunk);
  14. // }
  15. // handler.flush();
  16. // }
  17. // extension StringEscape on String {
  18. // String escapeInvisible() {
  19. // return this.replaceAllMapped(RegExp('[\x00-\x1F]'), (match) {
  20. // return '\\x${match.group(0)!.codeUnitAt(0).toRadixString(16).padLeft(2, '0')}';
  21. // });
  22. // }
  23. // }
  24. // class DebugTerminalHandler implements EscapeHandler {
  25. // final stringBuffer = StringBuffer();
  26. // void flush() {
  27. // if (stringBuffer.isEmpty) return;
  28. // print(Color.green('TXT') + "'$stringBuffer'");
  29. // stringBuffer.clear();
  30. // }
  31. // void recordCommand(String description) {
  32. // flush();
  33. // final raw = input.toBytes().sublist(protocol.tokenBegin, protocol.tokenEnd);
  34. // final token = utf8.decode(raw).replaceAll('\x1b', 'ESC').escapeInvisible();
  35. // print(Color.magenta('CMD ') + token.padRight(40) + '$description');
  36. // }
  37. // @override
  38. // void writeChar(int char) {
  39. // stringBuffer.writeCharCode(char);
  40. // }
  41. // @override
  42. // void setCursor(int x, int y) {
  43. // recordCommand('setCursor $x, $y');
  44. // }
  45. // @override
  46. // void designateCharset(int charset) {
  47. // recordCommand('designateCharset $charset');
  48. // }
  49. // @override
  50. // void unkownEscape(int char) {
  51. // recordCommand('unkownEscape ${String.fromCharCode(char)}');
  52. // }
  53. // @override
  54. // void backspaceReturn() {
  55. // recordCommand('backspaceReturn');
  56. // }
  57. // @override
  58. // void carriageReturn() {
  59. // recordCommand('carriageReturn');
  60. // }
  61. // @override
  62. // void setCursorX(int x) {
  63. // recordCommand('setCursorX $x');
  64. // }
  65. // @override
  66. // void setCursorY(int y) {
  67. // recordCommand('setCursorY $y');
  68. // }
  69. // @override
  70. // void unkownCSI(int finalByte) {
  71. // recordCommand('unkownCSI ${String.fromCharCode(finalByte)}');
  72. // }
  73. // @override
  74. // void unkownSBC(int char) {
  75. // recordCommand('unkownSBC ${String.fromCharCode(char)}');
  76. // }
  77. // @override
  78. // noSuchMethod(Invocation invocation) {
  79. // final name = invocation.memberName;
  80. // final args = invocation.positionalArguments;
  81. // recordCommand('noSuchMethod: $name $args');
  82. // }
  83. // }
  84. // abstract class Color {
  85. // static String red(String s) => '\u001b[31m$s\u001b[0m';
  86. // static String green(String s) => '\u001b[32m$s\u001b[0m';
  87. // static String yellow(String s) => '\u001b[33m$s\u001b[0m';
  88. // static String blue(String s) => '\u001b[34m$s\u001b[0m';
  89. // static String magenta(String s) => '\u001b[35m$s\u001b[0m';
  90. // static String cyan(String s) => '\u001b[36m$s\u001b[0m';
  91. // }
  92. // abstract class Labels {
  93. // static final txt = Color.green('TXT');
  94. // }