Skip to content

Commit c775ed9

Browse files
sparkzkyGnoCiYeH
andauthored
解决退出程序后终端颜色的问题以及修复move_left的代码 (#13)
* 解决退出程序后终端颜色的问题以及修复move_left的代码 --------- Co-authored-by: GnoCiYeH <[email protected]>
1 parent 7d5806d commit c775ed9

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/utils/cursor.rs

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,20 +265,30 @@ impl CursorCrtl {
265265
}
266266

267267
pub fn move_left(&mut self, count: u16) -> io::Result<()> {
268-
let result = match self.x {
269-
x if x == 0 => Ok(()),
270-
x if x < count => self.move_to_columu(0),
271-
x => match self.prefix_mode {
272-
true if x == self.line_prefix_width - 1 => Ok(()),
273-
true if x - count < self.line_prefix_width => self.move_to_columu(0),
274-
_ => {
275-
self.x -= count;
276-
self.move_to_columu(x - count)
277-
}
278-
},
268+
// 如果当前光标位置小于或等于行前缀宽度,或者移动的距离大于当前光标位置,则直接移动到行前缀末尾
269+
if self.x <= self.line_prefix_width || count > self.x {
270+
return self.move_to_columu(0);
271+
}
272+
273+
// 如果启用了前缀模式且光标在前缀区域内,不进行移动
274+
if self.prefix_mode && self.x <= self.line_prefix_width {
275+
return Ok(());
276+
}
277+
278+
// 计算实际移动的距离
279+
let actual_move = if count > self.x - self.line_prefix_width {
280+
self.x - self.line_prefix_width
281+
} else {
282+
count
279283
};
280284

281-
result
285+
// 执行光标左移操作
286+
CursorManager::move_left(actual_move)?;
287+
288+
// 更新光标位置
289+
self.x -= actual_move;
290+
291+
Ok(())
282292
}
283293

284294
pub fn move_right(&mut self, count: u16) -> io::Result<()> {

src/utils/ui/uicore.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,9 @@ impl Ui {
385385

386386
fn ui_exit(&self) {
387387
// 处理未保存退出时的提醒
388+
389+
// 解决退出程序后颜色没改变的问题
390+
StyleManager::reset_color().unwrap();
388391
}
389392
}
390393

0 commit comments

Comments
 (0)