input_behavior_default.dart 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import 'package:flutter/services.dart';
  2. import 'package:flutter/widgets.dart';
  3. import 'package:xterm/frontend/input_behavior.dart';
  4. import 'package:xterm/frontend/input_map.dart';
  5. import 'package:xterm/xterm.dart';
  6. class InputBehaviorDefault extends InputBehavior {
  7. const InputBehaviorDefault();
  8. @override
  9. bool get acceptKeyStroke => true;
  10. @override
  11. void onKeyStroke(RawKeyEvent event, Terminal terminal) {
  12. if (event is! RawKeyDownEvent) {
  13. return;
  14. }
  15. final key = inputMap(event.logicalKey);
  16. if (key != null) {
  17. terminal.keyInput(
  18. key,
  19. ctrl: event.isControlPressed,
  20. alt: event.isAltPressed,
  21. shift: event.isShiftPressed,
  22. );
  23. }
  24. }
  25. @override
  26. TextEditingValue onTextEdit(TextEditingValue value, Terminal terminal) {
  27. terminal.onInput(value.text);
  28. if (value == TextEditingValue.empty) {
  29. return null;
  30. } else {
  31. return TextEditingValue.empty;
  32. }
  33. }
  34. @override
  35. void onAction(TextInputAction action, Terminal terminal) {
  36. //
  37. }
  38. }