Skip to content

Commit

Permalink
limit lines to screen width
Browse files Browse the repository at this point in the history
  • Loading branch information
codekitchen committed Nov 23, 2019
1 parent 1100609 commit bbcef19
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ void read_show_output(FILE *s, size_t *shown, size_t *total) {
if (read < 0)
break;
if (*shown < LINES - 2) {
fputs(line, stdout); // TODO: truncate long lines
// sometimes newline, sometimes not, so chomp off any newline and
// we'll add it ourselves for consistency.
if (line[read-1] == '\n')
read -= 1;
// truncate lines that are wider than the screen.
if (read > COLS)
read = COLS;
printf("%.*s\n", (int)read, line);
*shown += 1;
}
*total += 1;
Expand Down

0 comments on commit bbcef19

Please sign in to comment.