opt. & new

new: term respond to tap event
opt.: term selection
This commit is contained in:
lollipopkit
2024-03-12 19:55:17 -06:00
parent e361e509af
commit 150c8f014b
6 changed files with 44 additions and 51 deletions

View File

@@ -61,4 +61,3 @@ final isWeb = OS.type == OS.web;
final isMobile = OS.type == OS.ios || OS.type == OS.android; final isMobile = OS.type == OS.ios || OS.type == OS.android;
final isDesktop = final isDesktop =
OS.type == OS.linux || OS.type == OS.macos || OS.type == OS.windows; OS.type == OS.linux || OS.type == OS.macos || OS.type == OS.windows;
const isDebuggingMobileLayoutOnDesktop = kDebugMode;

View File

@@ -65,6 +65,7 @@ class DiskIO extends TimeSeq<DiskIOPiece> {
} }
(double?, double?) _getSpeed(String dev) { (double?, double?) _getSpeed(String dev) {
if (dev.startsWith('/dev/')) dev = dev.substring(5);
final old = pre.firstWhereOrNull((e) => e.dev == dev); final old = pre.firstWhereOrNull((e) => e.dev == dev);
final new_ = now.firstWhereOrNull((e) => e.dev == dev); final new_ = now.firstWhereOrNull((e) => e.dev == dev);
if (old == null || new_ == null) return (null, null); if (old == null || new_ == null) return (null, null);

View File

@@ -1,6 +1,5 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'dart:math' as math;
import 'package:dartssh2/dartssh2.dart'; import 'package:dartssh2/dartssh2.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@@ -17,6 +16,7 @@ import 'package:toolbox/data/model/server/snippet.dart';
import 'package:toolbox/data/provider/virtual_keyboard.dart'; import 'package:toolbox/data/provider/virtual_keyboard.dart';
import 'package:toolbox/data/res/provider.dart'; import 'package:toolbox/data/res/provider.dart';
import 'package:toolbox/data/res/store.dart'; import 'package:toolbox/data/res/store.dart';
import 'package:toolbox/view/widget/appbar.dart';
import 'package:xterm/core.dart'; import 'package:xterm/core.dart';
import 'package:xterm/ui.dart' hide TerminalThemes; import 'package:xterm/ui.dart' hide TerminalThemes;
@@ -47,6 +47,8 @@ class SSHPage extends StatefulWidget {
_SSHPageState createState() => _SSHPageState(); _SSHPageState createState() => _SSHPageState();
} }
const _horizonPadding = 7.0;
class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin { class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
final _keyboard = VirtKeyProvider(); final _keyboard = VirtKeyProvider();
late final _terminal = Terminal(inputHandler: _keyboard); late final _terminal = Terminal(inputHandler: _keyboard);
@@ -57,7 +59,6 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
late TerminalStyle _terminalStyle; late TerminalStyle _terminalStyle;
late TerminalTheme _terminalTheme; late TerminalTheme _terminalTheme;
late TextInputType _keyboardType; late TextInputType _keyboardType;
late double _originTextSize;
double _virtKeyWidth = 0; double _virtKeyWidth = 0;
double _virtKeysHeight = 0; double _virtKeysHeight = 0;
late final TerminalCursorType _termCursor; late final TerminalCursorType _termCursor;
@@ -89,16 +90,17 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
@override @override
void didChangeDependencies() { void didChangeDependencies() {
super.didChangeDependencies(); super.didChangeDependencies();
_isDark = context.isDark; _isDark = switch (Stores.setting.termTheme.fetch()) {
_media = MediaQuery.of(context); 1 => false,
_terminalTheme = switch (Stores.setting.termTheme.fetch()) { 2 => true,
1 => TerminalThemes.light, _ => context.isDark,
2 => TerminalThemes.dark,
_ => _isDark ? TerminalThemes.dark : TerminalThemes.light,
}; };
_media = MediaQuery.of(context);
_terminalTheme = _isDark ? TerminalThemes.dark : TerminalThemes.light;
// Because the virtual keyboard only displayed on mobile devices // Because the virtual keyboard only displayed on mobile devices
if (isMobile || isDebuggingMobileLayoutOnDesktop) { if (isMobile) {
_virtKeyWidth = _media.size.width / 7; _virtKeyWidth = _media.size.width / 7;
_virtKeysHeight = _media.size.height * 0.043 * _virtKeysList.length; _virtKeysHeight = _media.size.height * 0.043 * _virtKeysList.length;
} }
@@ -110,9 +112,7 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
Widget child = Scaffold( Widget child = Scaffold(
backgroundColor: _terminalTheme.background, backgroundColor: _terminalTheme.background,
body: _buildBody(), body: _buildBody(),
bottomNavigationBar: isDesktop && !isDebuggingMobileLayoutOnDesktop bottomNavigationBar: isDesktop ? null : _buildBottom(),
? null
: _buildBottom(),
); );
if (isIOS) { if (isIOS) {
child = AnnotatedRegion( child = AnnotatedRegion(
@@ -130,32 +130,27 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
_media.padding.bottom - _media.padding.bottom -
_media.padding.top, _media.padding.top,
child: Padding( child: Padding(
padding: EdgeInsets.only(top: _media.padding.top, left: 7, right: 7), padding: EdgeInsets.only(
child: GestureDetector( top: CustomAppBar.barHeight ?? _media.padding.top,
onScaleUpdate: (details) { left: _horizonPadding,
if (details.scale == 1) { right: _horizonPadding,
return; ),
}
final scale = math.pow(details.scale, 0.3);
final fontSize = _originTextSize * scale;
if (fontSize < 7 || fontSize > 17) {
return;
}
_terminalStyle = _terminalStyle.copyWith(fontSize: fontSize);
setState(() {});
},
child: TerminalView( child: TerminalView(
_terminal, _terminal,
controller: _terminalController, controller: _terminalController,
keyboardType: _keyboardType, keyboardType: _keyboardType,
textStyle: _terminalStyle, textStyle: _terminalStyle,
theme: _terminalTheme, theme: _terminalTheme,
deleteDetection: isMobile, deleteDetection: false,
autofocus: true, autofocus: true,
keyboardAppearance: _isDark ? Brightness.dark : Brightness.light, keyboardAppearance: _isDark ? Brightness.dark : Brightness.light,
cursorType: _termCursor, cursorType: _termCursor,
//hideScrollBar: false, showToolbar: isMobile,
viewOffset: Offset(
2 * _horizonPadding,
CustomAppBar.barHeight ?? _media.padding.top,
), ),
//hideScrollBar: false,
), ),
), ),
); );
@@ -483,7 +478,6 @@ class _SSHPageState extends State<SSHPage> with AutomaticKeepAliveClientMixin {
void _initStoredCfg() { void _initStoredCfg() {
final fontFamilly = getFileName(Stores.setting.fontPath.fetch()); final fontFamilly = getFileName(Stores.setting.fontPath.fetch());
final textSize = Stores.setting.termFontSize.fetch(); final textSize = Stores.setting.termFontSize.fetch();
_originTextSize = textSize;
final textStyle = TextStyle( final textStyle = TextStyle(
fontFamily: fontFamilly, fontFamily: fontFamilly,
fontSize: textSize, fontSize: textSize,

View File

@@ -3,10 +3,10 @@ import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:window_manager/window_manager.dart'; import 'package:window_manager/window_manager.dart';
int? _titlebarHeight;
bool _drawTitlebar = false;
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget { class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
static double? barHeight;
static bool _drawTitlebar = false;
const CustomAppBar({ const CustomAppBar({
super.key, super.key,
this.title, this.title,
@@ -31,7 +31,7 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
centerTitle: centerTitle, centerTitle: centerTitle,
leading: leading, leading: leading,
backgroundColor: backgroundColor, backgroundColor: backgroundColor,
toolbarHeight: (_titlebarHeight ?? 0) + kToolbarHeight, toolbarHeight: (barHeight ?? 0) + kToolbarHeight,
); );
if (!_drawTitlebar) return bar; if (!_drawTitlebar) return bar;
return Stack( return Stack(
@@ -82,11 +82,11 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
static Future<void> updateTitlebarHeight() async { static Future<void> updateTitlebarHeight() async {
switch (Platform.operatingSystem) { switch (Platform.operatingSystem) {
case 'macos': case 'macos':
_titlebarHeight = 27; barHeight = 27;
break; break;
// Draw a titlebar on Linux // Draw a titlebar on Linux
case 'linux' || 'windows': case 'linux' || 'windows':
_titlebarHeight = 37; barHeight = 37;
_drawTitlebar = true; _drawTitlebar = true;
break; break;
default: default:
@@ -95,6 +95,5 @@ class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
} }
@override @override
Size get preferredSize => Size get preferredSize => Size.fromHeight((barHeight ?? 0) + kToolbarHeight);
Size.fromHeight((_titlebarHeight ?? 0) + kToolbarHeight);
} }

View File

@@ -1259,10 +1259,10 @@ packages:
description: description:
path: "." path: "."
ref: master ref: master
resolved-ref: aad22a50bf09b2d87b20e2e45c1c9ca5ff0037f7 resolved-ref: b81b303040729b866f844dd46b25c9f6be582962
url: "https://github.com/lollipopkit/xterm.dart" url: "https://github.com/lollipopkit/xterm.dart"
source: git source: git
version: "3.6.1-pre" version: "4.0.0"
yaml: yaml:
dependency: transitive dependency: transitive
description: description:
@@ -1281,4 +1281,4 @@ packages:
version: "0.0.6" version: "0.0.6"
sdks: sdks:
dart: ">=3.3.0-279.1.beta <4.0.0" dart: ">=3.3.0-279.1.beta <4.0.0"
flutter: ">=3.16.6" flutter: ">=3.19.0"

View File

@@ -39,7 +39,7 @@ dependencies:
intl: ^0.18.0 intl: ^0.18.0
# xterm: ^3.5.0 # xterm: ^3.5.0
xterm: xterm:
#path: ../xterm.dart # path: ../xterm.dart
git: git:
ref: master ref: master
url: https://github.com/lollipopkit/xterm.dart url: https://github.com/lollipopkit/xterm.dart