opt. for ssh page

This commit is contained in:
lollipopkit
2023-01-28 23:39:03 +08:00
parent f109aca484
commit e6458a1d7f
9 changed files with 142 additions and 30 deletions

View File

@@ -14,6 +14,7 @@ import 'package:toolbox/data/provider/snippet.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/data/res/font_style.dart';
import 'package:toolbox/data/res/url.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/generated/l10n.dart';
import 'package:toolbox/locator.dart';
import 'package:toolbox/view/page/pkg.dart';
@@ -41,12 +42,14 @@ class _ServerPageState extends State<ServerPage>
late ThemeData _theme;
late Color _primaryColor;
late ServerProvider _serverProvider;
late SettingStore _settingStore;
late S _s;
@override
void initState() {
super.initState();
_serverProvider = locator<ServerProvider>();
_settingStore = locator<SettingStore>();
}
@override
@@ -203,22 +206,30 @@ class _ServerPageState extends State<ServerPage>
Icons.terminal,
size: 21,
),
onTap: () => showRoundDialog(
context,
_s.attention,
UrlText(
text: _s.sshTip(issueUrl),
replace: 'Github Issue',
),
[
TextButton(
onPressed: () {
Navigator.of(context).pop();
AppRoute(SSHPage(spi: spi), 'ssh page').go(context);
},
child: Text(_s.ok),
)
]),
onTap: () async {
if (_settingStore.firstTimeUseSshTerm.fetch()!) {
await showRoundDialog(
context,
_s.attention,
UrlText(
text: _s.sshTip(issueUrl),
replace: 'Github Issue',
),
[
TextButton(
onPressed: () {
Navigator.of(context).pop();
AppRoute(SSHPage(spi: spi), 'ssh page').go(context);
},
child: Text(_s.ok),
)
],
);
_settingStore.firstTimeUseSshTerm.put(false);
} else {
AppRoute(SSHPage(spi: spi), 'ssh page').go(context);
}
},
);
}

View File

@@ -65,6 +65,7 @@ class _SettingPageState extends State<SettingPage> {
_buildCheckUpdate(),
_buildLaunchPage(),
_buildDistLogoSwitch(),
_buildTermSize(),
].map((e) => RoundRectCard(e)).toList(),
),
);
@@ -240,4 +241,43 @@ class _SettingPageState extends State<SettingPage> {
},
);
}
Widget _buildTermSize() {
return const SizedBox();
// return ListTile(
// title: Text(
// _s.termSize,
// style: textSize13,
// ),
// trailing: InkWell(
// child: Text(
// _setting.sshTermSize.fetch()!,
// style: textSize13,
// textAlign: TextAlign.right,
// ),
// onTap: () {
// showRoundDialog(
// context,
// _s.termSize,
// TextField(
// decoration: InputDecoration(hintText: _s.wxh),
// onSubmitted: (value) {
// if (wxhReg.hasMatch(value)) {
// _setting.sshTermSize.put(value);
// Navigator.pop(context);
// } else {
// showSnackBar(context, Text(_s.termSizeFormatError));
// }
// },
// ),
// [],
// );
// },
// ),
// );
}
}
/// RegExp for 'Width*Height', eg: 80x24
/// 'Width' and 'Height' must both greater than 0, lesser than 1000
final wxhReg = RegExp(r'^(\d{1,3})x(\d{1,3})$');

View File

@@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:toolbox/data/store/setting.dart';
import 'package:toolbox/view/widget/two_line_text.dart';
import 'package:xterm/xterm.dart';
@@ -62,6 +63,12 @@ class _SSHPageState extends State<SSHPage> {
terminal.write('Connected\r\n');
final wxh = locator<SettingStore>().sshTermSize.fetch()!;
final split = wxh.split('x');
final w = int.parse(split.first);
final h = int.parse(split.last);
terminal.resize(w, h);
session = await client.shell(
pty: SSHPtyConfig(
width: terminal.viewWidth,
@@ -123,14 +130,10 @@ class _SSHPageState extends State<SSHPage> {
return Column(
children: [
Row(
children: top
.map((e) => _buildVirtualKeyItem(e))
.toList(),
children: top.map((e) => _buildVirtualKeyItem(e)).toList(),
),
Row(
children: bottom
.map((e) => _buildVirtualKeyItem(e))
.toList(),
children: bottom.map((e) => _buildVirtualKeyItem(e)).toList(),
)
],
);
@@ -150,8 +153,14 @@ class _SSHPageState extends State<SSHPage> {
}
final child = item.icon != null
? Icon(item.icon, color: isDark ? Colors.white : Colors.black, size: 17,)
: Text(item.text, style: TextStyle(color: selected ? Colors.blue : null, fontSize: 15));
? Icon(
item.icon,
color: isDark ? Colors.white : Colors.black,
size: 17,
)
: Text(item.text,
style:
TextStyle(color: selected ? Colors.blue : null, fontSize: 15));
return InkWell(
onTap: () {
@@ -221,4 +230,4 @@ class VirtualKeyboard extends TerminalInputHandler with ChangeNotifier {
alt: event.alt || alt,
));
}
}
}