Fix enter (pty) key, add broken stick key support

This commit is contained in:
Caten
2023-10-02 15:44:52 +08:00
parent b4ca9ae4f7
commit 27a5073551
2 changed files with 26 additions and 5 deletions

View File

@@ -24,7 +24,7 @@ import 'dart:math';
//import 'package:flutter/services.dart'; //import 'package:flutter/services.dart';
import 'package:flutter/gestures.dart'; import 'package:flutter/gestures.dart';
import 'package:flutter/services.dart'; //import 'package:flutter/services.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:xterm/xterm.dart'; import 'package:xterm/xterm.dart';
@@ -832,7 +832,7 @@ class _MyHomePageState extends State<MyHomePage> {
}); });
}, onScaleEnd: (details) async { }, onScaleEnd: (details) async {
await G.prefs.setDouble("termFontScale", G.termFontScale); await G.prefs.setDouble("termFontScale", G.termFontScale);
}, child: TerminalView(G.termPtys[G.currentContainer]!.terminal, textScaleFactor: G.termFontScale))), }, child: TerminalView(G.termPtys[G.currentContainer]!.terminal, textScaleFactor: G.termFontScale, keyboardType: TextInputType.multiline,))),
G.prefs.getBool("isTerminalCommandsEnabled")!?Padding(padding: const EdgeInsets.all(8), child: G.prefs.getBool("isTerminalCommandsEnabled")!?Padding(padding: const EdgeInsets.all(8), child:
SingleChildScrollView(scrollDirection: Axis.horizontal, child: Row(children: [AnimatedBuilder( SingleChildScrollView(scrollDirection: Axis.horizontal, child: Row(children: [AnimatedBuilder(
animation: G.keyboard, animation: G.keyboard,
@@ -1088,6 +1088,11 @@ class _MyHomePageState extends State<MyHomePage> {
setState(() {}); setState(() {});
},), },),
SizedBox.fromSize(size: const Size.square(8)), SizedBox.fromSize(size: const Size.square(8)),
SwitchListTile(title: const Text("终端粘滞键"), value: G.prefs.getBool("isStickyKey")!, onChanged:(value) {
G.prefs.setBool("isStickyKey", value);
setState(() {});
},),
SizedBox.fromSize(size: const Size.square(8)),
SwitchListTile(title: const Text("开启时启动图形界面"), value: G.prefs.getBool("autoLaunchVnc")!, onChanged:(value) { SwitchListTile(title: const Text("开启时启动图形界面"), value: G.prefs.getBool("autoLaunchVnc")!, onChanged:(value) {
G.prefs.setBool("autoLaunchVnc", value); G.prefs.setBool("autoLaunchVnc", value);
setState(() {}); setState(() {});

View File

@@ -178,11 +178,17 @@ class VirtualKeyboard extends TerminalInputHandler with ChangeNotifier {
@override @override
String? call(TerminalKeyboardEvent event) { String? call(TerminalKeyboardEvent event) {
return _inputHandler.call(event.copyWith( final ret = _inputHandler.call(event.copyWith(
ctrl: event.ctrl || _ctrl, ctrl: event.ctrl || _ctrl,
shift: event.shift || _shift, shift: event.shift || _shift,
alt: event.alt || _alt, alt: event.alt || _alt,
)); ));
if (!G.prefs.getBool("isStickyKey")!) {
_ctrl = false;
_shift = false;
_alt = false;
}
return ret;
} }
} }
@@ -240,9 +246,17 @@ class TermPty {
} }
}); });
terminal.onOutput = (data) { terminal.onOutput = (data) {
if (G.prefs.getBool("isTerminalWriteEnabled")!) { if (!G.prefs.getBool("isTerminalWriteEnabled")!) {
pty.write(const Utf8Encoder().convert(data)); return;
} }
//由于pty对回车的处理似乎存在问题所以拿出来单独处理
data.split("").forEach((element) {
if (element == "\n") {
terminal.keyInput(TerminalKey.enter);
return;
}
pty.write(const Utf8Encoder().convert(element));
});
}; };
terminal.onResize = (w, h, pw, ph) { terminal.onResize = (w, h, pw, ph) {
pty.resize(h, w); pty.resize(h, w);
@@ -293,6 +307,7 @@ class G {
//int termMaxLines = 4095 终端最大行数 //int termMaxLines = 4095 终端最大行数
//double termFontScale = 1 终端字体大小 //double termFontScale = 1 终端字体大小
//int vip = 0 用户等级vip免广告你要改吗(ToT) //int vip = 0 用户等级vip免广告你要改吗(ToT)
//bool isStickyKey = true 终端ctrl, shift, alt键是否粘滞
//? int bootstrapVersion: 启动包版本 //? int bootstrapVersion: 启动包版本
//String[] containersInfo: 所有容器信息(json) //String[] containersInfo: 所有容器信息(json)
//{name, boot:"\$DATA_DIR/bin/proot ...", vnc:"startnovnc", vncUrl:"...", commands:[{name:"更新和升级", command:"apt update -y && apt upgrade -y"}, ...]} //{name, boot:"\$DATA_DIR/bin/proot ...", vnc:"startnovnc", vncUrl:"...", commands:[{name:"更新和升级", command:"apt update -y && apt upgrade -y"}, ...]}
@@ -491,6 +506,7 @@ done
await G.prefs.setInt("termMaxLines", 4095); await G.prefs.setInt("termMaxLines", 4095);
await G.prefs.setDouble("termFontScale", 1); await G.prefs.setDouble("termFontScale", 1);
await G.prefs.setInt("vip", 0); await G.prefs.setInt("vip", 0);
await G.prefs.setBool("isStickyKey", true);
} }
static Future<void> initData() async { static Future<void> initData() async {