Skip to content

Commit

Permalink
change cursor shape depending on edit mode (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
cschierig committed Oct 21, 2022
1 parent 8e1511a commit da27f00
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 14 additions & 4 deletions src/engine.rs
Expand Up @@ -1373,8 +1373,13 @@ impl Reedline {
"",
);

self.painter
.repaint_buffer(prompt, &lines, None, self.use_ansi_coloring)?;
self.painter.repaint_buffer(
prompt,
&lines,
self.prompt_edit_mode(),
None,
self.use_ansi_coloring,
)?;
}

Ok(())
Expand Down Expand Up @@ -1435,8 +1440,13 @@ impl Reedline {

let menu = self.menus.iter().find(|menu| menu.is_active());

self.painter
.repaint_buffer(prompt, &lines, menu, self.use_ansi_coloring)
self.painter.repaint_buffer(
prompt,
&lines,
self.prompt_edit_mode(),
menu,
self.use_ansi_coloring,
)
}

/// Adds an external printer
Expand Down
11 changes: 10 additions & 1 deletion src/painting/painter.rs
@@ -1,3 +1,5 @@
use crate::PromptEditMode;

use {
super::utils::{coerce_crlf, line_width},
crate::{
Expand Down Expand Up @@ -132,6 +134,7 @@ impl Painter {
&mut self,
prompt: &dyn Prompt,
lines: &PromptLines,
prompt_mode: PromptEditMode,
menu: Option<&ReedlineMenu>,
use_ansi_coloring: bool,
) -> Result<()> {
Expand Down Expand Up @@ -172,7 +175,13 @@ impl Painter {
// can print without overwriting the things written during the painting
self.last_required_lines = required_lines;

self.stdout.queue(RestorePosition)?.queue(cursor::Show)?;
self.stdout
.queue(RestorePosition)?
.queue(cursor::SetCursorShape(match prompt_mode {
PromptEditMode::Vi(crate::PromptViMode::Insert) => cursor::CursorShape::Line,
_ => cursor::CursorShape::Block,
}))?
.queue(cursor::Show)?;

self.stdout.flush()
}
Expand Down

0 comments on commit da27f00

Please sign in to comment.