2018-12-21 01:42:30 +00:00
|
|
|
#include <fcntl.h>
|
2019-06-07 09:49:31 +00:00
|
|
|
#include <stdio.h>
|
2018-12-21 01:42:30 +00:00
|
|
|
#include <sys/ioctl.h>
|
2019-06-07 09:49:31 +00:00
|
|
|
#include <unistd.h>
|
2018-12-21 01:42:30 +00:00
|
|
|
|
|
|
|
static int key_fd;
|
|
|
|
|
|
|
|
void wait_for_key()
|
|
|
|
{
|
|
|
|
printf("\033[7m--[ more ]--\033[0m");
|
|
|
|
fflush(stdout);
|
|
|
|
char dummy;
|
|
|
|
read(key_fd, &dummy, 1);
|
|
|
|
printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2019-06-07 09:49:31 +00:00
|
|
|
(void)argc;
|
|
|
|
(void)argv;
|
2018-12-21 01:42:30 +00:00
|
|
|
|
|
|
|
key_fd = open(ttyname(1), O_RDONLY);
|
|
|
|
if (key_fd < 0) {
|
|
|
|
perror("open");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct winsize ws;
|
|
|
|
ioctl(1, TIOCGWINSZ, &ws);
|
|
|
|
|
|
|
|
unsigned lines_printed = 0;
|
|
|
|
while (!feof(stdin)) {
|
|
|
|
char buffer[BUFSIZ];
|
|
|
|
auto* str = fgets(buffer, sizeof(buffer), stdin);
|
|
|
|
if (!str)
|
|
|
|
break;
|
2019-08-01 09:39:41 +00:00
|
|
|
printf("%s", str);
|
2018-12-21 01:42:30 +00:00
|
|
|
++lines_printed;
|
2019-06-07 09:49:31 +00:00
|
|
|
if ((lines_printed % (ws.ws_row - 1)) == 0) {
|
2018-12-21 01:42:30 +00:00
|
|
|
wait_for_key();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close(key_fd);
|
|
|
|
return 0;
|
|
|
|
}
|