ref: ffb712a9f80886bf9b80f851b894dacf1a294b39
parent: 969f5bea56cff8f903f4535114b28ce2dc25d31b
author: Sigrid Haflínudóttir <ftrvxmtrx@gmail.com>
date: Sat Feb 22 07:16:06 EST 2020
plan9: add copy/paste/erase commands
--- a/orca.man
+++ b/orca.man
@@ -173,6 +173,15 @@
.B run
Forward one frame.
.TP
+.B copy
+Copy the selection to the snarf buffer.
+.TP
+.B paste
+Paste from the snarf buffer.
+.TP
+.B erase
+Erase the selected cells.
+.TP
.B bpm NUMBER
Set new BPM value.
.TP
@@ -194,7 +203,6 @@
.B udp NUMBER
Set UDP destination port.
.TP
-.TP
.B midi PATH
Set MIDI output path.
.B print
@@ -213,5 +221,6 @@
.EX
telnet tcp!127.0.0.1!49161
.EE
+.PP
.SH SOURCE
https://github.com/hundredrabbits/Orca
--- a/plan9.c
+++ b/plan9.c
@@ -185,6 +185,22 @@
}
static void
+fieldset(int x, int y, Glyph c)
+{
+ if (x < field.width && y < field.height && x >= 0 && y >= 0)
+ field.buffer[x + field.width*y] = c;
+}
+
+static void
+fieldsetn(int x, int y, Glyph c, int n)
+{
+ if (y >= 0 && y < field.height) {
+ for (; n > 0 && x < field.width; n--, x++)
+ field.buffer[x + field.width*y] = c;
+ }
+}
+
+static void
selpasteb(Biobuf *b)
{
char *s;
@@ -289,6 +305,56 @@
}
static void
+selset(Rune key)
+{
+ int y;
+ bool commented;
+
+ if (key == '#') {
+ commented = true;
+ for (y = sel.min.y; y <= sel.max.y && commented; y++)
+ commented = fieldget(sel.min.x, y) == key && fieldget(sel.max.x, y) == key;
+ if (commented)
+ key = '.';
+ } else {
+ commented = false;
+ }
+
+ for (y = sel.min.y; y <= sel.max.y; y++) {
+ if (key == '#' || commented) {
+ fieldset(sel.min.x, y, key);
+ fieldset(sel.max.x, y, key);
+ } else {
+ fieldsetn(sel.min.x, y, key, Dx(sel)+1);
+ }
+ }
+}
+
+static void
+selcopy(void)
+{
+ Biobuf *b;
+ int y;
+
+ if ((b = Bopen("/dev/snarf", OWRITE)) != nil) {
+ for (y = sel.min.y; y <= sel.max.y; y++) {
+ Bwrite(b, &field.buffer[sel.min.x + field.width*y], Dx(sel)+1);
+ Bputc(b, '\n');
+ }
+ Bterm(b);
+ }
+}
+
+static void
+selpaste(void)
+{
+ Biobuf *b;
+
+ if ((b = Bopen("/dev/snarf", OREAD)) != nil)
+ selpasteb(b);
+}
+
+static void
command(char *s)
{
char *a;
@@ -314,6 +380,12 @@
pause = true;
else if (strcmp(s, "run") == 0)
forward = true;
+ else if (strcmp(s, "copy") == 0)
+ selcopy();
+ else if (strcmp(s, "paste") == 0)
+ selpaste();
+ else if (strcmp(s, "erase") == 0)
+ selset('.');
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++)
@@ -719,72 +791,6 @@
field_fput(&field, f);
fclose(f);
return 0;
-}
-
-static void
-fieldset(int x, int y, Glyph c)
-{
- if (x < field.width && y < field.height && x >= 0 && y >= 0)
- field.buffer[x + field.width*y] = c;
-}
-
-static void
-fieldsetn(int x, int y, Glyph c, int n)
-{
- if (y >= 0 && y < field.height) {
- for (; n > 0 && x < field.width; n--, x++)
- field.buffer[x + field.width*y] = c;
- }
-}
-
-static void
-selset(Rune key)
-{
- int y;
- bool commented;
-
- if (key == '#') {
- commented = true;
- for (y = sel.min.y; y <= sel.max.y && commented; y++)
- commented = fieldget(sel.min.x, y) == key && fieldget(sel.max.x, y) == key;
- if (commented)
- key = '.';
- } else {
- commented = false;
- }
-
- for (y = sel.min.y; y <= sel.max.y; y++) {
- if (key == '#' || commented) {
- fieldset(sel.min.x, y, key);
- fieldset(sel.max.x, y, key);
- } else {
- fieldsetn(sel.min.x, y, key, Dx(sel)+1);
- }
- }
-}
-
-static void
-selcopy(void)
-{
- Biobuf *b;
- int y;
-
- if ((b = Bopen("/dev/snarf", OWRITE)) != nil) {
- for (y = sel.min.y; y <= sel.max.y; y++) {
- Bwrite(b, &field.buffer[sel.min.x + field.width*y], Dx(sel)+1);
- Bputc(b, '\n');
- }
- Bterm(b);
- }
-}
-
-static void
-selpaste(void)
-{
- Biobuf *b;
-
- if ((b = Bopen("/dev/snarf", OREAD)) != nil)
- selpasteb(b);
}
static Point