richterm

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

commit 6630d0d8aa1cf8154390766fe19dc8becd203b17
parent f70f47bf375aef6c499b04206e2a8428e4c99358
Author: Pavel Renev <an2qzavok@gmail.com>
Date:   Sat, 15 May 2021 22:03:43 +0000

simplify devfs.c by complicating richterm.c, add more fields to Object struct for future use

Diffstat:
Mdevfs.c | 18++++++++++--------
Mrichterm.c | 16++++++++++++----
Mrichterm.h | 6++++++
3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/devfs.c b/devfs.c @@ -32,16 +32,18 @@ devfs_write(Req *r) { File *f; Devfsctl *dctl; - Object obj; f = r->fid->file; dctl = f->aux; if (f == cons){ - obj.type = strdup("text"); - obj.opts = strdup(""); - obj.count = r->ifcall.count; - obj.data = mallocz(obj.count + 1, 1); - memcpy(obj.data, r->ifcall.data, r->ifcall.count); - send(dctl->wc, &obj); + char *buf; + buf = mallocz(r->ifcall.count + 1, 1); + /* + * + 1 is a hack to make sure string is \0 terminated + * we should send a struct that includes both data and size + * instead of simple char pointer. + */ + memcpy(buf, r->ifcall.data, r->ifcall.count); + send(dctl->wc, &buf); r->ofcall.count = r->ifcall.count; respond(r, nil); } else if (f == consctl) { @@ -59,7 +61,7 @@ initdevfs(void) }; dctl = mallocz(sizeof(Devfsctl), 1); - dctl->wc = chancreate(sizeof(Object), 0); + dctl->wc = chancreate(sizeof(char *), 0); dctl->rc = chancreate(sizeof(int), 1024); srv.tree = alloctree("richterm", "richterm", DMDIR|0555, nil); if (srv.tree == nil) diff --git a/richterm.c b/richterm.c @@ -93,7 +93,8 @@ usage(void) void threadmain(int argc, char **argv) { - Object ov, *olast; + Object *olast; + char *ov; Rich rich; int i; Mousectl *mctl; @@ -127,13 +128,15 @@ threadmain(int argc, char **argv) "text", "font=/lib/font/bit/lucida/unicode.24.font", strdup("This is richterm\n"), - strlen("This is richterm\n") + strlen("This is richterm\n"), + "", "", "", "", }; rich.obj[1] = (Object){ "text", "font=/lib/font/bit/lucida/unicode.16.font", strdup("The future of textual interfacing\n"), - strlen("The future of textual interfacing\n") + strlen("The future of textual interfacing\n"), + "", "", "", "", }; rich.page.scroll = ZP; rich.page.view = nil; @@ -162,6 +165,7 @@ threadmain(int argc, char **argv) {nil, nil, CHANEND}, }; for (;;) { + Object *obj; switch(alt(alts)) { case MOUSE: break; @@ -205,7 +209,11 @@ threadmain(int argc, char **argv) case DEVFSWRITE: rich.count++; rich.obj = realloc(rich.obj, rich.count * sizeof(Object)); - rich.obj[rich.count - 1] = ov; + obj = &(rich.obj[rich.count - 1]); + obj->data = ov; + obj->type = "text"; + obj->opts = ""; + obj->count = strlen(ov); generatepage(screen->r, &rich); draw(screen, screen->r, display->white, nil, ZP); diff --git a/richterm.h b/richterm.h @@ -6,10 +6,16 @@ struct Devfsctl { typedef struct Object Object; struct Object { + /* old fields */ char *type; char *opts; char *data; long count; + /* future fields */ + char *text; + char *font; + char *link; + char *image; }; Devfsctl * initdevfs(void);