shithub: orca

Download patch

ref: a79389ebf6faa1d0491d6ab188238cb28ab52511
parent: 77ce393e2625c2745feb4d04eb331ff9f29dea66
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Feb 21 12:05:17 EST 2020

plan9: add "print" command to print selected rectange

--- a/orca.man
+++ b/orca.man
@@ -180,14 +180,20 @@
 .TP
 .B rewind NUMBER
 Decrease frame value.
+.TP
+.B print
+Print selected rectangle to
+.I stdout .
 .PP
 .I Orca
-treats stdin as a stream of commands, you can run it like so:
+treats
+.I stdin
+as a stream of commands, you can run it like so:
 .EX
 aux/listen1 -t tcp!127.0.0.1!49161 games/orca
 .EE
 .PP
-Then start the following command in a separate "command" window:
+Then start the following in a separate "command" window:
 .EX
 telnet tcp!127.0.0.1!49161
 .EE
--- a/plan9.c
+++ b/plan9.c
@@ -259,7 +259,7 @@
 command(char *s)
 {
 	char *a;
-	int x;
+	int x, y;
 
 	if (s[0] == ',') {
 		cur = ZP;
@@ -281,7 +281,14 @@
 		pause = true;
 	else if (strcmp(s, "run") == 0)
 		forward = true;
-	else if (a != nil) {
+	else if (strcmp(s, "print") == 0) {
+		for (y = sel.min.y; y <= sel.max.y; y++) {
+			for (x = sel.min.x; x <= sel.max.x; x++)
+				putchar(field.buffer[x + y*field.width]);
+			putchar('\n');
+		}
+		fflush(stdout);
+	} else if (a != nil) {
 		x = atoi(a);
 
 		if (strcmp(s, "bpm") == 0)
@@ -819,6 +826,7 @@
 	for (;;) {
 		if ((n = read(0, buf, sizeof(buf)-1)) <= 0)
 			break;
+
 		for (i = 0; i < n; i++) {
 			if (buf[i] == '\r' || buf[i] == '\n' || buf[i] == 0) {
 				buf[i] = 0;