commit 3f2aee21828f5489dd680cd8c244139e619bf699
parent 7e453498215cc620402a449e6e34c0838b6320ad
Author: Pavel Renev <an2qzavok@gmail.com>
Date: Sat, 26 Feb 2022 20:45:58 +0000
reattach to subporcess
Diffstat:
M | fs.c | | | 42 | ++++++++++++++++++++++++++++++++---------- |
M | richterm.c | | | 79 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------- |
M | richterm.h | | | 1 | + |
3 files changed, 104 insertions(+), 18 deletions(-)
diff --git a/fs.c b/fs.c
@@ -46,26 +46,40 @@ initfs(char *srvname)
.flush = fs_flush,
.destroyfid = fs_destroyfid,
};
- newobj = nil;
+ // newobj = nil;
consbuf = nil;
rq = reqqueuecreate();
- menubuf = arraycreate(sizeof(char), 1024, nil);
+ // menubuf = arraycreate(sizeof(char), 1024, nil);
consc = chancreate(sizeof(Array *), 1024);
- ctlc = chancreate(sizeof(Array *), 1024);
+ // ctlc = chancreate(sizeof(Array *), 1024);
+
srv.tree = alloctree("richterm", "richterm", DMDIR|0555, nil);
fsroot = srv.tree->root;
- new = createfile(fsroot, "new", "richterm", 0444,
+
+ cons = createfile(fsroot, "cons", "richterm", DMAPPEND|0666,
+ fauxalloc(nil, nil, nil, consread, conswrite, nil));
+
+ consctl = createfile(fsroot, "consctl", "richterm", DMAPPEND|0666,
+ fauxalloc(nil, nil, nil, nil, nil, nil));
+
+/*
+
+ new = createfile(fsroot, "new", "richterm", 0444,
fauxalloc(nil, nil, newopen, newread, nil, nil));
ctl = createfile(fsroot, "ctl", "richterm", DMAPPEND|0666,
fauxalloc(nil, nil, nil, ctlread, ctlwrite, nil));
- text = createfile(fsroot, "text", "richterm", 0444,
+
+
+ text = createfile(fsroot, "text", "richterm", 0444,
fauxalloc(nil, rich.text, nil, arrayread, nil, nil));
- cons = createfile(fsroot, "cons", "richterm", DMAPPEND|0666,
- fauxalloc(nil, nil, nil, consread, conswrite, nil));
- consctl = createfile(fsroot, "consctl", "richterm", DMAPPEND|0666,
- fauxalloc(nil, nil, nil, nil, nil, nil));
- menu = createfile(fsroot, "menu", "richterm", 0666,
+
+
+
+ menu = createfile(fsroot, "menu", "richterm", 0666,
fauxalloc(nil, menubuf, nil, arrayread, arraywrite, nil));
+
+*/
+
threadpostmountsrv(&srv, srvname, "/mnt/richterm", MREPL);
return 0;
}
@@ -234,6 +248,9 @@ arrayopen(Req *r)
void
arrayread(Req *r)
{
+
+/*
+
Array *data;
data = ((Faux *)r->fid->file->aux)->data;
qlock(rich.l);
@@ -241,6 +258,9 @@ arrayread(Req *r)
readbuf(r, data->p, data->count);
qunlock(data->l);
qunlock(rich.l);
+
+*/
+
respond(r, nil);
}
@@ -370,6 +390,7 @@ consread(Req *r)
arrayfree(consbuf);
consbuf = nil;
}
+
respond(r, nil);
}
@@ -381,6 +402,7 @@ conswrite(Req *r)
arraygrow(a, r->ifcall.count, r->ifcall.data);
nbsend(insertc, &a);
r->ofcall.count = r->ifcall.count;
+
respond(r, nil);
}
diff --git a/richterm.c b/richterm.c
@@ -24,6 +24,8 @@ Object * minobj(Object *, Object *);
long getsel(Point);
int objectisvisible(Object *);
+void insertfromcons(Array *);
+
Rich rich;
int hostpid = -1;
Channel *pidchan, *redrawc, *insertc;
@@ -170,11 +172,9 @@ threadmain(int argc, char **argv)
quotefmtinstall();
atexit(shutdown);
- /*
pidchan = chancreate(sizeof(int), 0);
proccreate(runcmd, argv, 16 * 1024);
hostpid = recvul(pidchan);
- */
threadsetname("main");
@@ -210,11 +210,22 @@ threadmain(int argc, char **argv)
unlockdisplay(display);
break;
case INSERT:
- obj = objectcreate();
+ /*obj = objectcreate();
mkobjectftree(obj, fsroot);
objinsertbeforelast(obj);
- objsettext(obj, arrayget(av, 0, nil), av->count);
+ objsettext(obj, arrayget(av, 0, nil), av->count);*/
+
+ insertfromcons(av);
arrayfree(av);
+ // TODO: this is not how things should be done!
+ // elems should be cleaned properly,
+ // or even better only append fresh data instead of reparsing everything
+ elems->count = 0;
+ parsedata(richdata, elems);
+ arraygrow(elems, 1, &euser);
+ elemslinklist(elems);
+ elemsupdatecache(elems);
+
nbsend(redrawc, &obj);
break;
case KBD:
@@ -259,6 +270,13 @@ threadmain(int argc, char **argv)
euser->count = strlen(euser->str);
free(R);
} else if (kv == '\n') {
+
+ // TODO: send str as array to consc channel
+ Array *msg = arraycreate(sizeof(char), strlen(euser->str) + 1, nil);
+ arraygrow(msg, strlen(euser->str), euser->str);
+ arraygrow(msg, 1, "\n");
+ nbsend(consc, &msg);
+
str = smprint("%c%s\n" "n\n", euser->type, euser->str);
arraygrow(richdata, strlen(str), str);
@@ -991,8 +1009,8 @@ Array *richdata;
Elem *euser;
char *sampledata =
- ".alpha\n"
- "s\n"
+ ".A\n"
+ "t\n"
".beta\n"
"s\n"
"Lhttp://nsmpr.xyz\n"
@@ -1111,7 +1129,7 @@ generatesampleelems(void)
count = strlen(sampledata);
- richdata = arraycreate(sizeof(char *), count, nil);
+ richdata = arraycreate(sizeof(char), count, nil);
arraygrow(richdata, count, (void *)sampledata);
parsedata(richdata, elems);
@@ -1158,7 +1176,7 @@ drawelem(Elem *e)
[E_LINK] drawnoop,
[E_IMAGE] drawnoop,
[E_NL] drawnl,
- [E_TAB] drawnoop,
+ [E_TAB] drawtab,
[E_SPACE] drawspace,
};
@@ -1267,7 +1285,51 @@ drawspace(Elem *e)
}
Point
+drawtab(Elem *e)
+{
+ int x, tabw;
+ tabw = stringwidth(font, "0") * 4;
+ x = (e->pos.x - rich.page.r.min.x) / tabw;
+ Point pos;
+ pos = e->pos;
+ pos.x = rich.page.r.min.x + (x + 1) * tabw;
+ return pos;
+}
+
+Point
drawnoop(Elem *e)
{
return e->pos;
}
+
+void
+insertfromcons(Array *a)
+{
+ int i, nl;
+ qlock(a->l);
+ nl = 1;
+ for (i = 0; i < a->count; i++) {
+ if (nl != 0) {
+ arraygrow(richdata, 1, ".");
+ nl = 0;
+ }
+
+ switch (a->p[i]) {
+ case ' ':
+ arraygrow(richdata, 3, "\ns\n");
+ nl = 1;
+ break;
+ case '\t':
+ arraygrow(richdata, 3, "\nt\n");
+ nl = 1;
+ break;
+ case '\n':
+ arraygrow(richdata, 3, "\nn\n");
+ nl = 1;
+ break;
+ default:
+ arraygrow(richdata, 1, a->p + i);
+ }
+ }
+ qunlock(a->l);
+}
+\ No newline at end of file
diff --git a/richterm.h b/richterm.h
@@ -133,6 +133,7 @@ Point drawelem(Elem *);
Point drawtext(Elem *);
Point drawnl(Elem *);
Point drawspace(Elem *);
+Point drawtab(Elem *);
Point drawnoop(Elem *);
char * elemparse(Elem *, char *, long);
void elemslinklist(Array *);