Skip to content

Commit

Permalink
解决退出程序后终端颜色的问题以及修复move_left的代码 (#13)
Browse files Browse the repository at this point in the history
* 解决退出程序后终端颜色的问题以及修复move_left的代码

---------

Co-authored-by: GnoCiYeH <[email protected]>
  • Loading branch information
sparkzky and GnoCiYeH authored Aug 6, 2024
1 parent 7d5806d commit c775ed9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
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

0 comments on commit c775ed9

Please sign in to comment.