aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/cmd/9term/Darwin.c21
-rw-r--r--src/cmd/9term/wind.c9
-rw-r--r--src/cmd/acme/dat.h1
-rw-r--r--src/cmd/acme/exec.c25
-rw-r--r--src/cmd/acme/text.c62
-rw-r--r--src/cmd/acme/wind.c3
-rw-r--r--src/cmd/samterm/main.c78
-rw-r--r--src/cmd/samterm/scroll.c26
8 files changed, 195 insertions, 30 deletions
diff --git a/src/cmd/9term/Darwin.c b/src/cmd/9term/Darwin.c
index 0bd4ece7..369f7da2 100644
--- a/src/cmd/9term/Darwin.c
+++ b/src/cmd/9term/Darwin.c
@@ -2,16 +2,19 @@
#include "bsdpty.c"
#undef getpts
-#include <util.h>
-
int
getpts(int fd[], char *slave)
{
- if(openpty(&fd[1], &fd[0], NULL, NULL, NULL) >= 0){
- fchmod(fd[1], 0620);
- strcpy(slave, ttyname(fd[0]));
- return 0;
- }
- sysfatal("no ptys");
- return 0;
+ fd[1] = posix_openpt(ORDWR);
+ if (fd[1] >= 0) {
+ grantpt(fd[1]);
+ unlockpt(fd[1]);
+ fchmod(fd[1], 0620);
+ strcpy(slave, ptsname(fd[1]));
+ if ((fd[0] = open(slave, ORDWR)) >= 0)
+ return 0;
+ close(fd[1]);
+ }
+ sysfatal("no ptys");
+ return 0;
}
diff --git a/src/cmd/9term/wind.c b/src/cmd/9term/wind.c
index 7993930d..da3fd2fc 100644
--- a/src/cmd/9term/wind.c
+++ b/src/cmd/9term/wind.c
@@ -53,9 +53,12 @@ wmk(Image *i, Mousectl *mc, Channel *ck, Channel *cctl, int scrolling)
/* greys are multiples of 0x11111100+0xFF, 14* being palest */
grey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xEEEEEEFF);
darkgrey = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x666666FF);
- cols[BACK] = display->white;
- cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF);
- cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF);
+ //cols[BACK] = display->white;
+ cols[BACK] = allocimagemix(display, DPaleyellow, DWhite);
+ //cols[HIGH] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0xCCCCCCFF);
+ cols[HIGH] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DDarkyellow);
+ //cols[BORD] = allocimage(display, Rect(0,0,1,1), CMAP8, 1, 0x999999FF);
+ cols[BORD] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, DYellowgreen);
cols[TEXT] = display->black;
cols[HTEXT] = display->black;
titlecol = allocimage(display, Rect(0,0,1,1), CMAP8, 1, DGreygreen);
diff --git a/src/cmd/acme/dat.h b/src/cmd/acme/dat.h
index 8a81c97d..3a3d2e78 100644
--- a/src/cmd/acme/dat.h
+++ b/src/cmd/acme/dat.h
@@ -269,6 +269,7 @@ struct Window
int utflastqid;
int utflastboff;
int utflastq;
+ uchar tabexpand; /* expand tab char with space*body.tabstop */
int tagsafe; /* taglines is correct */
int tagexpand;
int taglines;
diff --git a/src/cmd/acme/exec.c b/src/cmd/acme/exec.c
index be7936ae..f6dc32f4 100644
--- a/src/cmd/acme/exec.c
+++ b/src/cmd/acme/exec.c
@@ -54,6 +54,7 @@ void putall(Text*, Text*, Text*, int, int, Rune*, int);
void sendx(Text*, Text*, Text*, int, int, Rune*, int);
void sort(Text*, Text*, Text*, int, int, Rune*, int);
void tab(Text*, Text*, Text*, int, int, Rune*, int);
+void tabexpand(Text*, Text*, Text*, int, int, Rune*, int);
void zeroxx(Text*, Text*, Text*, int, int, Rune*, int);
typedef struct Exectab Exectab;
@@ -93,6 +94,7 @@ static Rune LSend[] = { 'S', 'e', 'n', 'd', 0 };
static Rune LSnarf[] = { 'S', 'n', 'a', 'r', 'f', 0 };
static Rune LSort[] = { 'S', 'o', 'r', 't', 0 };
static Rune LTab[] = { 'T', 'a', 'b', 0 };
+static Rune LTabexpand[] = { 'T', 'a', 'b', 'e', 'x', 'p', 'a', 'n', 'd', 0 };
static Rune LUndo[] = { 'U', 'n', 'd', 'o', 0 };
static Rune LZerox[] = { 'Z', 'e', 'r', 'o', 'x', 0 };
@@ -124,6 +126,7 @@ Exectab exectab[] = {
{ LSnarf, cut, FALSE, TRUE, FALSE },
{ LSort, sort, FALSE, XXX, XXX },
{ LTab, tab, FALSE, XXX, XXX },
+ { LTabexpand, tabexpand, FALSE, XXX, XXX },
{ LUndo, undo, FALSE, TRUE, XXX },
{ LZerox, zeroxx, FALSE, XXX, XXX },
{ nil, 0, 0, 0, 0 }
@@ -1490,6 +1493,28 @@ tab(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
}
void
+tabexpand(Text *et, Text *_0, Text *argt, int _1, int _2, Rune *arg, int narg)
+{
+ Window *w;
+
+ USED(_0);
+ USED(_1);
+ USED(_2);
+
+ if(et==nil || et->w==nil)
+ return;
+ w = et->w;
+
+ if(w->tabexpand){
+ w->tabexpand = FALSE;
+ warning(nil, "%.*S: Tabexpand OFF\n", w->body.file->nname, w->body.file->name);
+ }else{
+ w->tabexpand = TRUE;
+ warning(nil, "%.*S: Tabexpand ON\n", w->body.file->nname, w->body.file->name);
+ }
+}
+
+void
runproc(void *argvp)
{
/* args: */
diff --git a/src/cmd/acme/text.c b/src/cmd/acme/text.c
index 09422dda..00a3ed5b 100644
--- a/src/cmd/acme/text.c
+++ b/src/cmd/acme/text.c
@@ -243,6 +243,9 @@ textload(Text *t, uint q0, char *file, int setqid)
dbuf = nil;
while((n=dirread(fd, &dbuf)) > 0){
for(i=0; i<n; i++){
+// if(dbuf[i].name[0] == '.'){
+// continue; /* do not list dot files */
+// }
dl = emalloc(sizeof(Dirlist));
j = strlen(dbuf[i].name);
tmp = emalloc(j+1+1);
@@ -745,19 +748,74 @@ texttype(Text *t, Rune r)
} else
textshow(t, t->file->b.nc, t->file->b.nc, FALSE);
return;
+ case 0x09: /* ^I (TAB) */
+ if(t->what!=Body)
+ break;
+ if(t->w->tabexpand == TRUE){
+ for(i=0; i < t->w->body.tabstop; i++){
+ texttype(t, ' ');
+ }
+ return;
+ }else
+ break; /* fall through to normal code */
case 0x01: /* ^A: beginning of line */
typecommit(t);
/* go to where ^U would erase, if not already at BOL */
nnb = 0;
if(t->q0>0 && textreadc(t, t->q0-1)!='\n')
nnb = textbswidth(t, 0x15);
+ /* if already at beginning, wrap backwards to previous line if possible */
+ if (nnb == 0 && t->q0>0) {
+ textshow(t, t->q0-1, t->q0-1, TRUE);
+ return;
+ }
textshow(t, t->q0-nnb, t->q0-nnb, TRUE);
return;
case 0x05: /* ^E: end of line */
typecommit(t);
q0 = t->q0;
+ /* if already at end, wrap forward to the next line if possible */
+ if (q0<t->file->b.nc && textreadc(t, q0) == '\n') {
+ q0++;
+ textshow(t, q0, q0, TRUE);
+ return;
+ }
+ while(q0<t->file->b.nc && textreadc(t, q0)!='\n')
+ q0++;
+ textshow(t, q0, q0, TRUE);
+ return;
+ case 0x0E: /* ^N: move one line down */
+ typecommit(t);
+ q0 = t->q0;
+ nnb = 0;
+ if(q0>0 && textreadc(t, q0-1)!='\n')
+ nnb = textbswidth(t, 0x15);
while(q0<t->file->b.nc && textreadc(t, q0)!='\n')
q0++;
+ if (q0+1 <= t->file->b.nc)
+ q0++;
+ while(q0<t->file->b.nc && textreadc(t, q0)!='\n' && nnb--)
+ q0++;
+ textshow(t, q0, q0, TRUE);
+ return;
+ case 0x10: /* ^P: move one line up */
+ typecommit(t);
+ q0 = t->q0;
+ nnb = 0;
+ n = 0;
+ if(q0>0 && textreadc(t, q0-1)!='\n')
+ nnb = textbswidth(t, 0x15);
+ q0 -= nnb;
+ if (q0>0)
+ q0--;
+ while (q0>0 && textreadc(t, q0-1)!='\n')
+ if (q0 == 0)
+ break;
+ else {
+ q0--;
+ n++;
+ }
+ q0 += (nnb > n) ? n : nnb;
textshow(t, q0, q0, TRUE);
return;
case Kcmd+'c': /* %C: copy */
@@ -772,6 +830,10 @@ texttype(Text *t, Rune r)
typecommit(t);
undo(t, nil, nil, FALSE, 0, nil, 0);
return;
+ case Kcmd+'s': /* %S: save/put file */
+ typecommit(t);
+ put(&t->w->body, nil, nil, XXX, XXX, nil, 0);
+ return;
Tagdown:
/* expand tag to show all text */
diff --git a/src/cmd/acme/wind.c b/src/cmd/acme/wind.c
index 0cba5920..cf261311 100644
--- a/src/cmd/acme/wind.c
+++ b/src/cmd/acme/wind.c
@@ -81,9 +81,12 @@ wininit(Window *w, Window *clone, Rectangle r)
w->filemenu = TRUE;
w->maxlines = w->body.fr.maxlines;
w->autoindent = globalautoindent;
+ w->tabexpand = FALSE;
if(clone){
w->dirty = clone->dirty;
w->autoindent = clone->autoindent;
+ w->tabexpand = clone->tabexpand;
+ w->body.tabstop = clone->body.tabstop;
textsetselect(&w->body, clone->body.q0, clone->body.q1);
winsettag(w);
}
diff --git a/src/cmd/samterm/main.c b/src/cmd/samterm/main.c
index de951845..8bd02ca0 100644
--- a/src/cmd/samterm/main.c
+++ b/src/cmd/samterm/main.c
@@ -108,19 +108,21 @@ threadmain(int argc, char *argv[])
continue;
}
nwhich = flwhich(mousep->xy);
- scr = which && ptinrect(mousep->xy, which->scroll);
+ //scr = which && ptinrect(mousep->xy, which->scroll);
+ scr = which && (ptinrect(mousep->xy, which->scroll) || mousep->buttons&(8|16));
if(mousep->buttons)
flushtyping(1);
if(chording && chord==1 && !mousep->buttons)
chord = 0;
if(chording && chord)
chord |= mousep->buttons;
- else if(mousep->buttons&1){
+ else if(mousep->buttons&(1|8)){
if(nwhich){
if(nwhich!=which)
current(nwhich);
else if(scr)
- scroll(which, 1);
+ //scroll(which, 1);
+ scroll(which, (mousep->buttons&8) ? 4 : 1);
else{
t=(Text *)which->user1;
if(flselect(which)){
@@ -137,9 +139,10 @@ threadmain(int argc, char *argv[])
scroll(which, 2);
else
menu2hit();
- }else if((mousep->buttons&4)){
+ }else if((mousep->buttons&(4|16))){
if(scr)
- scroll(which, 3);
+ //scroll(which, 3);
+ scroll(which, (mousep->buttons&16) ? 5 : 3);
else
menu3hit();
}
@@ -483,6 +486,48 @@ flushtyping(int clearesc)
typeend = -1;
}
+void
+sendcmd(char *c, int n, Text *t) {
+ Text *to = t;
+ Rune buf[100];
+ Rune *p = buf;
+ Flayer *l;
+ long a;
+
+ 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);
+
+ for(int x = 0; x < n; x++){
+ chartorune(p++,c++);
+ }
+ *p++ = '\n';
+ if(typestart < 0)
+ typestart = a;
+ if(typeesc < 0)
+ typeesc = a;
+ hgrow(t->tag, a, p-buf, 0);
+ t->lock++; /* pretend we Trequest'ed for hdatarune*/
+ hdatarune(t->tag, a, buf, p-buf);
+ a += p-buf;
+ l->p0 = a;
+ l->p1 = a;
+ typeend = a;
+ flushtyping(0);
+ onethird(l, a);
+
+ t = to;
+ for(l=t->l; l->textfn==0; l++)
+ ;
+ current(l);
+ flushtyping(1);
+}
+
#define BACKSCROLLKEY Kup
#define ENDKEY Kend
#define ESC 0x1B
@@ -497,6 +542,8 @@ flushtyping(int clearesc)
#define CUT (Kcmd+'x')
#define COPY (Kcmd+'c')
#define PASTE (Kcmd+'v')
+#define UNDO (Kcmd+'z')
+#define REDO (Kcmd+'Z')
int
nontypingkey(int c)
@@ -619,16 +666,29 @@ type(Flayer *l, int res) /* what a bloody mess this is */
center(l, t->rasp.nrunes);
}else if(c == LINESTART || c == LINEEND){
flushtyping(1);
- if(c == LINESTART)
- while(a > 0 && raspc(&t->rasp, a-1)!='\n')
+ if(c == LINESTART){
+ if (a > 0 && raspc(&t->rasp, a-1)=='\n')
a--;
- else
- while(a < t->rasp.nrunes && raspc(&t->rasp, a)!='\n')
+ else{
+ while(a > 0 && raspc(&t->rasp, a-1)!='\n')
+ a--;
+ }
+ }else{
+ if(a < t->rasp.nrunes && raspc(&t->rasp, a)=='\n')
a++;
+ else{
+ while(a < t->rasp.nrunes && raspc(&t->rasp, a)!='\n')
+ a++;
+ }
+ }
l->p0 = l->p1 = a;
for(l=t->l; l<&t->l[NL]; l++)
if(l->textfn)
flsetselect(l, l->p0, l->p1);
+ }else if(c == UNDO) {
+ sendcmd("u", 1, t);
+ }else if(c == REDO) {
+ sendcmd("u-1", 3, t);
}else if(backspacing && !hostlock){
/* backspacing immediately after outcmd(): sorry */
if(l->f.p0>0 && a>0){
diff --git a/src/cmd/samterm/scroll.c b/src/cmd/samterm/scroll.c
index 12614751..36173410 100644
--- a/src/cmd/samterm/scroll.c
+++ b/src/cmd/samterm/scroll.c
@@ -115,7 +115,7 @@ scroll(Flayer *l, int but)
draw(scrback, Rect(0,0,Dx(l->scroll), Dy(l->scroll)), l->f.b, nil, l->scroll.min);
do{
oin = in;
- in = abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
+ in = (but > 3) || (but == 2) || abs(x-mousep->xy.x)<=FLSCROLLWID(l)/2;
if(oin && !in)
scrunmark(l, r);
if(in){
@@ -126,9 +126,11 @@ scroll(Flayer *l, int but)
my = s.min.y;
if(my >= s.max.y)
my = s.max.y;
- if(!eqpt(mousep->xy, Pt(x, my)))
- moveto(mousectl, Pt(x, my));
- if(but == 1){
+ if(!eqpt(mousep->xy, Pt(x, my))) {
+ if (but <=3)
+ moveto(mousectl, Pt(x, my));
+ }
+ if(but == 1 || but == 4){
p0 = l->origin-frcharofpt(&l->f, Pt(s.max.x, my));
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
y = rt.min.y;
@@ -136,7 +138,7 @@ scroll(Flayer *l, int but)
y = my;
if(y > s.max.y-2)
y = s.max.y-2;
- }else if(but == 3){
+ }else if(but == 3 || but == 5){
p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
rt = scrpos(l->scroll, p0, p0+l->f.nchars, tot);
y = rt.min.y;
@@ -147,22 +149,28 @@ scroll(Flayer *l, int but)
scrmark(l, r);
}
}
- }while(button(but));
+ }while(but <=3 && button(but));
if(in){
h = s.max.y-s.min.y;
scrunmark(l, r);
p0 = 0;
- if(but == 1)
+ if(but == 1 || but == 4) {
p0 = (long)(my-s.min.y)/l->f.font->height+1;
- else if(but == 2){
+ if(but == 4)
+ p0 = (long)2;
+ but = 1;
+ }else if(but == 2){
if(tot > 1024L*1024L)
p0 = ((tot>>10)*(y-s.min.y)/h)<<10;
else
p0 = tot*(y-s.min.y)/h;
- }else if(but == 3){
+ }else if(but == 3 || but == 5){
p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, my));
+ if(but == 5)
+ p0 = l->origin+frcharofpt(&l->f, Pt(s.max.x, s.min.y+l->f.font->height+1));
if(p0 > tot)
p0 = tot;
+ but = 3;
}
scrorigin(l, but, p0);
}