Skip to content

Commit

Permalink
fix: input - always renders default prompt if inline (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
roele authored Jan 30, 2024
1 parent e035c07 commit 088e643
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl<'a> Input<'a> {

out.set_color(&self.theme.title)?;
match self.inline {
true => write!(out, "{}", self.title)?,
true => write!(out, " {}", self.title)?,
false => writeln!(out, " {}", self.title)?,
}

Expand All @@ -229,7 +229,7 @@ impl<'a> Input<'a> {
out.set_color(&self.theme.input_prompt)?;
if !self.prompt.is_empty() {
match self.inline {
true => write!(out, ">")?,
true => write!(out, "{}", self.prompt)?,
false => write!(out, " {}", self.prompt)?,
}
} else {
Expand Down Expand Up @@ -343,4 +343,18 @@ mod tests {
without_ansi(input.render().unwrap().as_str())
);
}

#[test]
fn test_render_inline() {
let mut input = Input::new("Title?")
.description("Description.")
.prompt("Prompt:")
.placeholder("Placeholder")
.inline(true);

assert_eq!(
" Title?Description.Prompt:Placeholder",
without_ansi(input.render().unwrap().as_str())
);
}
}

0 comments on commit 088e643

Please sign in to comment.