keytab_record.dart 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. import 'package:xterm/core/input/keys.dart';
  2. import 'package:xterm/core/input/keytab/keytab_escape.dart';
  3. enum KeytabActionType {
  4. input,
  5. shortcut,
  6. }
  7. class KeytabAction {
  8. KeytabAction(this.type, this.value);
  9. final KeytabActionType type;
  10. final String value;
  11. String unescapedValue() {
  12. if (type == KeytabActionType.input) {
  13. return keytabUnescape(value);
  14. } else {
  15. return value;
  16. }
  17. }
  18. @override
  19. String toString() {
  20. switch (type) {
  21. case KeytabActionType.input:
  22. return '"$value"';
  23. case KeytabActionType.shortcut:
  24. return value;
  25. }
  26. }
  27. }
  28. class KeytabRecord {
  29. KeytabRecord({
  30. required this.qtKeyName,
  31. required this.key,
  32. required this.action,
  33. required this.alt,
  34. required this.ctrl,
  35. required this.shift,
  36. required this.anyModifier,
  37. required this.ansi,
  38. required this.appScreen,
  39. required this.keyPad,
  40. required this.appCursorKeys,
  41. required this.appKeyPad,
  42. required this.newLine,
  43. required this.macos,
  44. });
  45. String qtKeyName;
  46. TerminalKey key;
  47. KeytabAction action;
  48. bool? alt;
  49. bool? ctrl;
  50. bool? shift;
  51. bool? anyModifier;
  52. bool? ansi;
  53. bool? appScreen;
  54. bool? keyPad;
  55. bool? appCursorKeys;
  56. bool? appKeyPad;
  57. bool? newLine;
  58. bool? macos;
  59. @override
  60. String toString() {
  61. final buffer = StringBuffer();
  62. buffer.write('$qtKeyName ');
  63. if (alt != null) {
  64. buffer.write(_toMode(alt!, 'Alt'));
  65. }
  66. if (ctrl != null) {
  67. buffer.write(_toMode(ctrl!, 'Control'));
  68. }
  69. if (shift != null) {
  70. buffer.write(_toMode(shift!, 'Shift'));
  71. }
  72. if (anyModifier != null) {
  73. buffer.write(_toMode(anyModifier!, 'AnyMod'));
  74. }
  75. if (ansi != null) {
  76. buffer.write(_toMode(ansi!, 'Ansi'));
  77. }
  78. if (appScreen != null) {
  79. buffer.write(_toMode(appScreen!, 'AppScreen'));
  80. }
  81. if (keyPad != null) {
  82. buffer.write(_toMode(keyPad!, 'KeyPad'));
  83. }
  84. if (appCursorKeys != null) {
  85. buffer.write(_toMode(appCursorKeys!, 'AppCuKeys'));
  86. }
  87. if (appKeyPad != null) {
  88. buffer.write(_toMode(appKeyPad!, 'AppKeyPad'));
  89. }
  90. if (newLine != null) {
  91. buffer.write(_toMode(newLine!, 'NewLine'));
  92. }
  93. if (macos != null) {
  94. buffer.write(_toMode(macos!, 'Mac'));
  95. }
  96. buffer.write(' : $action');
  97. return buffer.toString();
  98. }
  99. static String _toMode(bool status, String mode) {
  100. if (status == true) {
  101. return '+$mode';
  102. }
  103. if (status == false) {
  104. return '-$mode';
  105. }
  106. return '';
  107. }
  108. }