all repos — kuro @ 15fd5e6d59cb0cc5c6e8083ace8f7cea8175ebfe

multiwindow text editor thing for plan9 with simple client VM and 9p interface

can draw some text
Iris Lightshard nilix@nilfm.cc
PGP Signature
-----BEGIN PGP SIGNATURE-----

iHUEABYKAB0WIQT/foVVmI9pK13hPWFohAcXSWbK8wUCZbyERgAKCRBohAcXSWbK
80jzAP49aIPeX0/0cxuz7TWxJ16Ao0FIhq50kKyuvKLJL1SoAgD7BMNXEoB5yjP7
kd1BJ1gEd3TPYMd3eABEqmzwchlCCQk=
=jD8n
-----END PGP SIGNATURE-----
commit

15fd5e6d59cb0cc5c6e8083ace8f7cea8175ebfe

parent

4ed8a026bb214e9ee19387226dbd51d9bc63ad74

7 files changed, 145 insertions(+), 11 deletions(-)

jump to
M 9port.mkfile9port.mkfile

@@ -8,9 +8,12 @@ srv.$O\

client.$O\ util.$O\ node.$O\ + opcodes.$O\ + theme.$O\ HFILES=dat.h\ fns.h\ + theme.h\ UPDATE=\ mkfile\
M dat.hdat.h

@@ -8,6 +8,7 @@ #include <draw.h>

#include <cursor.h> #include <mouse.h> #include <keyboard.h> +#include <frame.h> typedef enum { CTL = 0,

@@ -55,7 +56,7 @@ TAGF,

BODYF, SHELLF, TOTAL_SUBF -} SubFrame; +} FrameType; typedef struct Aux { FileType type;

@@ -71,15 +72,18 @@

typedef void (*Handler)(void*, void*); typedef struct { + Rune* text; + uint text_len; + Frame* frame; +} SubFrame; + +typedef struct { uvlong id; WindowStatus status; Image* img; Screen* screen; char filepath[512]; - Rune* tag; - uint tag_len; - Rune* body; - uint body_len; + SubFrame* editorState[TOTAL_SUBF]; } KuroMemory; typedef struct {

@@ -89,4 +93,7 @@ Channel* cpu; /* chan(Instruction) */

Handler* handlers; KuroMemory* memory; Channel* status; /* chan(WidowStatus) */ -} Node;+} Node; + +Image* tagcols[NCOL]; +Image* textcols[NCOL];
M fns.hfns.h

@@ -15,4 +15,8 @@ void node_loop(void* data);

Node* create_node(char* filename); void supervise_node(Node* self); void node_cleanup(Node* self); -void memory_cleanup(KuroMemory* self);+void memory_cleanup(KuroMemory* self); + +void set_theme(Image** t, Image** b); + +Handler* get_handlers(void);
M node.cnode.c

@@ -1,6 +1,7 @@

#include "dat.h" #include "fns.h" +static Instruction init_instr = { INIT, nil }; void node_setup(Node* self, Handler* handlers, KuroMemory* memory) { if (self) {

@@ -15,17 +16,22 @@ Node* self = (Node*)data;

Instruction x; for (;;) { + print("waiting for instruction\n"); recv(self->cpu, &x); + print("got opcode: %d\n", x.opcode); + if (self->handlers[x.opcode]) { (*(self->handlers[x.opcode]))(self, x.data); + print("finished executing handler for opcode %d\n", x.opcode); switch(self->memory->status) { case KURO_QUITS: - nbsend(self->status, 0); + nbsend(self->status, 0); threadexits(0); default: break; } - flushimage(self->memory->screen->display, 1); + flushimage(display, 1); + print("refreshed screen\n"); } } }

@@ -40,11 +46,11 @@ initdraw(nil, nil, "kuro");

KuroMemory* self = (KuroMemory*)malloc(sizeof(KuroMemory)); Node* node = (Node*)malloc(sizeof(Node)); - Handler* handlers = (Handler*)malloc(TOTAL_OPCODES * sizeof(Handler*)); + Handler* handlers = get_handlers(); node_setup(node, handlers, self); - self->img = screen; + self->img = allocimage(display, screen->r, screen->chan, 1, display->black); self->screen = _screen; if (filename) { strcpy(self->filepath, filename);

@@ -52,6 +58,8 @@ }

