vt: block selection mode for snarf
This commit is contained in:
parent
797f85f023
commit
c4fd860a56
2 changed files with 38 additions and 12 deletions
|
@ -83,6 +83,9 @@ Enter raw (no echo, no interpretation) character mode for input.
|
||||||
.B cooked
|
.B cooked
|
||||||
Leave raw mode.
|
Leave raw mode.
|
||||||
.TP
|
.TP
|
||||||
|
.B blocksel
|
||||||
|
Toggle block selection for mode for rio snarf buffer.
|
||||||
|
.TP
|
||||||
.B exit
|
.B exit
|
||||||
Exit
|
Exit
|
||||||
.IR vt .
|
.IR vt .
|
||||||
|
|
|
@ -27,6 +27,7 @@ char *menutext3[] = {
|
||||||
"crnl",
|
"crnl",
|
||||||
"nl",
|
"nl",
|
||||||
"raw",
|
"raw",
|
||||||
|
"blocksel",
|
||||||
"exit",
|
"exit",
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
|
@ -44,6 +45,7 @@ int resize_flag = 1;
|
||||||
int pagemode;
|
int pagemode;
|
||||||
int olines;
|
int olines;
|
||||||
int peekc;
|
int peekc;
|
||||||
|
int blocksel = 0;
|
||||||
int cursoron = 1;
|
int cursoron = 1;
|
||||||
int hostclosed = 0;
|
int hostclosed = 0;
|
||||||
Menu menu2;
|
Menu menu2;
|
||||||
|
@ -867,17 +869,13 @@ sendsnarf(void)
|
||||||
snarffp = Bopen("/dev/snarf",OREAD);
|
snarffp = Bopen("/dev/snarf",OREAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
void
|
||||||
writesnarf(Rune *s, Rune *e)
|
seputrunes(Biobuf *b, Rune *s, Rune *e)
|
||||||
{
|
{
|
||||||
Biobuf *b;
|
|
||||||
int z, p;
|
int z, p;
|
||||||
|
|
||||||
if(s >= e)
|
if(s >= e)
|
||||||
return 0;
|
return;
|
||||||
b = Bopen("/dev/snarf", OWRITE|OTRUNC);
|
|
||||||
if(b == nil)
|
|
||||||
return 0;
|
|
||||||
for(z = p = 0; s < e; s++){
|
for(z = p = 0; s < e; s++){
|
||||||
if(*s){
|
if(*s){
|
||||||
if(*s == '\n')
|
if(*s == '\n')
|
||||||
|
@ -890,6 +888,25 @@ writesnarf(Rune *s, Rune *e)
|
||||||
z++;
|
z++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
snarfrect(Rectangle r)
|
||||||
|
{
|
||||||
|
Biobuf *b;
|
||||||
|
|
||||||
|
b = Bopen("/dev/snarf", OWRITE|OTRUNC);
|
||||||
|
if(b == nil)
|
||||||
|
return 0;
|
||||||
|
if(blocksel){
|
||||||
|
while(r.min.y <= r.max.y){
|
||||||
|
seputrunes(b, onscreenr(r.min.x, r.min.y), onscreenr(r.max.x, r.min.y));
|
||||||
|
Bputrune(b, L'\n');
|
||||||
|
r.min.y++;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
seputrunes(b, onscreenr(r.min.x, r.min.y), onscreenr(r.max.x, r.max.y));
|
||||||
|
}
|
||||||
Bterm(b);
|
Bterm(b);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -897,10 +914,12 @@ writesnarf(Rune *s, Rune *e)
|
||||||
Rectangle
|
Rectangle
|
||||||
drawselection(Rectangle r, Rectangle d, Image *color)
|
drawselection(Rectangle r, Rectangle d, Image *color)
|
||||||
{
|
{
|
||||||
while(r.min.y < r.max.y){
|
if(!blocksel){
|
||||||
d = drawselection(Rect(r.min.x, r.min.y, xmax+1, r.min.y), d, color);
|
while(r.min.y < r.max.y){
|
||||||
r.min.x = 0;
|
d = drawselection(Rect(r.min.x, r.min.y, xmax+1, r.min.y), d, color);
|
||||||
r.min.y++;
|
r.min.x = 0;
|
||||||
|
r.min.y++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(r.min.x >= r.max.x)
|
if(r.min.x >= r.max.x)
|
||||||
return d;
|
return d;
|
||||||
|
@ -938,7 +957,7 @@ selection(void)
|
||||||
} while(button1());
|
} while(button1());
|
||||||
if((mc->buttons & 07) == 5)
|
if((mc->buttons & 07) == 5)
|
||||||
sendsnarf();
|
sendsnarf();
|
||||||
else if(writesnarf(onscreenr(r.min.x, r.min.y), onscreenr(r.max.x, r.max.y))){
|
else if(snarfrect(r)){
|
||||||
d = drawselection(r, ZR, green);
|
d = drawselection(r, ZR, green);
|
||||||
flushimage(display, 1);
|
flushimage(display, 1);
|
||||||
sleep(200);
|
sleep(200);
|
||||||
|
@ -954,6 +973,7 @@ readmenu(void)
|
||||||
menu3.item[1] = ttystate[cs->raw].crnl ? "cr" : "crnl";
|
menu3.item[1] = ttystate[cs->raw].crnl ? "cr" : "crnl";
|
||||||
menu3.item[2] = ttystate[cs->raw].nlcr ? "nl" : "nlcr";
|
menu3.item[2] = ttystate[cs->raw].nlcr ? "nl" : "nlcr";
|
||||||
menu3.item[3] = cs->raw ? "cooked" : "raw";
|
menu3.item[3] = cs->raw ? "cooked" : "raw";
|
||||||
|
menu3.item[4] = blocksel ? "linesel" : "blocksel";
|
||||||
|
|
||||||
switch(menuhit(3, mc, &menu3, nil)) {
|
switch(menuhit(3, mc, &menu3, nil)) {
|
||||||
case 0: /* 24x80 */
|
case 0: /* 24x80 */
|
||||||
|
@ -969,6 +989,9 @@ readmenu(void)
|
||||||
cs->raw = !cs->raw;
|
cs->raw = !cs->raw;
|
||||||
return;
|
return;
|
||||||
case 4:
|
case 4:
|
||||||
|
blocksel = !blocksel;
|
||||||
|
return;
|
||||||
|
case 5:
|
||||||
exits(0);
|
exits(0);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue