while (nrows < maxrows && off < buf_end(&(view->buffer))) {
Rune rune = buf_getrat(&(view->buffer), off);
xpos += rune_width(rune, xpos, view->width);
- if (rune == '\n') {
+ /* if the line is full, reset the line and increase row count */
+ if (xpos > view->width) {
xpos = 0, nrows++;
- off = buf_byrune(&(view->buffer), off, RIGHT);
} else {
- if (xpos <= view->width)
- off = buf_byrune(&(view->buffer), off, RIGHT);
- else
+ if (rune == '\n')
xpos = 0, nrows++;
+ off = buf_byrune(&(view->buffer), off, RIGHT);
}
}
- printf("rows: %lu\n", nrows);
return nrows;
}