richterm

"terminal emulator" with support for text fonts and images for plan9
git clone git://nsmpr.xyz/richterm.git
Log | Files | Refs | README

commit 0263b69e9c86181f759031c081cb24b48e36db0d
parent 9412d8b2e3bb1dba331e4737053f9ac4a6df1c3a
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Wed, 16 Mar 2022 23:53:15 +0000

rework Handler, add ../ to Dir output, fix read(1) failing on ctl file

Diffstat:
Mextra/Dir.c | 2+-
Mextra/Handler | 27++++++++++++++-------------
Mextra/mkfile | 1-
Mfs.c | 18+++++++++++-------
Mrichterm.c | 3++-
5 files changed, 28 insertions(+), 23 deletions(-)

diff --git a/extra/Dir.c b/extra/Dir.c @@ -27,7 +27,7 @@ main(int argc, char **argv) dbuf = mallocz(DIRMAX, 1); n = dirreadall(fd, &dbuf); - print("l\nf\n"); + print("f\nl..\n.../\nn\n"); for (i = 0; i < n; i++) { char *spacer = ""; diff --git a/extra/Handler b/extra/Handler @@ -8,12 +8,12 @@ history=`{pwd} forward=() fn clear { - echo clear > $rroot/ctl + echo -n > $rroot/text } fn _exit { clear - echo -n > $rroot/menu + # echo -n > $rroot/menu exit } @@ -21,8 +21,7 @@ fn ldir { cd $1 history = (`{pwd} $history) forward = () - clear - Dir + Dir > $rroot/text } fn lmarkdown { @@ -31,16 +30,15 @@ fn lmarkdown { history = (`{pwd}^/$fname $history) forward = () clear - Markdown $fname + cat $fname } fn lgopher { history = ($1 $history) forward = () - clear switch ($1) { case *.md; Gopher $1 | Markdown - case *; Gopher $1 + case *; Gopher $1 > $rroot/text } } @@ -82,16 +80,19 @@ fn link { if (test -d $1) ldir $1 if not tryfile $1 } + + # following echo is a hack around some race condition in richterm + echo } -cat > $rroot/menu <<EOF ----- -Back -Exit -EOF +# cat > $rroot/menu <<EOF +# ---- +# Back +# Exit +# EOF if (test -n $"1) link $1 -if not link . +if not link `{pwd} event='' while ( { event=`{read $rroot/ctl} } ) { diff --git a/extra/mkfile b/extra/mkfile @@ -12,7 +12,6 @@ BIN=$SYSLIB/bin/$cputype RC=\ Handler\ - clear\ install:V: bindir $RC diff --git a/fs.c b/fs.c @@ -41,10 +41,11 @@ initfs(char *srvname) .destroyfid = fs_destroyfid, }; consbuf = nil; + ctlbuf = nil; rq = reqqueuecreate(); menubuf = arraycreate(sizeof(char), 1024, nil); consc = chancreate(sizeof(Array *), 1024); - ctlc = chancreate(sizeof(Array *), 1024); + ctlc = chancreate(sizeof(Array *), 8); srv.tree = alloctree("richterm", "richterm", DMDIR|0555, nil); fsroot = srv.tree->root; @@ -230,13 +231,16 @@ conswrite(Req *r) void ctlread(Req *r) { - Array *msg; - - recv(ctlc, &msg); - + if (ctlbuf == nil) recv(ctlc, &ctlbuf); + if (ctlbuf == nil) sysfatal("ctlread: ctlbuf is nil: %r"); r->ifcall.offset = 0; - readbuf(r, msg->p, msg->count); - arrayfree(msg); + readbuf(r, ctlbuf->p, ctlbuf->count); + if (arraydel(ctlbuf, 0, r->ofcall.count) != 0) + sysfatal("ctlread: %r"); + if (ctlbuf->count == 0) { + arrayfree(ctlbuf); + ctlbuf = nil; + } respond(r, nil); } diff --git a/richterm.c b/richterm.c @@ -580,6 +580,7 @@ rfollow(void *v) Array *a; a = arraycreate(sizeof(char), 1024, nil); + if (a == nil) sysfatal("rfollow: arraycreate failed: %r"); arraygrow(a, 5, "link "); arraygrow(a, strlen(e->link), e->link); arraygrow(a, 1, "\n"); @@ -637,7 +638,7 @@ ruseract(int f) arraygrow(a, 5, "menu "); arraygrow(a, strlen(s), s); arraygrow(a, 1, "\n"); - // nbsend(ctlc, &a); + nbsend(ctlc, &a); }