From 0bbdc36d798f1e1bd287e55998899b67d0f4d1ad Mon Sep 17 00:00:00 2001 From: Baiye <17881468910@163.com> Date: Mon, 23 Sep 2024 10:28:57 +0000 Subject: [PATCH] =?UTF-8?q?KeyeventCallback=E9=99=A4=E4=BA=86input=5Fdata(?= =?UTF-8?q?)=E9=83=BD=E6=94=B9=E4=B8=BA=E6=8F=90=E4=BE=9B=E9=BB=98?= =?UTF-8?q?=E8=AE=A4=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/ui/event.rs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/utils/ui/event.rs b/src/utils/ui/event.rs index b223065..8e728fc 100644 --- a/src/utils/ui/event.rs +++ b/src/utils/ui/event.rs @@ -10,9 +10,16 @@ use super::{ pub const TAB_STR: &'static str = " "; pub trait KeyEventCallback { - fn enter(&self, ui: &mut MutexGuard) -> io::Result; - fn tab(&self, ui: &mut MutexGuard) -> io::Result; + fn enter(&self, ui: &mut MutexGuard) -> io::Result{ + // 默认实现 + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) + } + fn tab(&self, ui: &mut MutexGuard) -> io::Result{ + // 默认实现 + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) + } fn backspace(&self, ui: &mut MutexGuard) -> io::Result { + // 默认实现 if ui.cursor.x() == 0 { let y = ui.cursor.y(); let (merged, linelen) = ui.buffer.merge_line(y); @@ -80,9 +87,10 @@ pub trait KeyEventCallback { ui.cursor.move_to_columu(x - 1)?; - Ok(WarpUiCallBackType::None) + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) } fn up(&self, ui: &mut MutexGuard) -> io::Result { + // 默认实现 if ui.cursor.y() == 0 { if ui.buffer.offset() == 0 { // 上面没有数据 @@ -115,9 +123,10 @@ pub trait KeyEventCallback { let last_y = ui.cursor.y() + 1; ui.cursor.highlight(Some(last_y))?; - Ok(WarpUiCallBackType::None) + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) } fn down(&self, ui: &mut MutexGuard) -> io::Result { + // 默认实现 let size = *CONTENT_WINSIZE.read().unwrap(); let mut linesize = ui.buffer.get_linesize(ui.cursor.y() + 1); @@ -145,17 +154,22 @@ pub trait KeyEventCallback { let last_y = ui.cursor.y() - 1; ui.cursor.highlight(Some(last_y))?; - Ok(WarpUiCallBackType::None) + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) } fn left(&self, ui: &mut MutexGuard) -> io::Result { + // 默认实现 ui.cursor.move_left(1)?; - Ok(WarpUiCallBackType::None) + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) } fn right(&self, ui: &mut MutexGuard) -> io::Result { + // 默认实现 ui.cursor.move_right(1)?; - Ok(WarpUiCallBackType::None) + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) + } + fn esc(&self, ui: &mut MutexGuard) -> io::Result{ + // 默认实现 + Ok(WarpUiCallBackType::ChangMode(ModeType::Normal)) } - fn esc(&self, ui: &mut MutexGuard) -> io::Result; fn input_data( &self, ui: &mut MutexGuard,