Commits

Anonymous committed f27bb1a

rough fancy lineup stuff, no way to specify margin yet, so it's set for my setup

  • Participants
  • Parent commits e31d01d

Comments (0)

Files changed (1)

 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 #include <sys/ioctl.h>
 
 FILE *in, *out;
 char buf[4096];
+struct winsize ws;
+int margin = 30;
+
+void print_line(char *line)
+{
+	int len = strlen(line);
+	int i, cols = ws.ws_col;
+
+	if (line[len - 1] == '\n')
+		line[--len] = '\0';
+
+	printf("%-*.*s\n", cols, cols, line);
+
+	for (i = cols; i < len; i += cols)
+		printf("%*s| %-*.*s\n", margin - 2, "", cols - margin, cols - margin, line + i);
+}
 
 void sigwinch(int unused)
 {
 	rewind(in);
 
+	if (ioctl(STDOUT, TIOCGWINSZ, &ws) < 0)
+		err(1, "failed ioctl");
+
 	while (fgets(buf, sizeof(buf), in))
-		fputs(buf, stdout);
+		print_line(buf);
 	fflush(stdout);
 }
 
 	if ((in_wd = inotify_add_watch(evq, argv[1], IN_MODIFY)) < 0)
 		err(1, "failed inotify_add_watch()");
 
-	while (fgets(buf, sizeof(buf), in))
-		fputs(buf, stdout);
-	fflush(stdout);
+	sigwinch(0); // set winsize and print what we start with
 
 	if ((out = fopen(argv[2], "w")) == NULL)
 		err(1, "failed to fopen %s", argv[2]);
 				err(1, "failed read() on evq");
 
 			while (fgets(buf, sizeof(buf), in))
-				fputs(buf, stdout);
+				print_line(buf);
 			fflush(stdout);
 		}
 		if (FD_ISSET(fileno(stdin), &rd)) {