/* node_execute runs the node on a separate thread */ node_execute(node); + + send(node->cpu, (void*)&init_instr); return node; }
A opcodes.c

@@ -0,0 +1,52 @@

+#include "dat.h" +#include "fns.h" +#include "theme.h" + +static Handler handlers[TOTAL_OPCODES]; +static Font* f; + + +static char testbytes[256] = "test data ya heard"; +static Rune testdata[256]; + +void set_handler(Opcode o, Handler h) { + handlers[o] = h; +} + +static void handle_init(void* node, void* data) { + Node* self = (Node*)node; + + SubFrame* tag = (SubFrame*)malloc(sizeof(SubFrame)); + SubFrame* body = (SubFrame*)malloc(sizeof(SubFrame)); + SubFrame* shell = (SubFrame*)malloc(sizeof(SubFrame)); + + tag->frame = (Frame*)malloc(sizeof(Frame)); + body->frame = (Frame*)malloc(sizeof(Frame)); + shell->frame = (Frame*)malloc(sizeof(Frame)); + + self->memory->editorState[TAGF] = tag; + self->memory->editorState[BODYF] = body; + self->memory->editorState[SHELLF] = shell; + + Rectangle r = Rect(self->memory->img->r.min.x,self->memory->img->r.min.y,self->memory->img->r.max.x, self->memory->img->r.min.y + 20); + Rectangle r2 = Rect(self->memory->img->r.min.x, self->memory->img->r.min.y + 20, self->memory->img->r.max.x, self->memory->img->r.max.y); + + set_theme(tagcols, textcols); + + f = openfont(display, PRIMARY_FONT); + frinit(tag->frame, r, f, self->memory->img, tagcols); + frinit(body->frame, r2, f, self->memory->img, textcols); + + Rune* rr = testdata; + for (char* c = testbytes; *c; c++, rr++) { + chartorune(rr, c); + } + frinsert(tag->frame, testdata, testdata + 8*sizeof(Rune), 0); + + draw(screen, self->memory->img->r, self->memory->img, nil, r.min); +} + +Handler* get_handlers(void) { + set_handler(INIT, handle_init); + return handlers; +}
A theme.c

@@ -0,0 +1,28 @@

+#include "dat.h" +#include "fns.h" +#include "theme.h" + +void set_theme(Image** t, Image** b) { + t[BACK] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_BG); + t[HIGH] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_HI); + t[BORD] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_BD); + t[TEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_TX); + t[HTEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_TAG_HT); + + /* BODY */ + b[BACK] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_BG); + b[HIGH] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_HI); + b[BORD] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_BD); + b[TEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_TX); + b[HTEXT] = + allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, COLOR_BODY_HT); +}
A theme.h

@@ -0,0 +1,32 @@

+/* tag & body colors: bg, hilight, border, text, hilighted text */ +#define COLOR_TAG_BG 0x000000FF +#define COLOR_TAG_HI 0x1F9B92FF +#define COLOR_TAG_BD 0x797979FF +#define COLOR_TAG_TX 0xC9C9C9FF +#define COLOR_TAG_HT 0x000000FF + +#define COLOR_BODY_BG 0x000F19FF +#define COLOR_BODY_HI 0x1F9B92FF +#define COLOR_BODY_BD 0x797979FF +#define COLOR_BODY_TX 0x93A1A1FF +#define COLOR_BODY_HT 0x000000FF + +/* button colors: dirty file (mod) indicator and column handles */ + +#define COLOR_BTN_MD 0x1F9B92FF +#define COLOR_BTN_CO 0x002B36FF + +/* button 2 and 3 selection colors */ + +#define COLOR_B2_HI 0x797979FF +#define COLOR_B3_HI 0x002B36FF + +/********* + * fonts * + *********/ + +/* can use either x fonts via fontsrv or p9p fonts */ + +#define PRIMARY_FONT "/mnt/font/SauceCodeProNF/9a/font" +#define SECONDARY_FONT "/lib/font/bit/lucm/unicode.9.font" +