Skip to content

Commit 9919650

Browse files
committed
feat (language): 支持 Cangjie 语言
1 parent 5d528ac commit 9919650

File tree

8 files changed

+199
-1
lines changed

8 files changed

+199
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ CodeForge 是一款轻量级、高性能的桌面代码执行器,专为开发
2424

2525
<div style="display: flex; align-items: center; justify-content: center;">
2626
<img src="public/icons/c.svg" width="60" alt="C">
27+
<img src="public/icons/cangjie.svg" width="60" alt="Cangjie">
2728
<img src="public/icons/clojure.svg" width="60" alt="Clojure">
2829
<img src="public/icons/cpp.svg" width="60" alt="C++">
2930
<img src="public/icons/css.svg" width="60" alt="CSS">

public/icons/cangjie.svg

Lines changed: 17 additions & 0 deletions
Loading

src-tauri/src/examples/cangjie.cj

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
// 仓颉示例代码 - CodeForge 代码执行环境
2+
3+
main(): Unit {
4+
println("🎉 欢迎使用 CodeForge!")
5+
println("Welcome to CodeForge!")
6+
println("")
7+
8+
println("=========================================")
9+
println(" CodeForge Cangjie ")
10+
println("=========================================")
11+
println("")
12+
13+
// 基本输出示例
14+
println("✅ 仓颉运行成功! (Cangjie is working!)")
15+
println("⚡ 这是仓颉程序 (This is Cangjie program)")
16+
println("")
17+
18+
// 变量操作
19+
let name = "CodeForge"
20+
let version = "Cangjie"
21+
let number1 = 10
22+
let number2 = 20
23+
let result = number1 + number2
24+
25+
println("🔢 简单计算 (Simple calculation):")
26+
println("${number1} + ${number2} = ${result}")
27+
println("")
28+
29+
// 字符串操作和插值
30+
println("📝 字符串操作 (String operations):")
31+
println("平台名称 (Platform): ${name}")
32+
println("语言版本 (Language): ${version}")
33+
println("完整信息 (Full info): ${name} - ${version}")
34+
println("")
35+
36+
// 数组操作
37+
println("🍎 数组示例 (Array example):")
38+
let fruits = ["苹果", "香蕉", "橙子", "葡萄"]
39+
for (i in 0..fruits.size) {
40+
println("${i + 1}. ${fruits[i]}")
41+
}
42+
println("")
43+
44+
// 条件判断
45+
let score = 85
46+
println("📊 成绩评估 (Score evaluation):")
47+
if (score >= 90) {
48+
println("优秀! (Excellent!)")
49+
} else if (score >= 80) {
50+
println("良好! (Good!)")
51+
} else if (score >= 60) {
52+
println("及格 (Pass)")
53+
} else {
54+
println("需要努力 (Need improvement)")
55+
}
56+
println("")
57+
58+
// 循环示例
59+
println("🔄 循环输出 (Loop output):")
60+
for (i in 1..6) {
61+
println("第 ${i} 次输出 (Output #${i}): Hello from CodeForge!")
62+
}
63+
println("")
64+
65+
// while循环示例
66+
println("🔁 While循环示例 (While loop example):")
67+
var counter = 1
68+
while (counter <= 3) {
69+
println("While循环: 第 ${counter} 次")
70+
counter += 1
71+
}
72+
println("")
73+
74+
println("🎯 CodeForge 仓颉代码执行完成!")
75+
println("🎯 CodeForge Cangjie execution completed!")
76+
println("")
77+
println("感谢使用 CodeForge 代码执行环境! 🚀")
78+
println("Thank you for using CodeForge! 🚀")
79+
}

