diff --git a/assets/lorem.txt b/assets/lorem.txt index 11cd169..b537917 100644 --- a/assets/lorem.txt +++ b/assets/lorem.txt @@ -7,5 +7,3 @@ Praesent iaculis enim id eros consectetur venenatis. Nunc malesuada faucibus luc Sed consectetur imperdiet augue et consectetur. Aliquam rhoncus nisl et mi lobortis ultricies. Fusce pretium mi nibh, in maximus nunc porta et. Morbi maximus elit vel egestas sagittis. Pellentesque egestas vehicula augue. Quisque ornare placerat ante, non vulputate nisl placerat commodo. Nam sit amet eros placerat, varius diam a, bibendum sem. Mauris orci leo, dapibus nec sapien eu, finibus hendrerit erat. Duis et neque diam. Vivamus nec ultrices ipsum. In hac habitasse platea dictumst. Fusce vel eros sit amet velit sollicitudin eleifend vitae et nunc. Donec elementum pharetra elit, quis finibus ante dictum et. Vivamus tristique dignissim nulla. Ut dignissim tincidunt elementum. Nullam pellentesque turpis sapien, iaculis sagittis arcu mollis nec. Pellentesque quis vehicula urna. Aenean pretium eget ex vitae interdum. Phasellus pharetra magna id vehicula cursus. Vivamus egestas id nulla et lacinia. Donec congue at eros volutpat tristique. Donec mi tortor, commodo a nisl sed, vulputate malesuada velit. Morbi sed sagittis odio. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Aenean lacinia auctor dapibus. Quisque sagittis odio vel urna laoreet ultrices. - - diff --git a/src/printer.rs b/src/printer.rs index 6811f6f..6c43998 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -24,7 +24,9 @@ impl Printer { /// Prints some text at the given position relative to the window. pub fn print(&self, pos: S, text: &str) { - let p = pos.to_vec2() + self.offset; + let mut p = pos.to_vec2(); + if p.y >= self.size.y { return; } + p = p + self.offset; ncurses::mvprintw(p.y as i32, p.x as i32, text); } diff --git a/src/view/text_view.rs b/src/view/text_view.rs index f86d28f..4aeed3d 100644 --- a/src/view/text_view.rs +++ b/src/view/text_view.rs @@ -17,10 +17,11 @@ 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; } + length += 1; } lines }