1
This commit is contained in:
1 parent
54c3083c24
commit
87e03ce0d8
44 files changed
+3965
-307
No files matched your search
@@ -0,0 +1,250 @@
|
||||
/// 字体定义与预设常量
|
||||
class AppFontItem {
|
||||
final String id;
|
||||
final String name;
|
||||
final String? fontFamily;
|
||||
final List<String> fallback;
|
||||
final bool isMonospace;
|
||||
|
||||
const AppFontItem({
|
||||
required this.id,
|
||||
required this.name,
|
||||
this.fontFamily,
|
||||
this.fallback = const [],
|
||||
this.isMonospace = false,
|
||||
});
|
||||
}
|
||||
|
||||
/// 集中管理的字体常量表(方便随时追加网络/本地下载的字体)
|
||||
class AppFonts {
|
||||
// ==========================================
|
||||
// 1. 外观 UI 字体选项
|
||||
// ==========================================
|
||||
static const AppFontItem uiDefault = AppFontItem(
|
||||
id: 'system_default',
|
||||
name: '系统默认 (System Default)',
|
||||
fontFamily: null,
|
||||
fallback: [
|
||||
'PingFang SC',
|
||||
'Noto Sans SC',
|
||||
'Microsoft YaHei',
|
||||
'WenQuanYi Micro Hei',
|
||||
'sans-serif',
|
||||
],
|
||||
);
|
||||
|
||||
static const AppFontItem uiSansSerif = AppFontItem(
|
||||
id: 'sans_serif',
|
||||
name: '无衬线体 (Sans-Serif)',
|
||||
fontFamily: 'sans-serif',
|
||||
fallback: [
|
||||
'PingFang SC',
|
||||
'Noto Sans SC',
|
||||
'Microsoft YaHei',
|
||||
'sans-serif',
|
||||
],
|
||||
);
|
||||
|
||||
static const AppFontItem uiSerif = AppFontItem(
|
||||
id: 'serif',
|
||||
name: '衬线体 (Serif / 宋体)',
|
||||
fontFamily: 'serif',
|
||||
fallback: [
|
||||
'Songti SC',
|
||||
'SimSun',
|
||||
'serif',
|
||||
],
|
||||
);
|
||||
|
||||
static const AppFontItem uiJetBrainsMono = AppFontItem(
|
||||
id: 'jetbrains_mono',
|
||||
name: 'JetBrains Mono',
|
||||
fontFamily: 'JetBrains Mono',
|
||||
fallback: [
|
||||
'PingFang SC',
|
||||
'Noto Sans SC',
|
||||
'Microsoft YaHei',
|
||||
'sans-serif',
|
||||
],
|
||||
);
|
||||
|
||||
static const AppFontItem uiFiraCode = AppFontItem(
|
||||
id: 'fira_code',
|
||||
name: 'Fira Code',
|
||||
fontFamily: 'Fira Code',
|
||||
fallback: [
|
||||
'PingFang SC',
|
||||
'Noto Sans SC',
|
||||
'Microsoft YaHei',
|
||||
'sans-serif',
|
||||
],
|
||||
);
|
||||
|
||||
/// 外观 UI 可选字体列表
|
||||
static const List<AppFontItem> uiFonts = [
|
||||
uiDefault,
|
||||
uiSansSerif,
|
||||
uiSerif,
|
||||
uiJetBrainsMono,
|
||||
uiFiraCode,
|
||||
];
|
||||
|
||||
// ==========================================
|
||||
// 2. 代码编辑区字体选项
|
||||
// ==========================================
|
||||
static const AppFontItem editorMonospace = AppFontItem(
|
||||
id: 'monospace',
|
||||
name: '系统等宽 (System Monospace)',
|
||||
fontFamily: 'monospace',
|
||||
fallback: [
|
||||
'Consolas',
|
||||
'Menlo',
|
||||
'Monaco',
|
||||
'Courier New',
|
||||
'monospace',
|
||||
],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem editorConsolas = AppFontItem(
|
||||
id: 'consolas',
|
||||
name: 'Consolas',
|
||||
fontFamily: 'Consolas',
|
||||
fallback: ['monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem editorCourierNew = AppFontItem(
|
||||
id: 'courier_new',
|
||||
name: 'Courier New',
|
||||
fontFamily: 'Courier New',
|
||||
fallback: ['Courier', 'monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem editorMenlo = AppFontItem(
|
||||
id: 'menlo',
|
||||
name: 'Menlo / Monaco',
|
||||
fontFamily: 'Menlo',
|
||||
fallback: ['Monaco', 'monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
/// 预设的开源编程字体配置(用户后续下载字体包放入 assets/fonts/ 并配置 pubspec 后即可即开即用)
|
||||
static const AppFontItem editorJetBrainsMono = AppFontItem(
|
||||
id: 'jetbrains_mono',
|
||||
name: 'JetBrains Mono (推荐)',
|
||||
fontFamily: 'JetBrains Mono',
|
||||
fallback: ['monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem editorFiraCode = AppFontItem(
|
||||
id: 'fira_code',
|
||||
name: 'Fira Code',
|
||||
fontFamily: 'Fira Code',
|
||||
fallback: ['monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
/// 代码编辑区可选字体列表
|
||||
static const List<AppFontItem> editorFonts = [
|
||||
editorMonospace,
|
||||
editorConsolas,
|
||||
editorCourierNew,
|
||||
editorMenlo,
|
||||
editorJetBrainsMono,
|
||||
editorFiraCode,
|
||||
];
|
||||
|
||||
// ==========================================
|
||||
// 3. 终端字体选项
|
||||
// ==========================================
|
||||
static const AppFontItem terminalMonospace = AppFontItem(
|
||||
id: 'monospace',
|
||||
name: '系统等宽 (System Monospace)',
|
||||
fontFamily: 'monospace',
|
||||
fallback: [
|
||||
'Consolas',
|
||||
'Menlo',
|
||||
'Monaco',
|
||||
'Courier New',
|
||||
'monospace',
|
||||
],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem terminalConsolas = AppFontItem(
|
||||
id: 'consolas',
|
||||
name: 'Consolas',
|
||||
fontFamily: 'Consolas',
|
||||
fallback: ['monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem terminalCourierNew = AppFontItem(
|
||||
id: 'courier_new',
|
||||
name: 'Courier New',
|
||||
fontFamily: 'Courier New',
|
||||
fallback: ['Courier', 'monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem terminalMenlo = AppFontItem(
|
||||
id: 'menlo',
|
||||
name: 'Menlo / Monaco',
|
||||
fontFamily: 'Menlo',
|
||||
fallback: ['Monaco', 'monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem terminalJetBrainsMono = AppFontItem(
|
||||
id: 'jetbrains_mono',
|
||||
name: 'JetBrains Mono (推荐)',
|
||||
fontFamily: 'JetBrains Mono',
|
||||
fallback: ['monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
static const AppFontItem terminalFiraCode = AppFontItem(
|
||||
id: 'fira_code',
|
||||
name: 'Fira Code',
|
||||
fontFamily: 'Fira Code',
|
||||
fallback: ['monospace'],
|
||||
isMonospace: true,
|
||||
);
|
||||
|
||||
/// 终端可选字体列表
|
||||
static const List<AppFontItem> terminalFonts = [
|
||||
terminalMonospace,
|
||||
terminalConsolas,
|
||||
terminalCourierNew,
|
||||
terminalMenlo,
|
||||
terminalJetBrainsMono,
|
||||
terminalFiraCode,
|
||||
];
|
||||
|
||||
// ==========================================
|
||||
// 4. 查询辅助方法
|
||||
// ==========================================
|
||||
static AppFontItem getUiFont(String? id) {
|
||||
return uiFonts.firstWhere(
|
||||
(f) => f.id == id,
|
||||
orElse: () => uiDefault,
|
||||
);
|
||||
}
|
||||
|
||||
static AppFontItem getEditorFont(String? id) {
|
||||
return editorFonts.firstWhere(
|
||||
(f) => f.id == id,
|
||||
orElse: () => editorMonospace,
|
||||
);
|
||||
}
|
||||
|
||||
static AppFontItem getTerminalFont(String? id) {
|
||||
return terminalFonts.firstWhere(
|
||||
(f) => f.id == id,
|
||||
orElse: () => terminalMonospace,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
/// Linux 发行版安装状态
|
||||
enum DistroStatus {
|
||||
/// 未安装
|
||||
notInstalled,
|
||||
|
||||
/// 正在安装/解压中
|
||||
installing,
|
||||
|
||||
/// 已安装就绪
|
||||
installed,
|
||||
|
||||
/// 安装或运行异常
|
||||
error,
|
||||
}
|
||||
|
||||
/// Linux 发行版元数据模型,具备高扩展性
|
||||
class DistroInfo {
|
||||
/// 唯一标识符,例如 'alpine', 'debian', 'ubuntu', 'host'
|
||||
final String id;
|
||||
|
||||
/// 显示名称,例如 'Alpine Linux'
|
||||
final String name;
|
||||
|
||||
/// 版本号,例如 '3.20.3'
|
||||
final String version;
|
||||
|
||||
/// 描述信息
|
||||
final String description;
|
||||
|
||||
/// 默认登录 Shell,例如 '/bin/sh', '/bin/bash'
|
||||
final String defaultShell;
|
||||
|
||||
/// 包管理器名称,例如 'apk', 'apt'
|
||||
final String packageManager;
|
||||
|
||||
/// 支持的硬件架构,例如 ['aarch64', 'arm64-v8a']
|
||||
final List<String> supportedArchs;
|
||||
|
||||
/// 内置应用资源路径(如有,可离线解压)
|
||||
final String? assetPath;
|
||||
|
||||
/// 远程下载地址(支持网络按需下载扩展)
|
||||
final String? downloadUrl;
|
||||
|
||||
/// 是否为官方内置预设
|
||||
final bool isBuiltin;
|
||||
|
||||
/// 图标名称标识
|
||||
final String iconName;
|
||||
|
||||
const DistroInfo({
|
||||
required this.id,
|
||||
required this.name,
|
||||
required this.version,
|
||||
required this.description,
|
||||
this.defaultShell = '/bin/sh',
|
||||
this.packageManager = 'apk',
|
||||
this.supportedArchs = const ['aarch64', 'arm64-v8a', 'all'],
|
||||
this.assetPath,
|
||||
this.downloadUrl,
|
||||
this.isBuiltin = true,
|
||||
this.iconName = 'terminal',
|
||||
});
|
||||
|
||||
/// 预设:Alpine Linux (轻量极速,内置 asset)
|
||||
static const DistroInfo alpine = DistroInfo(
|
||||
id: 'alpine',
|
||||
name: 'Alpine Linux',
|
||||
version: '3.20.3',
|
||||
description: '轻量快速的 Linux 发行版,体积仅约 4MB,内置 apk 包管理器',
|
||||
defaultShell: '/bin/sh',
|
||||
packageManager: 'apk',
|
||||
supportedArchs: ['aarch64', 'arm64-v8a'],
|
||||
assetPath: 'assets/distros/alpine-minirootfs-3.20.3-aarch64.tar.gz',
|
||||
isBuiltin: true,
|
||||
iconName: 'alpine',
|
||||
);
|
||||
|
||||
/// 预设扩展:Debian GNU/Linux
|
||||
static const DistroInfo debian = DistroInfo(
|
||||
id: 'debian',
|
||||
name: 'Debian GNU/Linux',
|
||||
version: '12 (Bookworm)',
|
||||
description: '全能稳定的 Linux 发行版,标准 glibc 兼容,内置 apt 包管理器',
|
||||
defaultShell: '/bin/bash',
|
||||
packageManager: 'apt',
|
||||
supportedArchs: ['aarch64', 'x86_64'],
|
||||
downloadUrl: 'https://mirrors.tuna.tsinghua.edu.cn/lxc-images/images/debian/bookworm/arm64/default/',
|
||||
isBuiltin: false,
|
||||
iconName: 'debian',
|
||||
);
|
||||
|
||||
/// 预设扩展:Ubuntu
|
||||
static const DistroInfo ubuntu = DistroInfo(
|
||||
id: 'ubuntu',
|
||||
name: 'Ubuntu',
|
||||
version: '24.04 LTS',
|
||||
description: '应用与开发生态丰富的流行 Linux 发行版,内置 apt 包管理器',
|
||||
defaultShell: '/bin/bash',
|
||||
packageManager: 'apt',
|
||||
supportedArchs: ['aarch64', 'x86_64'],
|
||||
downloadUrl: 'https://mirrors.tuna.tsinghua.edu.cn/ubuntu-cdimage/ubuntu-base/releases/24.04/release/',
|
||||
isBuiltin: false,
|
||||
iconName: 'ubuntu',
|
||||
);
|
||||
|
||||
/// 预设:Android 本地 Shell
|
||||
static const DistroInfo host = DistroInfo(
|
||||
id: 'host',
|
||||
name: '本地 Shell',
|
||||
version: 'Android',
|
||||
description: '直接调用安卓系统内置的基础 Shell,无需虚拟环境',
|
||||
defaultShell: '/system/bin/sh',
|
||||
packageManager: 'none',
|
||||
supportedArchs: ['all'],
|
||||
isBuiltin: true,
|
||||
iconName: 'host',
|
||||
);
|
||||
|
||||
/// 默认官方预设列表
|
||||
static const List<DistroInfo> defaults = [
|
||||
alpine,
|
||||
debian,
|
||||
ubuntu,
|
||||
host,
|
||||
];
|
||||
|
||||
DistroInfo copyWith({
|
||||
String? id,
|
||||
String? name,
|
||||
String? version,
|
||||
String? description,
|
||||
String? defaultShell,
|
||||
String? packageManager,
|
||||
List<String>? supportedArchs,
|
||||
String? assetPath,
|
||||
String? downloadUrl,
|
||||
bool? isBuiltin,
|
||||
String? iconName,
|
||||
}) {
|
||||
return DistroInfo(
|
||||
id: id ?? this.id,
|
||||
name: name ?? this.name,
|
||||
version: version ?? this.version,
|
||||
description: description ?? this.description,
|
||||
defaultShell: defaultShell ?? this.defaultShell,
|
||||
packageManager: packageManager ?? this.packageManager,
|
||||
supportedArchs: supportedArchs ?? this.supportedArchs,
|
||||
assetPath: assetPath ?? this.assetPath,
|
||||
downloadUrl: downloadUrl ?? this.downloadUrl,
|
||||
isBuiltin: isBuiltin ?? this.isBuiltin,
|
||||
iconName: iconName ?? this.iconName,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
'name': name,
|
||||
'version': version,
|
||||
'description': description,
|
||||
'defaultShell': defaultShell,
|
||||
'packageManager': packageManager,
|
||||
'supportedArchs': supportedArchs,
|
||||
'assetPath': assetPath,
|
||||
'downloadUrl': downloadUrl,
|
||||
'isBuiltin': isBuiltin,
|
||||
'iconName': iconName,
|
||||
};
|
||||
}
|
||||
|
||||
factory DistroInfo.fromJson(Map<String, dynamic> json) {
|
||||
return DistroInfo(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
version: json['version'] as String,
|
||||
description: json['description'] as String,
|
||||
defaultShell: (json['defaultShell'] as String?) ?? '/bin/sh',
|
||||
packageManager: (json['packageManager'] as String?) ?? 'apk',
|
||||
supportedArchs: (json['supportedArchs'] as List<dynamic>?)
|
||||
?.map((e) => e.toString())
|
||||
.toList() ??
|
||||
const ['aarch64'],
|
||||
assetPath: json['assetPath'] as String?,
|
||||
downloadUrl: json['downloadUrl'] as String?,
|
||||
isBuiltin: (json['isBuiltin'] as bool?) ?? false,
|
||||
iconName: (json['iconName'] as String?) ?? 'terminal',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// 单个终端会话的数据与状态模型
|
||||
class TerminalSession {
|
||||
final String id;
|
||||
String name;
|
||||
final String distroId;
|
||||
final DateTime createdAt;
|
||||
final List<String> outputLines;
|
||||
final TextEditingController inputController;
|
||||
final ScrollController scrollController;
|
||||
final FocusNode focusNode;
|
||||
|
||||
TerminalSession({
|
||||
required this.id,
|
||||
this.name = '会话',
|
||||
this.distroId = 'alpine',
|
||||
DateTime? createdAt,
|
||||
List<String>? initialOutput,
|
||||
}) : createdAt = createdAt ?? DateTime.now(),
|
||||
outputLines = initialOutput ?? <String>[],
|
||||
inputController = TextEditingController(),
|
||||
scrollController = ScrollController(),
|
||||
focusNode = FocusNode();
|
||||
|
||||
/// 向终端输出追加内容
|
||||
void appendOutput(String line) {
|
||||
outputLines.add(line);
|
||||
_autoScrollToBottom();
|
||||
}
|
||||
|
||||
/// 自动滚动到终端最底部
|
||||
void _autoScrollToBottom() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (scrollController.hasClients) {
|
||||
scrollController.animateTo(
|
||||
scrollController.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 100),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// 清屏
|
||||
void clear() {
|
||||
outputLines.clear();
|
||||
}
|
||||
|
||||
/// 释放资源
|
||||
void dispose() {
|
||||
inputController.dispose();
|
||||
scrollController.dispose();
|
||||
focusNode.dispose();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user