Fix bad TextView layout

This commit is contained in:
Alexandre Bury 2015-05-25 01:30:18 -07:00
parent 9ffcaef7ab
commit 222c4465d9
2 changed files with 4 additions and 4 deletions

View File

@ -21,7 +21,7 @@ fn main() {
// and will adapt to the terminal size.
siv.add_layer(TextView::new(&content));
// Show a popup on top of the view.
siv.add_layer(Dialog::new(TextView::new("Try resizing the terminal!\n(Press 'q' to quit when you're done)"))
siv.add_layer(Dialog::new(TextView::new("Try resizing the terminal!\n(Press 'q' to quit when you're done.)"))
.dismiss_button("Ok"));
siv.run();

View File

@ -36,7 +36,7 @@ fn get_line_span(line: &str, max_width: usize) -> usize {
let mut length = 0;
for l in line.split(" ").map(|word| word.len()) {
length += l;
if length >= max_width {
if length > max_width {
length = l;
lines += 1;
}
@ -129,7 +129,7 @@ impl <'a> Iterator for LinesIterator<'a> {
let content = &self.content[self.start..];
if let Some(next) = content.find("\n") {
if next < self.width {
if next <= self.width {
// We found a newline before the allowed limit.
// Break early.
self.start += next+1;
@ -149,7 +149,7 @@ impl <'a> Iterator for LinesIterator<'a> {
});
}
if let Some(i) = content[..self.width].rfind(" ") {
if let Some(i) = content[..self.width+1].rfind(" ") {
// If we have to break, try to find a whitespace for that.
self.start += i+1;
return Some(Row {