summaryrefslogtreecommitdiff
path: root/Userland/more.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/more.cpp')
-rw-r--r--Userland/more.cpp47
1 files changed, 47 insertions, 0 deletions
diff --git a/Userland/more.cpp b/Userland/more.cpp
new file mode 100644
index 0000000000..d0050c6b9d
--- /dev/null
+++ b/Userland/more.cpp
@@ -0,0 +1,47 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/ioctl.h>
+
+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)
+{
+ (void) argc;
+ (void) argv;
+
+ 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;
+ printf(str);
+ ++lines_printed;
+ if ((lines_printed % (ws.ws_row - 1)) == 0) {
+ wait_for_key();
+ }
+
+ }
+
+ close(key_fd);
+ return 0;
+}