ref: 37318361be56ff0c858aacadb7ab2a7587f9dd79
parent: e52c3b4a5ba1574b1ff65e134fb9118fe2a86bba
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jul 12 15:11:43 EDT 2023
vt: bracketed paste mode (fixes autoindentation in text editors)
--- a/sys/src/cmd/vt/cons.h
+++ b/sys/src/cmd/vt/cons.h
@@ -75,6 +75,7 @@
extern int cursoron;
extern int nocolor;
+extern int bracketed;
extern void setdim(int, int);
extern void mountcons(void);
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -655,6 +655,7 @@
input(void)
{
static char echobuf[4*BSIZE];
+ static int pasting;
Again:
if(resize_flag)
@@ -664,9 +665,17 @@
if(snarffp) {
int c;
+ if(bracketed && !pasting){
+ sendnchars(6, "\033[200~");
+ pasting = 1;
+ }
if((c = Bgetrune(snarffp)) < 0) {
Bterm(snarffp);
snarffp = nil;
+ if(bracketed){
+ sendnchars(6, "\033[201~");
+ pasting = 0;
+ }
goto Again;
}
kbdchar = c;
--- a/sys/src/cmd/vt/vt.c
+++ b/sys/src/cmd/vt/vt.c
@@ -30,6 +30,7 @@
int wraparound = 1;
int originrelative = 0;
+int bracketed = 0;
int tabcol[200];
char osc7cwd[WDIR];
@@ -492,6 +493,9 @@
case 25: /* text cursor off (VT220) */
cursoron = 0;
break;
+ case 2004: /* bracketed paste mode off */
+ bracketed = 0;
+ break;
}
}
break;
@@ -546,6 +550,9 @@
break;
case 25: /* text cursor on (VT220) */
cursoron = 1;
+ break;
+ case 2004: /* bracketed paste mode on */
+ bracketed = 1;
break;
}
}