Comments (7)
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.
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 FocusNode
s 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.
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.
In v3,
TerminalView
usesFocus
to listen for keyboard events, therefore events consumed by the terminal stop propagating to upperFocusNode
s 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.
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.
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.
@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)
- Instance action button icons
- Remember scroll offset HOT 1
- Quick launch dropdown menu HOT 1
- Home: keyboard search eats up shortcuts
- Project info UI enhancements HOT 2
- Multiple context menus HOT 2
- Config: invalid defaults for integers HOT 1
- Tooltip delay
- When LXD is not installed HOT 2
- Shared preferences
- Launcher wizard fails to render in `0+git.af9303f` due to missing `Provider<RemoteStore>`
- Escape not working
- Allow fast configuration of high level features for an already existing container
- Leave a failing session visible so user can diagnose
- showConfigEditorDialog() uses build context across async gap
- ButtonBar in instance table has not enough space
- Empty screen with latest update from edge
- Build fails, "Because mockito >=5.0.6 <5.4.0 depends on test_api >=0.2.1 <0.5.0 ..."
- Fails to open terminal if default shell of $USER isn't in container
- Bug: Selection goes through the TUIs
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from workshops.