summary refs log tree commit diff
diff options
context:
space:
mode:
authorC. McEnroe2020-02-08 16:56:49 -0500
committerC. McEnroe2020-02-08 16:56:49 -0500
commit29bd788660af90855f6acce411506aeaf14f8808 (patch)
tree6ba640373cf860edc7f0019bd798857c908b78a9
parentb98c7d68630a7af37f61a52a555e1aaed1c2e7af (diff)
Simplify(?) reflow buffer loop
-rw-r--r--ui.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/ui.c b/ui.c
index c738617..29062be 100644
--- a/ui.c
+++ b/ui.c
@@ -459,10 +459,12 @@ void uiFormat(
 static void reflow(struct Window *window) {
 	werase(window->pad);
 	wmove(window->pad, BufferCap - 1, 0);
-	size_t len = window->buffer.len;
-	for (size_t i = (len > BufferCap ? len - BufferCap : 0); i < len; ++i) {
+	struct Buffer *buffer = &window->buffer;
+	for (size_t i = 0; i < BufferCap; ++i) {
+		char *line = buffer->lines[(buffer->len + i) % BufferCap];
+		if (!line) continue;
 		waddch(window->pad, '\n');
-		wordWrap(window->pad, window->buffer.lines[i % BufferCap]);
+		wordWrap(window->pad, line);
 	}
 }