mirror of
https://github.com/ratatui-org/ratatui
synced 2024-11-22 04:33:13 +00:00
fix(text): remove trailing newline from single-line Display trait impl (#1320)
This commit is contained in:
parent
8b624f5952
commit
fdd5d8c092
1 changed files with 7 additions and 6 deletions
|
@ -633,7 +633,7 @@ impl<T: fmt::Display> ToText for T {
|
||||||
impl fmt::Display for Text<'_> {
|
impl fmt::Display for Text<'_> {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
for (position, line) in self.iter().with_position() {
|
for (position, line) in self.iter().with_position() {
|
||||||
if position == Position::Last {
|
if position == Position::Last || position == Position::Only {
|
||||||
write!(f, "{line}")?;
|
write!(f, "{line}")?;
|
||||||
} else {
|
} else {
|
||||||
writeln!(f, "{line}")?;
|
writeln!(f, "{line}")?;
|
||||||
|
@ -945,11 +945,12 @@ mod tests {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[rstest]
|
||||||
fn display_raw_text() {
|
#[case::one_line("The first line")]
|
||||||
let text = Text::raw("The first line\nThe second line");
|
#[case::multiple_lines("The first line\nThe second line")]
|
||||||
|
fn display_raw_text(#[case] value: &str) {
|
||||||
assert_eq!(format!("{text}"), "The first line\nThe second line");
|
let text = Text::raw(value);
|
||||||
|
assert_eq!(format!("{text}"), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue