[widgets][paragraph]: Truncate long lines when wrap is false

pull/80/merge
Karoline Pauls 6 years ago committed by Florian Dehau
parent 56fc43400a
commit 03bfcde147

@ -51,6 +51,10 @@ fn main() -> Result<(), failure::Error> {
app.size = size;
}
let mut long_line: String = std::iter::repeat('X').take(size.width.into()).collect();
long_line.insert_str(0, "Very long line: ");
long_line.push('\n');
terminal.draw(|mut f| {
Block::default()
.style(Style::default().bg(Color::White))
@ -76,6 +80,7 @@ fn main() -> Result<(), failure::Error> {
"This a longer line\n",
Style::default().modifier(Modifier::CrossedOut),
),
Text::raw(&long_line),
Text::styled(
"This a line\n",
Style::default().fg(Color::Green).modifier(Modifier::Italic),

@ -166,19 +166,23 @@ where
y += 1;
continue;
}
if x >= text_area.width && self.wrapping {
x = match self.alignment {
Alignment::Center => {
(text_area.width / 2).saturating_sub(get_cur_line_len(&mut styled) / 2)
}
Alignment::Right => {
(text_area.width).saturating_sub(get_cur_line_len(&mut styled) + 1)
}
Alignment::Left => 0,
};
y += 1;
remove_leading_whitespaces = true
if x >= text_area.width {
if !self.wrapping {
continue; // Truncate the remainder of the line.
} else {
x = match self.alignment {
Alignment::Center => {
(text_area.width / 2).saturating_sub(get_cur_line_len(&mut styled) / 2)
}
Alignment::Right => {
(text_area.width).saturating_sub(get_cur_line_len(&mut styled) + 1)
}
Alignment::Left => 0,
};
y += 1;
remove_leading_whitespaces = true
}
}
if remove_leading_whitespaces && string == " " {

Loading…
Cancel
Save