This commit is contained in:
lollipopkit
2023-05-28 15:03:02 +08:00
parent ae822de737
commit 68c1fe4943
11 changed files with 294 additions and 140 deletions

View File

@@ -1,90 +0,0 @@
import 'package:flutter/material.dart';
import 'package:xterm/ui.dart' hide TerminalColors;
class TerminalUITheme {
final Color cursor;
final Color selection;
final Color foreground;
final Color background;
final Color searchHitBackground;
final Color searchHitBackgroundCurrent;
final Color searchHitForeground;
const TerminalUITheme({
required this.cursor,
required this.selection,
required this.foreground,
required this.background,
required this.searchHitBackground,
required this.searchHitBackgroundCurrent,
required this.searchHitForeground,
});
TerminalTheme toTerminalTheme(TerminalColors termColor) {
return TerminalTheme(
cursor: cursor,
selection: selection,
foreground: foreground,
background: background,
black: termColor.black,
red: termColor.red,
green: termColor.green,
yellow: termColor.yellow,
blue: termColor.blue,
magenta: termColor.magenta,
cyan: termColor.cyan,
white: termColor.white,
brightBlack: termColor.brightBlack,
brightRed: termColor.brightRed,
brightGreen: termColor.brightGreen,
brightYellow: termColor.brightYellow,
brightBlue: termColor.brightBlue,
brightMagenta: termColor.brightMagenta,
brightCyan: termColor.brightCyan,
brightWhite: termColor.brightWhite,
searchHitBackground: searchHitBackground,
searchHitBackgroundCurrent: searchHitBackgroundCurrent,
searchHitForeground: searchHitForeground,
);
}
}
class TerminalColors {
final Color black;
final Color red;
final Color green;
final Color yellow;
final Color blue;
final Color magenta;
final Color cyan;
final Color white;
/// Also called grey
final Color brightBlack;
final Color brightRed;
final Color brightGreen;
final Color brightYellow;
final Color brightBlue;
final Color brightMagenta;
final Color brightCyan;
final Color brightWhite;
const TerminalColors(
this.red,
this.green,
this.yellow,
this.blue,
this.magenta,
this.cyan,
this.white,
this.brightBlack,
this.brightRed,
this.brightGreen,
this.brightYellow,
this.brightBlue,
this.brightMagenta,
this.brightCyan, {
this.black = const Color(0x00000000),
this.brightWhite = const Color(0xFFFFFFFF),
});
}

View File

@@ -2,8 +2,8 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 328;
static const int build = 329;
static const String engine = "3.10.0";
static const String buildAt = "2023-05-27 19:03:35.177457";
static const int modifications = 3;
static const String buildAt = "2023-05-27 22:51:11.684423";
static const int modifications = 7;
}

View File

