From 33c636afada32dd842cb4775428f64de20337781 Mon Sep 17 00:00:00 2001 From: qianmoQ Date: Thu, 14 Aug 2025 21:58:17 +0800 Subject: [PATCH] =?UTF-8?q?feat=20(language):=20=E6=94=AF=E6=8C=81=20Shell?= =?UTF-8?q?=20=E8=AF=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 ++ package.json | 2 + public/icons/shell.svg | 13 +++++++ src-tauri/src/plugins/manager.rs | 2 + src-tauri/src/plugins/mod.rs | 1 + src-tauri/src/plugins/shell.rs | 54 ++++++++++++++++++++++++++ src/components/setting/Language.vue | 2 +- src/composables/useCodeMirrorEditor.ts | 4 ++ 8 files changed, 80 insertions(+), 1 deletion(-) create mode 100644 public/icons/shell.svg create mode 100644 src-tauri/src/plugins/shell.rs diff --git a/README.md b/README.md index 5c0b86c..ce043ea 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发 - **Python 2** - **Python 3** +- **Node.js** +- **Go** +- **Java** - **...更多语言敬请期待** ## 安装 diff --git a/package.json b/package.json index 8260682..68681ab 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,8 @@ "@codemirror/lang-java": "^6.0.2", "@codemirror/lang-javascript": "^6.2.4", "@codemirror/lang-python": "^6.2.1", + "@codemirror/language": "^6.11.2", + "@codemirror/legacy-modes": "^6.5.1", "@codemirror/state": "^6.5.2", "@codemirror/view": "^6.38.1", "@tauri-apps/api": "^2", diff --git a/public/icons/shell.svg b/public/icons/shell.svg new file mode 100644 index 0000000..f0d81ed --- /dev/null +++ b/public/icons/shell.svg @@ -0,0 +1,13 @@ + + + + + + >_ + + + + + + + diff --git a/src-tauri/src/plugins/manager.rs b/src-tauri/src/plugins/manager.rs index fa74661..bca946b 100644 --- a/src-tauri/src/plugins/manager.rs +++ b/src-tauri/src/plugins/manager.rs @@ -3,6 +3,7 @@ use super::{ python3::Python3Plugin, }; use crate::plugins::java::JavaPlugin; +use crate::plugins::shell::ShellPlugin; use std::collections::HashMap; pub struct PluginManager { @@ -18,6 +19,7 @@ impl PluginManager { plugins.insert("nodejs".to_string(), Box::new(NodeJSPlugin)); plugins.insert("go".to_string(), Box::new(GoPlugin)); plugins.insert("java".to_string(), Box::new(JavaPlugin)); + plugins.insert("shell".to_string(), Box::new(ShellPlugin)); Self { plugins } } diff --git a/src-tauri/src/plugins/mod.rs b/src-tauri/src/plugins/mod.rs index 6c20443..0be83e7 100644 --- a/src-tauri/src/plugins/mod.rs +++ b/src-tauri/src/plugins/mod.rs @@ -335,5 +335,6 @@ pub mod manager; pub mod nodejs; pub mod python2; pub mod python3; +pub mod shell; pub use manager::PluginManager; diff --git a/src-tauri/src/plugins/shell.rs b/src-tauri/src/plugins/shell.rs new file mode 100644 index 0000000..c708e19 --- /dev/null +++ b/src-tauri/src/plugins/shell.rs @@ -0,0 +1,54 @@ +use super::{LanguagePlugin, PluginConfig}; +use std::vec; + +pub struct ShellPlugin; + +impl LanguagePlugin for ShellPlugin { + fn get_order(&self) -> i32 { + 6 + } + + fn get_language_name(&self) -> &'static str { + "Shell" + } + + fn get_language_key(&self) -> &'static str { + "shell" + } + + fn get_file_extension(&self) -> String { + self.get_config() + .map(|config| config.extension.clone()) + .unwrap_or_else(|| "sh".to_string()) + } + + fn get_version_args(&self) -> Vec<&'static str> { + vec!["--version"] + } + + fn get_path_command(&self) -> String { + "which bash || which sh".to_string() + } + + fn get_default_config(&self) -> PluginConfig { + PluginConfig { + enabled: true, + language: String::from("shell"), + before_compile: None, + extension: String::from("sh"), + execute_home: None, + run_command: Some(String::from("bash $filename")), + after_compile: None, + template: Some(String::from( + "#!/bin/bash\n# Shell 示例代码 - CodeForge 代码执行环境\n\necho \"🎉 欢迎使用 CodeForge!\"\necho \"Welcome to CodeForge!\"\necho \"\"\n\necho \"=========================================\"\necho \" CodeForge Shell \"\necho \"=========================================\"\necho \"\"\n\n# 基本输出示例\necho \"✅ Shell 运行成功! (Shell is working!)\"\necho \"🐚 这是 Shell 脚本 (This is Shell script)\"\necho \"\"\n\n# 变量操作\nname=\"CodeForge\"\nversion=\"Shell\"\nnumber1=10\nnumber2=20\nresult=$((number1 + number2))\n\necho \"🔢 简单计算 (Simple calculation):\"\necho \"$number1 + $number2 = $result\"\necho \"\"\n\n# 字符串操作\necho \"📝 字符串操作 (String operations):\"\necho \"平台名称 (Platform): $name\"\necho \"语言版本 (Language): $version\"\necho \"完整信息 (Full info): $name - $version\"\necho \"\"\n\n# 循环示例\necho \"🔄 循环输出 (Loop output):\"\nfor i in {1..5}; do\n echo \"第 $i 次输出 (Output #$i): Hello from CodeForge!\"\ndone\necho \"\"\n\n# 数组操作\nfruits=(\"苹果\" \"香蕉\" \"橙子\" \"葡萄\")\necho \"🍎 水果列表 (Fruit list):\"\nfor i in \"${!fruits[@]}\"; do\n echo \"$((i + 1)). ${fruits[i]}\"\ndone\necho \"\"\n\n# 条件判断\nscore=85\necho \"📊 成绩评估 (Score evaluation):\"\nif [ $score -ge 90 ]; then\n echo \"优秀! (Excellent!)\"\nelif [ $score -ge 80 ]; then\n echo \"良好! (Good!)\"\nelif [ $score -ge 60 ]; then\n echo \"及格 (Pass)\"\nelse\n echo \"需要努力 (Need improvement)\"\nfi\n\necho \"\"\necho \"🎯 CodeForge Shell 代码执行完成!\"\necho \"🎯 CodeForge Shell execution completed!\"\necho \"\"\necho \"感谢使用 CodeForge 代码执行环境! 🚀\"\necho \"Thank you for using CodeForge! 🚀\"", + )), + timeout: Some(30), + } + } + + fn get_default_command(&self) -> String { + self.get_config() + .and_then(|config| config.run_command.clone()) + .unwrap_or_else(|| "bash".to_string()) + } +} diff --git a/src/components/setting/Language.vue b/src/components/setting/Language.vue index 9fa6085..4dd22b4 100644 --- a/src/components/setting/Language.vue +++ b/src/components/setting/Language.vue @@ -98,7 +98,7 @@