defaultTerminalActions function

Map<Type, Action<Intent>> defaultTerminalActions({
  1. required TerminalController controller,
  2. required TerminalEngine engine,
  3. required ValueSetter<double> onSetZoom,
  4. required double baselineFontSize,
  5. required double currentFontSize(),
  6. VoidCallback? onCopy,
  7. Future<void> onPaste()?,
  8. VoidCallback? onToggleSearch,
})

Default action handlers for the intents in defaultTerminalShortcuts.

The view supplies controller + engine + font-size hooks; the host can override individual side-effects via the optional callbacks:

  • onCopy — defaults to defaultCopyAction (engine selection → clipboard).
  • onPaste — defaults to defaultPasteAction (clipboard → engine, with bracketed-paste encoding + scrollback rewind).
  • onToggleSearch — host concern; default is a no-op (TerminalView ships no search bar).

With every override left null this map gives a stand-alone TerminalView fully working Ctrl+Shift+C/V and Ctrl+=/-/0; the only intent that requires host wiring is ToggleSearchIntent.

Implementation

Map<Type, Action<Intent>> defaultTerminalActions({
  required TerminalController controller,
  required TerminalEngine engine,
  required ValueSetter<double> onSetZoom,
  required double baselineFontSize,
  required double Function() currentFontSize,
  VoidCallback? onCopy,
  Future<void> Function()? onPaste,
  VoidCallback? onToggleSearch,
}) {
  return <Type, Action<Intent>>{
    CopyIntent: CallbackAction<CopyIntent>(onInvoke: (_) {
      if (onCopy != null) {
        onCopy();
      } else {
        defaultCopyAction(engine);
      }
      return null;
    }),
    PasteIntent: CallbackAction<PasteIntent>(
      onInvoke: (_) =>
          onPaste != null ? onPaste() : defaultPasteAction(engine, controller),
    ),
    ToggleSearchIntent: CallbackAction<ToggleSearchIntent>(onInvoke: (_) {
      onToggleSearch?.call();
      return null;
    }),
    IncreaseFontSizeIntent:
        CallbackAction<IncreaseFontSizeIntent>(onInvoke: (_) {
      onSetZoom(currentFontSize() + 1.0);
      return null;
    }),
    DecreaseFontSizeIntent:
        CallbackAction<DecreaseFontSizeIntent>(onInvoke: (_) {
      onSetZoom(currentFontSize() - 1.0);
      return null;
    }),
    ResetFontSizeIntent: CallbackAction<ResetFontSizeIntent>(onInvoke: (_) {
      onSetZoom(baselineFontSize);
      return null;
    }),
    SendEscapeIntent: CallbackAction<SendEscapeIntent>(onInvoke: (i) {
      controller.onTerminalInputStart();
      engine.write(Uint8List.fromList(i.bytes));
      return null;
    }),
    ScrollPageIntent: CallbackAction<ScrollPageIntent>(onInvoke: (i) {
      final rows = engine.grid.rows;
      final lines = (i.half ? (rows ~/ 2) : rows) * (i.up ? 1 : -1);
      engine.scrollLines(lines);
      return null;
    }),
    ScrollLineIntent: CallbackAction<ScrollLineIntent>(onInvoke: (i) {
      engine.scrollLines(i.up ? 1 : -1);
      return null;
    }),
    ScrollToEdgeIntent: CallbackAction<ScrollToEdgeIntent>(onInvoke: (i) {
      if (i.top) {
        controller.scrollToTop();
      } else {
        controller.scrollToBottom();
      }
      return null;
    }),
    ClearHistoryIntent: CallbackAction<ClearHistoryIntent>(onInvoke: (_) {
      engine.clearHistory();
      return null;
    }),
    ClearSelectionIntent: CallbackAction<ClearSelectionIntent>(onInvoke: (_) {
      controller.clearSelection();
      return null;
    }),
    UnsupportedActionIntent: CallbackAction<UnsupportedActionIntent>(onInvoke: (i) {
      assert(() {
        debugPrint('flutter_alacritty: keybinding action "${i.name}" not supported (ignored)');
        return true;
      }());
      return null;
    }),
  };
}