diff --git a/example/lib/src/virtual_keyboard.dart b/example/lib/src/virtual_keyboard.dart new file mode 100644 index 00000000..82ec4a03 --- /dev/null +++ b/example/lib/src/virtual_keyboard.dart @@ -0,0 +1,80 @@ +import 'package:flutter/material.dart'; +import 'package:xterm/xterm.dart'; + +class VirtualKeyboardView extends StatelessWidget { + const VirtualKeyboardView(this.keyboard, {super.key}); + + final VirtualKeyboard keyboard; + + @override + Widget build(BuildContext context) { + return AnimatedBuilder( + animation: keyboard, + builder: (context, child) => ToggleButtons( + children: [Text('Ctrl'), Text('Alt'), Text('Shift')], + isSelected: [keyboard.ctrl, keyboard.alt, keyboard.shift], + onPressed: (index) { + switch (index) { + case 0: + keyboard.ctrl = !keyboard.ctrl; + break; + case 1: + keyboard.alt = !keyboard.alt; + break; + case 2: + keyboard.shift = !keyboard.shift; + break; + } + }, + ), + ); + } +} + +class VirtualKeyboard extends TerminalInputHandler with ChangeNotifier { + final TerminalInputHandler _inputHandler; + + VirtualKeyboard(this._inputHandler); + + bool _ctrl = false; + + bool get ctrl => _ctrl; + + set ctrl(bool value) { + if (_ctrl != value) { + _ctrl = value; + notifyListeners(); + } + } + + bool _shift = false; + + bool get shift => _shift; + + set shift(bool value) { + if (_shift != value) { + _shift = value; + notifyListeners(); + } + } + + bool _alt = false; + + bool get alt => _alt; + + set alt(bool value) { + if (_alt != value) { + _alt = value; + notifyListeners(); + } + } + + @override + String? call(TerminalInputEvent event) { + return _inputHandler.call(event.copyWith( + ctrl: event.ctrl || _ctrl, + shift: event.shift || _shift, + alt: event.alt || _alt, + )); + } +} diff --git a/example/lib/ssh.dart b/example/lib/ssh.dart index 4f665467..22879167 100644 --- a/example/lib/ssh.dart +++ b/example/lib/ssh.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'dart:typed_data'; import 'package:dartssh2/dartssh2.dart'; +import 'package:example/src/virtual_keyboard.dart'; import 'package:flutter/cupertino.dart'; import 'package:xterm/xterm.dart'; @@ -34,7 +35,9 @@ class MyHomePage extends StatefulWidget { } class _MyHomePageState extends State { - final terminal = Terminal(); + late final terminal = Terminal(inputHandler: keyboard); + + final keyboard = VirtualKeyboard(defaultInputHandler); var title = host; @@ -96,8 +99,13 @@ class _MyHomePageState extends State { backgroundColor: CupertinoTheme.of(context).barBackgroundColor.withOpacity(0.5), ), - child: TerminalView( - terminal, + child: Column( + children: [ + Expanded( + child: TerminalView(terminal), + ), + VirtualKeyboardView(keyboard), + ], ), ); }