all repos — kuro @ 15fd5e6d59cb0cc5c6e8083ace8f7cea8175ebfe

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

opcodes.c (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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;
}