Giter VIP home page Giter VIP logo

Comments (7)

jpnurmi avatar jpnurmi commented on June 17, 2024

xterm v2 works

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xterm/flutter.dart';
import 'package:xterm/xterm.dart';

void main() {
  runApp(const MaterialApp(home: MyHomePage()));
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _terminal = Terminal(maxLines: 10000);

  @override
  Widget build(BuildContext context) {
    return CallbackShortcuts(
      bindings: {
        const SingleActivator(LogicalKeyboardKey.pageDown): () {
          print('page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp): () {
          print('page up');
        },
        const SingleActivator(LogicalKeyboardKey.pageDown, control: true): () {
          print('ctrl+page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp, control: true): () {
          print('ctrl+page up');
        },
        const SingleActivator(LogicalKeyboardKey.pageDown, shift: true): () {
          print('shift+page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp, shift: true): () {
          print('shift+page up');
        },
        const SingleActivator(LogicalKeyboardKey.pageDown,
            control: true, shift: true): () {
          print('ctrl+shift+page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp,
            control: true, shift: true): () {
          print('ctrl+shift+page up');
        },
        const SingleActivator(LogicalKeyboardKey.keyT,
            control: true, shift: true): () {
          print('ctrl+shift+T');
        },
      },
      child: Focus(
        autofocus: true,
        child: Scaffold(
          appBar: AppBar(title: const Text('xterm')),
          body: TerminalView(
            terminal: _terminal,
            autofocus: true,
          ),
        ),
      ),
    );
  }
}

xterm v3 doesn't work

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:xterm/xterm.dart';

void main() {
  runApp(const MaterialApp(home: MyHomePage()));
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key});

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  final _terminal = Terminal();

  @override
  Widget build(BuildContext context) {
    return CallbackShortcuts(
      bindings: {
        const SingleActivator(LogicalKeyboardKey.pageDown): () {
          print('page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp): () {
          print('page up');
        },
        const SingleActivator(LogicalKeyboardKey.pageDown, control: true): () {
          print('ctrl+page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp, control: true): () {
          print('ctrl+page up');
        },
        const SingleActivator(LogicalKeyboardKey.pageDown, shift: true): () {
          print('shift+page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp, shift: true): () {
          print('shift+page up');
        },
        const SingleActivator(LogicalKeyboardKey.pageDown,
            control: true, shift: true): () {
          print('ctrl+shift+page down');
        },
        const SingleActivator(LogicalKeyboardKey.pageUp,
            control: true, shift: true): () {
          print('ctrl+shift+page up');
        },
        const SingleActivator(LogicalKeyboardKey.keyT,
            control: true, shift: true): () {
          print('ctrl+shift+T');
        },
      },
      child: Focus(
        autofocus: true,
        child: Scaffold(
          appBar: AppBar(title: const Text('xterm')),
          body: TerminalView(
            autofocus: true,
            _terminal,
          ),
        ),
      ),
    );
  }
}

from workshops.

xtyxtyx avatar xtyxtyx commented on June 17, 2024

v2 internally uses RawKeyboardListener which fire keyboard events no matter whether the event is consumed by the focus system or not. In v3, TerminalView uses Focus to listen for keyboard events, therefore events consumed by the terminal stop propagating to upper FocusNodes in the focus tree.

For now it's recommended to use TerminalView.shortcuts to make shortcuts have higher priority than the input handler of the terminal.

from workshops.

jpnurmi avatar jpnurmi commented on June 17, 2024

Hi @xtyxtyx, thanks for chiming in. TerminalStudio/xterm.dart#134 also helps with this because it makes it possible to pair the map of shortcuts with actions. The above example is using callback shortcuts for the sake of simplicity but this is not the case for all shortcuts. :)

from workshops.

jpnurmi avatar jpnurmi commented on June 17, 2024

In v3, TerminalView uses Focus to listen for keyboard events, therefore events consumed by the terminal stop propagating to upper FocusNodes in the focus tree.

Hmm, does Flutter not have a system to let shortcuts handle key events before normal key event handlers are called? It seems problematic that a normal key handler deep down the tree blocks the entire app's shortcuts.

from workshops.

xtyxtyx avatar xtyxtyx commented on June 17, 2024

TerminalStudio/xterm.dart#134 also helps with this because it makes it possible to pair the map of shortcuts with actions.

Sorry for the delay in responding to the PR. I'm trying to figure out a better design of the interface to add shortcuts to the terminal. Will merge the PR as soon as possible once the design is finalized.

from workshops.

xtyxtyx avatar xtyxtyx commented on June 17, 2024

Hmm, does Flutter not have a system to let shortcuts handle key events before normal key event handlers are called?

No way as far as I know... Perhaps the terminal is consuming too much key bindings by default. I'm planning to deprecate the keytab and instead turn it into something like List<TerminalKeybinding> to make it easier to customize the default key bindings.

from workshops.

jpnurmi avatar jpnurmi commented on June 17, 2024

@xtyxtyx What about something similar to what Flutter does with text editing shortcuts? Something you put high up in the tree to be able to override them below.

https://api.flutter.dev/flutter/widgets/DefaultTextEditingShortcuts-class.html

from workshops.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.