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

解决退出程序后终端颜色的问题以及修复move_left的代码 #13

Merged
merged 12 commits into from
Aug 6, 2024
34 changes: 22 additions & 12 deletions src/utils/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,20 +265,30 @@ impl CursorCrtl {
}

pub fn move_left(&mut self, count: u16) -> io::Result<()> {
let result = match self.x {
x if x == 0 => Ok(()),
x if x < count => self.move_to_columu(0),
x => match self.prefix_mode {
true if x == self.line_prefix_width - 1 => Ok(()),
true if x - count < self.line_prefix_width => self.move_to_columu(0),
_ => {
self.x -= count;
self.move_to_columu(x - count)
}
},
// 如果当前光标位置小于或等于行前缀宽度,或者移动的距离大于当前光标位置,则直接移动到行前缀末尾
if self.x <= self.line_prefix_width || count > self.x {
return self.move_to_columu(0);
}

// 如果启用了前缀模式且光标在前缀区域内,不进行移动
if self.prefix_mode && self.x <= self.line_prefix_width {
return Ok(());
}

// 计算实际移动的距离
let actual_move = if count > self.x - self.line_prefix_width {
self.x - self.line_prefix_width
} else {
count
};

result
// 执行光标左移操作
CursorManager::move_left(actual_move)?;

// 更新光标位置
self.x -= actual_move;

Ok(())
}

pub fn move_right(&mut self, count: u16) -> io::Result<()> {
Expand Down
3 changes: 3 additions & 0 deletions src/utils/ui/uicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ impl Ui {

fn ui_exit(&self) {
// 处理未保存退出时的提醒

// 解决退出程序后颜色没改变的问题
StyleManager::reset_color().unwrap();
}
}

Expand Down
Loading