X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=sys%2Fsrc%2Fcmd%2Fsamterm%2Fmain.c;h=fe5dbab93e103e68105cfc7ff855eab2d149c7d2;hb=4bbb3b0b21edd81be37a0a6ad12c76a63d127bed;hp=0b650becf4f9cb0318d95401fcf946b6cecdcead;hpb=87325403b0b32e5c3f7f36dae92b9aaac0355175;p=plan9front.git diff --git a/sys/src/cmd/samterm/main.c b/sys/src/cmd/samterm/main.c index 0b650becf..fe5dbab93 100644 --- a/sys/src/cmd/samterm/main.c +++ b/sys/src/cmd/samterm/main.c @@ -9,6 +9,8 @@ #include "flayer.h" #include "samterm.h" +int mainstacksize = 16*1024; + Text cmd; Rune *scratch; long nscralloc; @@ -24,14 +26,16 @@ char hostlock = 1; char hasunlocked = 0; int maxtab = 8; int autoindent; +int spacesindent; void threadmain(int argc, char *argv[]) { - int i, got, scr, chord; + int i, got, nclick, scr, chord; Text *t; Rectangle r; Flayer *nwhich; + ulong p; getscreen(argc, argv); iconinit(); @@ -96,21 +100,23 @@ threadmain(int argc, char *argv[]) } } }else if(mousep->buttons&(1|8)){ - if(nwhich){ - if(nwhich!=which) - current(nwhich); - else if(scr) - scroll(which, (mousep->buttons&8) ? 4 : 1); - else{ - t=(Text *)which->user1; - if(flselect(which)){ - outTsl(Tdclick, t->tag, which->p0); - t->lock++; - }else if(t!=&cmd) - outcmd(); - if(mousep->buttons&1) - chord = mousep->buttons; - } + if(scr) + scroll(which, (mousep->buttons&8) ? 4 : 1); + else if(nwhich && nwhich!=which) + current(nwhich); + else{ + t=(Text *)which->user1; + nclick = flselect(which, &p); + if(nclick > 0){ + if(nclick > 1) + outTsl(Ttclick, t->tag, p); + else + outTsl(Tdclick, t->tag, p); + t->lock++; + }else if(t!=&cmd) + outcmd(); + if(mousep->buttons&1) + chord = mousep->buttons; } }else if((mousep->buttons&2) && which){ if(scr) @@ -309,6 +315,9 @@ scrorigin(Flayer *l, int but, long p0) { Text *t=(Text *)l->user1; + if(t->tag == Untagged) + return; + switch(but){ case 1: outTsll(Torigin, t->tag, l->origin, p0); @@ -348,6 +357,33 @@ raspc(Rasp *r, long p) return 0; } +int +getcol(Rasp *r, long p) +{ + int col; + + for(col = 0; p > 0 && raspc(r, p-1)!='\n'; p--, col++) + ; + return col; +} + +long +del(Rasp *r, long o, long p) +{ + int i, col, n; + + if(--p < o) + return o; + if(!spacesindent || raspc(r, p)!=' ') + return p; + col = getcol(r, p) + 1; + if((n = col % maxtab) == 0) + n = maxtab; + for(i = 0; p-1>=o && raspc(r, p-1)==' ' && i=o? p : o; +} + long ctlw(Rasp *r, long o, long p) { @@ -439,32 +475,22 @@ flushtyping(int clearesc) typeend = -1; } -#define BACKSCROLLKEY Kup -#define ENDKEY Kend -#define ESC 0x1B -#define HOMEKEY Khome -#define LEFTARROW Kleft -#define LINEEND 0x05 -#define LINESTART 0x01 -#define PAGEDOWN Kpgdown -#define PAGEUP Kpgup -#define RIGHTARROW Kright -#define SCROLLKEY Kdown - int nontypingkey(int c) { switch(c){ - case BACKSCROLLKEY: - case ENDKEY: - case HOMEKEY: - case LEFTARROW: - case LINEEND: - case LINESTART: - case PAGEDOWN: - case PAGEUP: - case RIGHTARROW: - case SCROLLKEY: + case Kup: + case Kdown: + case Khome: + case Kend: + case Kpgdown: + case Kpgup: + case Kleft: + case Kright: + case Ksoh: + case Kenq: + case Kstx: + case Kbel: return 1; } return 0; @@ -498,15 +524,22 @@ type(Flayer *l, int res) /* what a bloody mess this is */ backspacing = 0; while((c = kbdchar())>0){ if(res == RKeyboard){ - if(nontypingkey(c) || c==ESC) + if(nontypingkey(c) || c==Kesc) break; /* backspace, ctrl-u, ctrl-w, del */ - if(c=='\b' || c==0x15 || c==0x17 || c==0x7F){ + if(c==Kbs || c==Knack || c==Ketb || c==Kdel){ backspacing = 1; break; } } - *p++ = c; + if(spacesindent && c == '\t'){ + int i, col, n; + col = getcol(&t->rasp, a); + n = maxtab - col % maxtab; + for(i = 0; i < n && p < buf+nelem(buf); i++) + *p++ = ' '; + } else + *p++ = c; if(autoindent) if(c == '\n'){ /* autoindent */ @@ -539,39 +572,39 @@ type(Flayer *l, int res) /* what a bloody mess this is */ flushtyping(0); onethird(l, a); } - if(c==SCROLLKEY || c==PAGEDOWN){ + if(c==Kdown || c==Kpgdown){ flushtyping(0); center(l, l->origin+l->f.nchars+1); /* backspacing immediately after outcmd(): sorry */ - }else if(c==BACKSCROLLKEY || c==PAGEUP){ + }else if(c==Kup || c==Kpgup){ flushtyping(0); a0 = l->origin-l->f.nchars; if(a0 < 0) a0 = 0; center(l, a0); - }else if(c == RIGHTARROW){ + }else if(c == Kright){ flushtyping(0); a0 = l->p0; if(a0 < t->rasp.nrunes) a0++; flsetselect(l, a0, a0); center(l, a0); - }else if(c == LEFTARROW){ + }else if(c == Kleft){ flushtyping(0); a0 = l->p0; if(a0 > 0) a0--; flsetselect(l, a0, a0); center(l, a0); - }else if(c == HOMEKEY){ + }else if(c == Khome){ flushtyping(0); center(l, 0); - }else if(c == ENDKEY){ + }else if(c == Kend){ flushtyping(0); center(l, t->rasp.nrunes); - }else if(c == LINESTART || c == LINEEND){ + }else if(c == Ksoh || c == Kenq){ flushtyping(1); - if(c == LINESTART) + if(c == Ksoh) while(a > 0 && raspc(&t->rasp, a-1)!='\n') a--; else @@ -585,14 +618,14 @@ type(Flayer *l, int res) /* what a bloody mess this is */ /* backspacing immediately after outcmd(): sorry */ if(l->f.p0>0 && a>0){ switch(c){ - case '\b': - case 0x7F: /* del */ - l->p0 = a-1; + case Kbs: + case Kdel: /* del */ + l->p0 = del(&t->rasp, l->origin, a); break; - case 0x15: /* ctrl-u */ + case Knack: /* ctrl-u */ l->p0 = ctlu(&t->rasp, l->origin, a); break; - case 0x17: /* ctrl-w */ + case Ketb: /* ctrl-w */ l->p0 = ctlw(&t->rasp, l->origin, a); break; } @@ -622,8 +655,33 @@ type(Flayer *l, int res) /* what a bloody mess this is */ } } } + }else if(c == Kstx){ + t = &cmd; + for(l=t->l; l->textfn==0; l++) + ; + current(l); + flushtyping(0); + a = t->rasp.nrunes; + flsetselect(l, a, a); + center(l, a); + }else if(c == Kbel){ + int i; + if(work == nil) + return; + if(which != work){ + current(work); + return; + } + t = (Text*)work->user1; + l = &t->l[t->front]; + for(i=t->front; t->nwin>1 && (i = (i+1)%NL) != t->front; ) + if(t->l[i].textfn != 0){ + l = &t->l[i]; + break; + } + current(l); }else{ - if(c==ESC && typeesc>=0){ + if(c==Kesc && typeesc>=0){ l->p0 = typeesc; l->p1 = a; flushtyping(1);