Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyeventCallback除了input_data()都改为提供默认实现 #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
30 changes: 22 additions & 8 deletions src/utils/ui/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ use super::{
pub const TAB_STR: &'static str = " ";

pub trait KeyEventCallback {
fn enter(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType>;
fn tab(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType>;
fn enter(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType>{
// 默认实现
Ok(WarpUiCallBackType::ChangMode(ModeType::Normal))
}
fn tab(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType>{
// 默认实现
Ok(WarpUiCallBackType::ChangMode(ModeType::Normal))
}
fn backspace(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType> {
// 默认实现
if ui.cursor.x() == 0 {
let y = ui.cursor.y();
let (merged, linelen) = ui.buffer.merge_line(y);
Expand Down Expand Up @@ -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<UiCore>) -> io::Result<WarpUiCallBackType> {
// 默认实现
if ui.cursor.y() == 0 {
if ui.buffer.offset() == 0 {
// 上面没有数据
Expand Down Expand Up @@ -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<UiCore>) -> io::Result<WarpUiCallBackType> {
// 默认实现
let size = *CONTENT_WINSIZE.read().unwrap();
let mut linesize = ui.buffer.get_linesize(ui.cursor.y() + 1);

Expand Down Expand Up @@ -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<UiCore>) -> io::Result<WarpUiCallBackType> {
// 默认实现
ui.cursor.move_left(1)?;
Ok(WarpUiCallBackType::None)
Ok(WarpUiCallBackType::ChangMode(ModeType::Normal))
}
fn right(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType> {
// 默认实现
ui.cursor.move_right(1)?;
Ok(WarpUiCallBackType::None)
Ok(WarpUiCallBackType::ChangMode(ModeType::Normal))
}
fn esc(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType>{
// 默认实现
Ok(WarpUiCallBackType::ChangMode(ModeType::Normal))
}
fn esc(&self, ui: &mut MutexGuard<UiCore>) -> io::Result<WarpUiCallBackType>;
fn input_data(
&self,
ui: &mut MutexGuard<UiCore>,
Expand Down