@@ -1,7 +1,7 @@
import 'package:flutter/material.dart';
import 'package:toolbox/data/model/ssh/terminal_color.dart';
import 'package:xterm/ui.dart';
const termDarkTheme = TerminalUITheme(
const termDarkTheme = TerminalTheme(
cursor: Color.fromARGB(137, 174, 175, 173),
selection: Color.fromARGB(147, 174, 175, 173),
foreground: Color(0XFFCCCCCC),
@@ -9,9 +9,25 @@ const termDarkTheme = TerminalUITheme(
searchHitBackground: Color(0XFFFFFF2B),
searchHitBackgroundCurrent: Color(0XFF31FF26),
searchHitForeground: Color(0XFF000000),
red: Color.fromARGB(255, 194, 54, 33),
green: Color.fromARGB(255, 37, 188, 36),
yellow: Color.fromARGB(255, 173, 173, 39),
blue: Color.fromARGB(255, 73, 46, 225),
magenta: Color.fromARGB(255, 211, 56, 211),
cyan: Color.fromARGB(255, 51, 187, 200),
white: Color.fromARGB(255, 203, 204, 205),
brightBlack: Color.fromARGB(255, 129, 131, 131),
brightRed: Color.fromARGB(255, 252, 57, 31),
brightGreen: Color.fromARGB(255, 49, 231, 34),
brightYellow: Color.fromARGB(255, 234, 236, 35),
brightBlue: Color.fromARGB(255, 88, 51, 255),
brightMagenta: Color.fromARGB(255, 249, 53, 248),
brightCyan: Color.fromARGB(255, 20, 240, 240),
brightWhite: Color.fromARGB(255, 233, 235, 235),
black: Colors.black,
);
const termLightTheme = TerminalUITheme(
const termLightTheme = TerminalTheme(
cursor: Color.fromARGB(153, 174, 175, 173),
selection: Color.fromARGB(102, 174, 175, 173),
foreground: Color(0XFF000000),
@@ -19,25 +35,20 @@ const termLightTheme = TerminalUITheme(
searchHitBackground: Color(0XFFFFFF2B),
searchHitBackgroundCurrent: Color(0XFF31FF26),
searchHitForeground: Color(0XFF000000),
red: Color.fromARGB(255, 194, 54, 33),
green: Color.fromARGB(255, 37, 188, 36),
yellow: Color.fromARGB(255, 173, 173, 39),
blue: Color.fromARGB(255, 73, 46, 225),
magenta: Color.fromARGB(255, 211, 56, 211),
cyan: Color.fromARGB(255, 51, 187, 200),
white: Color.fromARGB(255, 203, 204, 205),
brightBlack: Color.fromARGB(255, 129, 131, 131),
brightRed: Color.fromARGB(255, 252, 57, 31),
brightGreen: Color.fromARGB(255, 49, 231, 34),
brightYellow: Color.fromARGB(255, 234, 236, 35),
brightBlue: Color.fromARGB(255, 88, 51, 255),
brightMagenta: Color.fromARGB(255, 249, 53, 248),
brightCyan: Color.fromARGB(255, 20, 240, 240),
brightWhite: Color.fromARGB(255, 233, 235, 235),
black: Colors.black,
);
class MacOSTerminalColor extends TerminalColors {
MacOSTerminalColor()
: super(
const Color.fromARGB(255, 194, 54, 33),
const Color.fromARGB(255, 37, 188, 36),
const Color.fromARGB(255, 173, 173, 39),
const Color.fromARGB(255, 73, 46, 225),
const Color.fromARGB(255, 211, 56, 211),
const Color.fromARGB(255, 51, 187, 200),
const Color.fromARGB(255, 203, 204, 205),
const Color.fromARGB(255, 129, 131, 131),
const Color.fromARGB(255, 252, 57, 31),
const Color.fromARGB(255, 49, 231, 34),
const Color.fromARGB(255, 234, 236, 35),
const Color.fromARGB(255, 88, 51, 255),
const Color.fromARGB(255, 249, 53, 248),
const Color.fromARGB(255, 20, 240, 240),
brightWhite: const Color.fromARGB(255, 233, 235, 235),
);
}

66
lib/view/page/editor.dart Normal file
View File

@@ -0,0 +1,66 @@
import 'package:flutter/material.dart';
import 'package:flutter_code_editor/flutter_code_editor.dart';
import 'package:flutter_highlight/themes/monokai-sublime.dart';
import 'package:highlight/languages/java.dart';
import 'package:toolbox/core/extension/navigator.dart';
class EditorPage extends StatefulWidget {
final String? initCode;
const EditorPage({Key? key, this.initCode}) : super(key: key);
@override
_EditorPageState createState() => _EditorPageState();
}
class _EditorPageState extends State<EditorPage> {
late CodeController _controller;
late final _focusNode = FocusNode();
@override
void initState() {
super.initState();
_focusNode.requestFocus();
_controller = CodeController(
text: widget.initCode,
language: java,
analyzer: const DefaultLocalAnalyzer(),
);
}
@override
void dispose() {
_controller.dispose();
_focusNode.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: monokaiSublimeTheme['root']!.backgroundColor,
appBar: AppBar(
title: const Text('Editor'),
actions: [
IconButton(
icon: const Icon(Icons.done),
onPressed: () {
context.pop(_controller.fullText);
},
),
],
),
body: CodeTheme(
data: CodeThemeData(styles: monokaiSublimeTheme),
child: SingleChildScrollView(
child: CodeField(
controller: _controller,
gutterStyle: const GutterStyle(
width: 37,
showLineNumbers: false,
),
),
),
),
);
}
}

View File

@@ -3,6 +3,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:toolbox/core/extension/navigator.dart';
import 'package:toolbox/view/page/editor.dart';
import '../../../core/extension/numx.dart';
import '../../../core/extension/stringx.dart';
@@ -172,6 +173,21 @@ class _SFTPDownloadedPageState extends State<SFTPDownloadedPage> {
shareFiles(context, [file.absolute.path]);
},
),
ListTile(
leading: const Icon(Icons.edit),
title: Text(_s.edit),
onTap: () async {
context.pop();
final stat = await file.stat();
if (stat.size > 1024 * 1024) {
showRoundDialog(context: context, child: Text('too big'));
return;
}
final f = await File(file.absolute.path).readAsString();
AppRoute(EditorPage(initCode: f), 'sftp dled editor')
.go(context);
},
)
],
),
actions: [

View File

@@ -10,7 +10,6 @@ import 'package:toolbox/core/extension/navigator.dart';
import 'package:xterm/xterm.dart';
import '../../core/utils/platform.dart';
import '../../data/model/ssh/terminal_color.dart';
import '../../core/utils/misc.dart';
import '../../core/utils/ui.dart';
import '../../core/utils/server.dart';
@@ -44,7 +43,6 @@ class _SSHPageState extends State<SSHPage> {
late TextStyle _menuTextStyle;
late S _s;
late TerminalStyle _terminalStyle;
late TerminalUITheme _termUITheme;
late TerminalTheme _terminalTheme;
var _isDark = false;
@@ -68,8 +66,7 @@ class _SSHPageState extends State<SSHPage> {
_media = MediaQuery.of(context);
_menuTextStyle = TextStyle(color: contentColor.resolve(context));
_s = S.of(context)!;
_termUITheme = _isDark ? termDarkTheme : termLightTheme;
_terminalTheme = _termUITheme.toTerminalTheme(MacOSTerminalColor());
_terminalTheme = _isDark ? termDarkTheme : termLightTheme;
}
@override
@@ -81,7 +78,7 @@ class _SSHPageState extends State<SSHPage> {
@override
Widget build(BuildContext context) {
Widget child = Scaffold(
backgroundColor: _termUITheme.background,
backgroundColor: _terminalTheme.background,
body: _buildBody(),
bottomNavigationBar: _buildBottom(),
);
@@ -120,7 +117,7 @@ class _SSHPageState extends State<SSHPage> {
duration: const Duration(milliseconds: 23),
curve: Curves.fastOutSlowIn,
child: Container(
color: _termUITheme.background,
color: _terminalTheme.background,
height: _virtualKeyboardHeight,
child: Consumer<VirtualKeyboard>(
builder: (_, __, ___) => _buildVirtualKey(),