aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/samterm
diff options
context:
space:
mode:
authorrsc <devnull@localhost>2005-01-27 06:10:35 +0000
committerrsc <devnull@localhost>2005-01-27 06:10:35 +0000
commit17ab31aac6639e210613691669163b0c2874d1ce (patch)
treed64fa43d93a72fe850f6cf936eb1ea2d64b4905f /src/cmd/samterm
parent4ac5f249ad40f3452fc87dc9a3f4b9d9546c83b0 (diff)
downloadplan9port-17ab31aac6639e210613691669163b0c2874d1ce.tar.gz
plan9port-17ab31aac6639e210613691669163b0c2874d1ce.tar.bz2
plan9port-17ab31aac6639e210613691669163b0c2874d1ce.zip
add autoindent (-a) and chording.
clean up argument parsing.
Diffstat (limited to 'src/cmd/samterm')
-rw-r--r--src/cmd/samterm/flayer.c3
-rw-r--r--src/cmd/samterm/main.c57
-rw-r--r--src/cmd/samterm/plan9.c23
-rw-r--r--src/cmd/samterm/samterm.h1
4 files changed, 71 insertions, 13 deletions
diff --git a/src/cmd/samterm/flayer.c b/src/cmd/samterm/flayer.c
index c308993a..729b72cf 100644
--- a/src/cmd/samterm/flayer.c
+++ b/src/cmd/samterm/flayer.c
@@ -253,10 +253,11 @@ fldelete(Flayer *l, long p0, long p1)
int
flselect(Flayer *l)
{
- int ret = 0;
+ int ret;
if(l->visible!=All)
flupfront(l);
frselect(&l->f, mousectl);
+ ret = 0;
if(l->f.p0==l->f.p1){
if(mousep->msec-l->click<Clicktime && l->f.p0+l->origin==l->p0){
ret = 1;
diff --git a/src/cmd/samterm/main.c b/src/cmd/samterm/main.c
index c56ea5f8..ed75af79 100644
--- a/src/cmd/samterm/main.c
+++ b/src/cmd/samterm/main.c
@@ -23,11 +23,13 @@ long modified = 0; /* strange lookahead for menus */
char hostlock = 1;
char hasunlocked = 0;
int maxtab = 8;
+int chord;
+int autoindent;
void
threadmain(int argc, char *argv[])
{
- int i, got, scr;
+ int i, got, scr, w;
Text *t;
Rectangle r;
Flayer *nwhich;
@@ -98,7 +100,11 @@ dup(2, 1);
scr = which && ptinrect(mousep->xy, which->scroll);
if(mousep->buttons)
flushtyping(1);
- if(mousep->buttons&1){
+ if(chord==1 && !mousep->buttons)
+ chord = 0;
+ if(chord)
+ chord |= mousep->buttons;
+ else if(mousep->buttons&1){
if(nwhich){
if(nwhich!=which)
current(nwhich);
@@ -111,6 +117,8 @@ dup(2, 1);
t->lock++;
}else if(t!=&cmd)
outcmd();
+ if(mousep->buttons&1)
+ chord = mousep->buttons;
}
}
}else if((mousep->buttons&2) && which){
@@ -126,10 +134,22 @@ dup(2, 1);
}
mouseunblock();
}
+ if(chord){
+ t = (Text*)which->user1;
+ if(!t->lock && !hostlock){
+ w = which-t->l;
+ if(chord&2){
+ cut(t, w, 1, 1);
+ chord &= ~2;
+ }else if(chord&4){
+ paste(t, w);
+ chord &= ~4;
+ }
+ }
+ }
}
}
-
void
resize(void)
{
@@ -394,7 +414,7 @@ center(Flayer *l, long a)
}
int
-onethird(Flayer *l, long a)
+thirds(Flayer *l, long a, int n)
{
Text *t;
Rectangle s;
@@ -405,7 +425,7 @@ onethird(Flayer *l, long a)
if(a > t->rasp.nrunes)
a = t->rasp.nrunes;
s = insetrect(l->scroll, 1);
- lines = ((s.max.y-s.min.y)/l->f.font->height+1)/3;
+ lines = (n*(s.max.y-s.min.y)/l->f.font->height+1)/3;
if (lines < 2)
lines = 2;
outTsll(Torigin, t->tag, a, lines);
@@ -414,6 +434,18 @@ onethird(Flayer *l, long a)
return 0;
}
+int
+onethird(Flayer *l, long a)
+{
+ return thirds(l, a, 1);
+}
+
+int
+twothirds(Flayer *l, long a)
+{
+ return thirds(l, a, 2);
+}
+
void
flushtyping(int clearesc)
{
@@ -495,7 +527,20 @@ type(Flayer *l, int res) /* what a bloody mess this is */
}
}
*p++ = c;
- if(c == '\n' || p >= buf+sizeof(buf)/sizeof(buf[0]))
+ if(autoindent)
+ if(c == '\n'){
+ /* autoindent */
+ int cursor, ch;
+ cursor = ctlu(&t->rasp, 0, a+(p-buf)-1);
+ while(p < buf+nelem(buf)){
+ ch = raspc(&t->rasp, cursor++);
+ if(ch == ' ' || ch == '\t')
+ *p++ = ch;
+ else
+ break;
+ }
+ }
+ if(c == '\n' || p >= buf+nelem(buf))
break;
}
if(p > buf){
diff --git a/src/cmd/samterm/plan9.c b/src/cmd/samterm/plan9.c
index 3d2df85d..2aca0842 100644
--- a/src/cmd/samterm/plan9.c
+++ b/src/cmd/samterm/plan9.c
@@ -26,16 +26,27 @@ static char *exname;
#define STACK 16384
void
+usage(void)
+{
+ fprint(2, "usage: samterm -a -W winsize\n");
+ threadexitsall("usage");
+}
+
+void
getscreen(int argc, char **argv)
{
- int i;
char *t;
- /* not exactly right */
- for(i=0; i<argc-1; i++){
- if(strcmp(argv[i], "-W") == 0)
- winsize = argv[i+1];
- }
+ ARGBEGIN{
+ case 'a':
+ autoindent = 1;
+ break;
+ case 'W':
+ winsize = EARGF(usage());
+ break;
+ default:
+ usage();
+ }ARGEND
if(initdraw(panic1, nil, "sam") < 0){
fprint(2, "samterm: initdraw: %r\n");
diff --git a/src/cmd/samterm/samterm.h b/src/cmd/samterm/samterm.h
index dfe2f345..5ba7c315 100644
--- a/src/cmd/samterm/samterm.h
+++ b/src/cmd/samterm/samterm.h
@@ -88,6 +88,7 @@ extern int hversion;
extern int plumbfd;
extern int hostfd[2];
extern int exiting;
+extern int autoindent;
#define gettext sam_gettext /* stupid gcc built-in functions */
Rune *gettext(Flayer*, long, ulong*);