[hackers] [scroll][PATCH] hotkey to dump buffer to file (like screen hardcopy)

From: Kaspars Vandans <kaspars.vandans_AT_gmail.com>
Date: Sat, 6 Dec 2025 15:08:31 +0200

From: kaspars <kaspars.vandans_AT_gmail.com>

---
 TODO         |  1 -
 config.def.h |  4 ++++
 scroll.c     | 25 ++++++++++++++++++++++++-
 3 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/TODO b/TODO
index 84ffd33..dff0ea6 100644
--- a/TODO
+++ b/TODO
_AT_@ -1,3 +1,2 @@
  * strlen function which is aware of unicode
  * handle wrapping lines in scrolling line count correctly
- * hotkey to dump buffer to file (like screen hardcopy)
diff --git a/config.def.h b/config.def.h
index 536db70..7d961d5 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -13,4 +13,8 @@ struct rule rules[] = {
 	/* mouse binding shadows ^E and ^Y, so it's disabled by default */
 	//{"\031",        SCROLL_UP,    1},	/* mouse wheel up */
 	//{"\005",        SCROLL_DOWN,  1},	/* mouse wheel Down */
+	/* an ok UX requires ansifilter, so it's disabled by default*/
+	//{"\033v",       PIPE_OUTSIDE, 0},	/* [Alt]   + v ; lines ignored */
 };
+
+const char pipecmd[] = "ansifilter > scroll_output.txt";
diff --git a/scroll.c b/scroll.c
index 8f66d54..7892a88 100644
--- a/scroll.c
+++ b/scroll.c
_AT_@ -54,7 +54,7 @@ static bool doredraw = false;	/* redraw upon sigwinch */
 
 struct rule {
 	const char *seq;
-	enum {SCROLL_UP, SCROLL_DOWN} event;
+	enum {SCROLL_UP, SCROLL_DOWN, PIPE_OUTSIDE} event;
 	short lines;
 };
 
_AT_@ -389,6 +389,27 @@ jumpdown(char *buf, size_t size)
 	scrolldown(buf, size, ws.ws_row);
 }
 
+void 
+pipeoutside(void)
+{
+	FILE *pipe;
+	struct line *current;
+
+	pipe = popen(pipecmd, "w");
+	if (!pipe) {
+		perror("popen");
+		return;
+	}
+
+	current = TAILQ_LAST(&head, tailhead);
+	while (current != NULL) {
+		fwrite(current->buf, 1, current->size, pipe);
+		current = TAILQ_PREV(current, tailhead, entries);
+	}
+
+	pclose(pipe);
+}
+
 void
 usage(void) {
 	die("usage: %s [-Mvh] [-m mem] [program]", argv0);
_AT_@ -523,6 +544,8 @@ main(int argc, char *argv[])
 					if (rules[i].event == SCROLL_DOWN)
 						scrolldown(buf, len,
 						    rules[i].lines);
+					if (rules[i].event == PIPE_OUTSIDE)
+						pipeoutside();
 					goto out;
 				}
 			}
-- 
2.51.2
Received on Sat Dec 06 2025 - 14:08:31 CET

This archive was generated by hypermail 2.3.0 : Sat Dec 06 2025 - 17:24:35 CET