forked from devlive-community/codeforge
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcpp.rs
More file actions
79 lines (68 loc) · 2.22 KB
/
cpp.rs
File metadata and controls
79 lines (68 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use super::{LanguagePlugin, PluginConfig};
use std::vec;
pub struct CppPlugin;
impl LanguagePlugin for CppPlugin {
fn get_order(&self) -> i32 {
18
}
fn get_language_name(&self) -> &'static str {
"C++"
}
fn get_language_key(&self) -> &'static str {
"cpp"
}
fn get_file_extension(&self) -> String {
self.get_config()
.map(|config| config.extension.clone())
.unwrap_or_else(|| "cpp".to_string())
}
fn get_version_args(&self) -> Vec<&'static str> {
vec!["--version"]
}
fn get_path_command(&self) -> String {
"which g++".to_string()
}
fn get_command(
&self,
_file_path: Option<&str>,
_is_version: bool,
_file_name: Option<String>,
) -> String {
if _is_version {
// 获取版本信息时,返回编译器命令
return "g++".to_string();
}
// 执行代码时
if let Some(config) = self.get_config() {
if let Some(run_cmd) = &config.run_command {
return if let Some(file_name) = _file_name {
run_cmd.replace("$filename", &file_name)
} else {
// 执行代码但没有文件名时,返回原始命令让框架处理 $filename 替换
run_cmd.clone()
};
}
}
self.get_default_command()
}
fn get_default_config(&self) -> PluginConfig {
PluginConfig {
enabled: true,
language: String::from("cpp"),
before_compile: Some(String::from("g++ $filename -o $filename")),
extension: String::from("cpp"),
execute_home: None,
run_command: Some(String::from("$filename")),
after_compile: Some(String::from("rm -f $filename")),
template: Some(String::from("// 在这里输入 C++ 代码")),
timeout: Some(30),
console_type: Some(String::from("console")),
icon_path: None,
}
}
fn get_default_command(&self) -> String {
self.get_config()
.and_then(|config| config.run_command.clone())
.unwrap_or_else(|| "g++".to_string())
}
}