Skip to content

Commit 5d785d9

Browse files
GnoCiYeHtrv3woodsparkzkysparkzkyzhuweihao12138
authored
Refactor (#37)
* Patch refactor render/input/plugin (#22) 重新构建整体架构,包括: 渲染模块 输入处理模块 新增插件系统框架 * Feat insert (#23) * Insert mode * 完善render_lexme (#24) * 完善render_lexme换行和\t * 解决退出时屏幕没有刷新的问题 --------- Co-authored-by: sparkzky <[email protected]> * 优化渲染模块,采用局部渲染提高渲染速度 (#26) * insertMode添加tab处理 (#25) * 修复buffer在最后个字符cursor右移时崩溃的问题 (#27) * worksapce模式,支持查看工作区内容,动态打开工作区文件等操作 (#33) * 将共用结构体移动到held_core中,增加部分插件相关的interface (#34) - 增加插件系统 - 更改部分项目结构 * normal mode (#28) * normal mode * 实现了功能的自定义(除了delete_some) * 纠正default.yaml: 'G' -> 'shift-G' * 删除单词,移动到下一单词 * 移动undo, redo等到buffer模块 移动到前一单词,下一单词末尾 * CMD_COUNTER作为Application的成员变量 * Feat search (#32) * feat search * 修改default.yaml * 修改usize溢出bug,修改exec_search前后部分按键不能使用 --------- Co-authored-by: zhuweihao12138 <[email protected]> Co-authored-by: GnoCiYeH <[email protected]> * Feat Command (#29) * Add command mode * modified to resolve the conflict * get command mode modified * worksapce模式,支持查看工作区内容,动态打开工作区文件等操作 (#33) * 将共用结构体移动到held_core中,增加部分插件相关的interface (#34) - 增加插件系统 - 更改部分项目结构 --------- Co-authored-by: GnoCiYeH <[email protected]> * patch the error of command mode (#35) * feat-replace (#31) * 增加Replace模式 --------- Co-authored-by: sparkzky <[email protected]> Co-authored-by: GnoCiYeH <[email protected]> * Patch fix (#36) * patch the error of command mode * 进一步修复文件移动引起的错误 * 修改import, default.yaml --------- Co-authored-by: zhou <[email protected]> --------- Co-authored-by: Z YS <[email protected]> Co-authored-by: sparkzky <[email protected]> Co-authored-by: sparkzky <[email protected]> Co-authored-by: Weihao Zhu <[email protected]> Co-authored-by: zhuweihao12138 <[email protected]> Co-authored-by: laokengwt <[email protected]> Co-authored-by: 火花 <[email protected]> Co-authored-by: zhou <[email protected]>
1 parent c2100e2 commit 5d785d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

102 files changed

+8822
-107
lines changed

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

8+
[workspace]
9+
members = ["held_core", "test/test_render_plugin"]
10+
811
[features]
912
dragonos = []
1013

@@ -26,3 +29,20 @@ serde_yaml = "0.9"
2629

2730
# 定义标志位
2831
bitflags = "2.4.2"
32+
33+
walkdir = "2.5.0"
34+
35+
held_core = { path = "./held_core" }
36+
unicode-segmentation = "1.12.0"
37+
syntect = "5.2.0"
38+
error-chain = "0.12.4"
39+
yaml-rust = "0.4.5"
40+
app_dirs2 = "2.5.5"
41+
linked-hash-map = "0.5.6"
42+
strum = { version = "^0.26.3", features = ["std","derive"] }
43+
smallvec = "1.13.2"
44+
dlopen2 = "0.7.0"
45+
46+
[build-dependencies]
47+
regex = "1.10"
48+

build.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
use std::{
2+
env,
3+
fs::{read_dir, read_to_string, File},
4+
io::Write,
5+
path::PathBuf,
6+
};
7+
8+
use regex::Regex;
9+
10+
const COMMAND_REGEX: &str = r"pub fn (.*)\(app: &mut Application\) -> Result<\(\)>";
11+
12+
fn main() {
13+
generate_handler();
14+
}
15+
16+
fn generate_handler() {
17+
let out_dir = env::var("OUT_DIR").unwrap();
18+
let out_file_pathbuf = PathBuf::new().join(out_dir).join("handle_map");
19+
20+
let mut out_file = File::create(out_file_pathbuf).unwrap();
21+
out_file
22+
.write(
23+
r"{
24+
let mut handles: HashMap<&'static str, fn(&mut Application) -> Result<()>> = HashMap::new();
25+
"
26+
.as_bytes(),
27+
)
28+
.unwrap();
29+
30+
let expression = Regex::new(COMMAND_REGEX).expect("Failed to compile command matching regex");
31+
let readdir = read_dir("./src/application/handler/").unwrap();
32+
33+
for entry in readdir {
34+
if let Ok(entry) = entry {
35+
let path = entry.path();
36+
let module_name = entry
37+
.file_name()
38+
.into_string()
39+
.unwrap()
40+
.split('.')
41+
.next()
42+
.unwrap()
43+
.to_owned();
44+
45+
let content = read_to_string(path).unwrap();
46+
for captures in expression.captures_iter(&content) {
47+
let function_name = captures.get(1).unwrap().as_str();
48+
write(&mut out_file, &module_name, function_name);
49+
}
50+
}
51+
}
52+
53+
out_file
54+
.write(
55+
r"
56+
handles
57+
}"
58+
.as_bytes(),
59+
)
60+
.unwrap();
61+
}
62+
63+
fn write(output: &mut File, module_name: &str, function_name: &str) {
64+
output
65+
.write(
66+
format!(
67+
" handles.insert(\"{}::{}\", {}::{});\n",
68+
module_name, function_name, module_name, function_name
69+
)
70+
.as_bytes(),
71+
)
72+
.unwrap();
73+
}

held_core/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "held_core"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
crossterm = "0.27"

held_core/src/control.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

held_core/src/interface/app.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use super::{get_application, APPLICATION};
2+
3+
pub trait App {
4+
fn exit(&mut self);
5+
6+
fn to_insert_mode(&mut self);
7+
8+
fn to_normal_mode(&mut self);
9+
}
10+
11+
pub fn exit() {
12+
get_application().exit();
13+
}
14+
15+
pub fn to_insert_mode() {
16+
get_application().to_insert_mode();
17+
}
18+
19+
pub fn to_normal_mode() {
20+
get_application().to_normal_mode();
21+
}

held_core/src/interface/buffer.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pub trait Buffer {
2+
fn insert_char(&mut self);
3+
4+
fn new_line(&mut self);
5+
6+
fn insert_tab(&mut self);
7+
}

held_core/src/interface/cursor.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use crate::utils::position::Position;
2+
3+
use super::get_application;
4+
5+
pub trait Cursor {
6+
fn move_left(&mut self);
7+
8+
fn move_right(&mut self);
9+
10+
fn move_up(&mut self);
11+
12+
fn move_down(&mut self);
13+
14+
fn move_to_start_of_line(&mut self);
15+
16+
fn screen_cursor_position(&self) -> Position;
17+
}
18+
19+
pub fn screen_cursor_position() -> Position {
20+
get_application().screen_cursor_position()
21+
}
22+
23+
pub fn move_down() {
24+
get_application().move_down()
25+
}
26+
27+
pub fn move_up() {
28+
get_application().move_up()
29+
}
30+
31+
pub fn move_left() {
32+
get_application().move_left()
33+
}
34+
35+
pub fn move_right() {
36+
get_application().move_right()
37+
}
38+
39+
pub fn move_to_start_of_line() {
40+
get_application().move_to_start_of_line()
41+
}

held_core/src/interface/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use app::App;
2+
use buffer::Buffer;
3+
use cursor::Cursor;
4+
use monitor::Monitor;
5+
use workspace::Workspace;
6+
7+
pub mod app;
8+
pub mod buffer;
9+
pub mod cursor;
10+
pub mod monitor;
11+
pub mod render;
12+
pub mod terminal;
13+
pub mod workspace;
14+
15+
pub trait ApplicationInterface: App + Buffer + Cursor + Monitor + Workspace {}
16+
pub static mut APPLICATION: Option<&'static mut dyn ApplicationInterface> = None;
17+
18+
pub(crate) fn get_application() -> &'static mut &'static mut dyn ApplicationInterface {
19+
unsafe {
20+
APPLICATION
21+
.as_mut()
22+
.expect("The application has not been initialized!")
23+
}
24+
}

held_core/src/interface/monitor.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub trait Monitor {
2+
fn scroll_to_cursor(&mut self);
3+
4+
fn scroll_to_center(&mut self);
5+
}

held_core/src/interface/render.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)