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

Fix missing newlines at end of prompts #234

Merged
merged 2 commits into from
Mar 17, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

## [Unreleased] <!-- ReleaseDate -->

- Pressing Ctrl+D now cancels the prompt.
- Add support for `h` and `l` bindings when vim_mode is enabled on MultiSelect prompts, clearing or selecting all options respectively.
- Pressing Ctrl+D now cancels the prompt. Thanks @mikecvet for the PR!
- Add support for `h` and `l` bindings when vim_mode is enabled on MultiSelect prompts, clearing or selecting all options respectively. Thanks @afh for the PR!
- Fix render issue [#233](https://github.com/mikaelmello/inquire/issues/233) where cursor positioning at the end of a prompt was incorrect. Thanks @msrd0 and @Sydonian for reporting!

## [0.7.1] - 2024-03-10

Expand Down
6 changes: 3 additions & 3 deletions inquire/src/prompts/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ where
if last_handle.needs_redraw() {
backend.frame_setup()?;
self.render(backend)?;
backend.frame_finish()?;
backend.frame_finish(false)?;
last_handle = ActionResult::Clean;
}

Expand All @@ -144,7 +144,7 @@ where
if pre_cancel_result {
backend.frame_setup()?;
backend.render_canceled_prompt(self.message())?;
backend.frame_finish()?;
backend.frame_finish(true)?;
return Err(InquireError::OperationCanceled);
}

Expand All @@ -160,7 +160,7 @@ where

backend.frame_setup()?;
backend.render_prompt_with_answer(self.message(), &formatted)?;
backend.frame_finish()?;
backend.frame_finish(true)?;

Ok(final_answer)
}
Expand Down
13 changes: 9 additions & 4 deletions inquire/src/ui/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{frame_renderer::FrameRenderer, InputReader};

pub trait CommonBackend: InputReader {
fn frame_setup(&mut self) -> Result<()>;
fn frame_finish(&mut self) -> Result<()>;
fn frame_finish(&mut self, is_last_frame: bool) -> Result<()>;

fn render_canceled_prompt(&mut self, prompt: &str) -> Result<()>;
fn render_prompt_with_answer(&mut self, prompt: &str, answer: &str) -> Result<()>;
Expand Down Expand Up @@ -247,8 +247,8 @@ where
self.frame_renderer.start_frame()
}

fn frame_finish(&mut self) -> Result<()> {
self.frame_renderer.finish_current_frame()
fn frame_finish(&mut self, is_last_frame: bool) -> Result<()> {
self.frame_renderer.finish_current_frame(is_last_frame)
}

fn render_canceled_prompt(&mut self, prompt: &str) -> Result<()> {
Expand Down Expand Up @@ -689,6 +689,7 @@ pub(crate) mod test {
min_date: Option<NaiveDate>,
max_date: Option<NaiveDate>,
},
PromptEnd,
}

#[derive(Default, Debug, Clone)]
Expand Down Expand Up @@ -751,7 +752,11 @@ pub(crate) mod test {
Ok(())
}

fn frame_finish(&mut self) -> std::io::Result<()> {
fn frame_finish(&mut self, is_last_frame: bool) -> std::io::Result<()> {
if is_last_frame {
self.push_token(Token::PromptEnd);
}

if let Some(frame) = self.cur_frame.take() {
self.frames.push(frame);
} else {
Expand Down
9 changes: 7 additions & 2 deletions inquire/src/ui/frame_renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ where
Ok(())
}

pub fn finish_current_frame(&mut self) -> io::Result<()> {
pub fn finish_current_frame(&mut self, add_empty_line: bool) -> io::Result<()> {
let (last_rendered_frame, mut current_frame) = match std::mem::take(&mut self.state) {
RenderState::Rendered(_) | RenderState::Initial => {
return Ok(());
Expand All @@ -280,7 +280,7 @@ where
current_frame.frame_size.height(),
);

self.terminal.cursor_hide()?;
//self.terminal.cursor_hide()?;
self.move_cursor_to(Position { row: 0, col: 0 })?;

for i in 0..rows_to_iterate {
Expand Down Expand Up @@ -321,6 +321,11 @@ where
}
}

if add_empty_line {
self.terminal.write("\n")?;
self.cursor_position.row += 1;
}

if let Some(expected_cursor_position) = current_frame.expected_cursor_position {
self.move_cursor_to(expected_cursor_position)?;
}
Expand Down
Loading