Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发

- **Python 2**
- **Python 3**
- **Node.js**
- **Go**
- **Java**
- **...更多语言敬请期待**

## 安装
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 13 additions & 0 deletions public/icons/shell.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src-tauri/src/plugins/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 }
}
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/plugins/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,5 +335,6 @@ pub mod manager;
pub mod nodejs;
pub mod python2;
pub mod python3;
pub mod shell;

pub use manager::PluginManager;
54 changes: 54 additions & 0 deletions src-tauri/src/plugins/shell.rs
Original file line number Diff line number Diff line change
@@ -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())
}
}
2 changes: 1 addition & 1 deletion src/components/setting/Language.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<template #template>
<div class="w-[98%]">
<Codemirror v-if="isEditorReady && pluginConfig.template !== undefined"
style="width: 100%; height: 380px"
style="width: 102%; height: 380px"
v-model="pluginConfig.template"
:extensions="currentExtensions"
class="flex-1 border border-gray-300 dark:border-gray-600 rounded-md overflow-hidden"/>
Expand Down
4 changes: 4 additions & 0 deletions src/composables/useCodeMirrorEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { python } from '@codemirror/lang-python'
import { javascript } from '@codemirror/lang-javascript'
import { go } from '@codemirror/lang-go'
import { java } from '@codemirror/lang-java'
import { shell } from '@codemirror/legacy-modes/mode/shell'
import {
abcdef,
abyss,
Expand Down Expand Up @@ -53,6 +54,7 @@ import {
} from '@uiw/codemirror-themes-all'
import { invoke } from '@tauri-apps/api/core'
import { useToast } from '../plugins/toast'
import { StreamLanguage } from '@codemirror/language'

interface EditorConfig
{
Expand Down Expand Up @@ -153,6 +155,8 @@ export function useCodeMirrorEditor(props: Props)
return go()
case 'java':
return java()
case 'shell':
return StreamLanguage.define(shell)
default:
return null
}
Expand Down
Loading