src-tauri/src/plugins/cangjie.rs

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
use super::{LanguagePlugin, PluginConfig};
2+
use std::vec;
3+
4+
pub struct CangjiePlugin;
5+
6+
impl LanguagePlugin for CangjiePlugin {
7+
fn get_order(&self) -> i32 {
8+
24
9+
}
10+
11+
fn get_language_name(&self) -> &'static str {
12+
"Cangjie"
13+
}
14+
15+
fn get_language_key(&self) -> &'static str {
16+
"cangjie"
17+
}
18+
19+
fn get_file_extension(&self) -> String {
20+
self.get_config()
21+
.map(|config| config.extension.clone())
22+
.unwrap_or_else(|| "cj".to_string())
23+
}
24+
25+
fn get_version_args(&self) -> Vec<&'static str> {
26+
vec!["--version"]
27+
}
28+
29+
fn get_path_command(&self) -> String {
30+
"which cjc".to_string()
31+
}
32+
33+
fn get_command(
34+
&self,
35+
_file_path: Option<&str>,
36+
_is_version: bool,
37+
_file_name: Option<String>,
38+
) -> String {
39+
if _is_version {
40+
let cjc_command = if self.get_execute_home().is_some() {
41+
"./cjc"
42+
} else {
43+
"cjc"
44+
};
45+
46+
return cjc_command.to_string();
47+
}
48+
49+
// 执行代码时
50+
if let Some(config) = self.get_config() {
51+
if let Some(run_cmd) = &config.run_command {
52+
return if let Some(file_name) = _file_name {
53+
run_cmd.replace("$filename", &file_name)
54+
} else {
55+
// 执行代码但没有文件名时,返回原始命令让框架处理 $filename 替换
56+
run_cmd.clone()
57+
};
58+
}
59+
}
60+
self.get_default_command()
61+
}
62+
63+
fn get_execute_args(&self, file_path: &str) -> Vec<String> {
64+
let cjc_command = if self.get_execute_home().is_some() {
65+
"./cjc"
66+
} else {
67+
"cjc"
68+
};
69+
70+
let cmd = format!("{} {}", cjc_command, file_path);
71+
72+
vec!["-c".to_string(), cmd]
73+
}
74+
75+
fn get_default_config(&self) -> PluginConfig {
76+
PluginConfig {
77+
enabled: true,
78+
language: String::from("cangjie"),
79+
before_compile: Some(String::from("cjc $filename -o main")),
80+
extension: String::from("cj"),
81+
execute_home: None,
82+
run_command: Some(String::from("main")),
83+
after_compile: Some(String::from("rm -f main")),
84+
template: Some(String::from(
85+
"// 在这里输入仓颉代码\n// 仓颉 - 华为开发的现代编程语言",
86+
)),
87+
timeout: Some(30),
88+
console_type: Some(String::from("console")),
89+
}
90+
}
91+
92+
fn get_default_command(&self) -> String {
93+
self.get_config()
94+
.and_then(|config| config.run_command.clone())
95+
.unwrap_or_else(|| "cjc".to_string())
96+
}
97+
}

src-tauri/src/plugins/manager.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::{LanguagePlugin, PluginConfig};
22
use crate::plugins::applescript::AppleScriptPlugin;
33
use crate::plugins::c::CPlugin;
4+
use crate::plugins::cangjie::CangjiePlugin;
45
use crate::plugins::clojure::ClojurePlugin;
56
use crate::plugins::cpp::CppPlugin;
67
use crate::plugins::css::CssPlugin;
@@ -58,6 +59,7 @@ impl PluginManager {
5859
plugins.insert("svg".to_string(), Box::new(SvgPlugin));
5960
plugins.insert("php".to_string(), Box::new(PHPPlugin));
6061
plugins.insert("r".to_string(), Box::new(RPlugin));
62+
plugins.insert("cangjie".to_string(), Box::new(CangjiePlugin));
6163
plugins.insert(
6264
"javascript-nodejs".to_string(),
6365
Box::new(JavaScriptNodeJsPlugin),

src-tauri/src/plugins/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ pub trait LanguagePlugin: Send + Sync {
371371
// 重新导出子模块
372372
pub mod applescript;
373373
pub mod c;
374+
pub mod cangjie;
374375
pub mod clojure;
375376
pub mod cpp;
376377
pub mod css;

src-tauri/src/plugins/r.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub struct RPlugin;
55

66
impl LanguagePlugin for RPlugin {
77
fn get_order(&self) -> i32 {
8-
17
8+
23
99
}
1010

1111
fn get_language_name(&self) -> &'static str {

src/composables/useCodeMirrorEditor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ export function useCodeMirrorEditor(props: Props)
179179
case 'java':
180180
return java()
181181
case 'rust':
182+
case 'cangjie':
182183
return rust()
183184
case 'c':
184185
case 'cpp':

0 commit comments

Comments
 (0)