10
static void edwin_event(struct edwin *w, struct vt_event *ev);
13
cursor(struct edwin *w, int x, int y)
21
if (x < 0 || x >= W || y < 0 || y >= H)
26
xio_get_line(w->xw, 0, buf0);
27
xio_get_line(w->xw, y, buf1);
29
sprintf(buf2, "%2d\3%02x \7 ", y, buf1[x]);
30
buf2[6] = "CI"[w->mode];
31
memcpy(buf0, buf2, 8);
33
xio_put_line(w->xw, 0, buf0);
34
xio_set_cursor(w->xw, w->x = x, w->y = y);
38
adv_cursor(struct edwin *w)
41
cursor(w, w->x+1, w->y);
49
set_char(struct edwin *w, int c)
53
xio_get_line(w->xw, w->y, buf);
55
xio_put_line(w->xw, w->y, buf);
59
get_char(struct edwin *w)
63
xio_get_line(w->xw, w->y, buf);
68
set_gfx(struct edwin *w, int i)
72
if ((c & 0xa0) != 0x20)
76
case 1: c ^= 0x10; break;
77
case 2: c ^= 0x40; break;
78
case 4: c ^= 0x04; break;
79
case 5: c ^= 0x08; break;
80
case 7: c ^= 0x01; break;
81
case 8: c ^= 0x02; break;
82
case 0: c = 0x20; break;
83
case 9: c = 0x7f; break;
84
case 3: c ^= 0x5f; break;
85
case 6: c ^= 0x5f; break;
91
set_mode(struct edwin *w, int on, int off)
96
xio_get_line(w->xw, w->y, buf);
98
for (c = x = 0; x <= w->x; ++x)
99
if (buf[x] == on || buf[x] == off)
108
del_char(struct edwin *w)
113
xio_get_line(w->xw, w->y, buf);
114
for (x = w->x; x < W-1; ++x)
117
xio_put_line(w->xw, w->y, buf);
121
ins_char(struct edwin *w, int c)
126
xio_get_line(w->xw, w->y, buf);
127
for (x = w->x; x < W; ++x)
128
t = buf[x], buf[x] = c, c = t;
129
xio_put_line(w->xw, w->y, buf);
133
del_line(struct edwin *w)
138
for (y = w->y; y < H-1; ++y)
140
xio_get_line(w->xw, y+1, buf);
141
xio_put_line(w->xw, y, buf);
146
ins_line(struct edwin *w)
152
memset(buf2, ' ', sizeof(buf2));
153
for (y = w->y; y < H; ++y)
155
xio_get_line(w->xw, y, buf);
156
xio_put_line(w->xw, y, buf2);
157
memcpy(buf2, buf, sizeof(buf2));
163
do_save(struct edwin *w, u8 *name)
170
xio_put_line(w->xw, 24, w->tmpbuf);
171
cursor(w, w->x, w->y);
173
if (name == 0 || *name == 0)
176
fp = fopen(name, "w");
182
for (y = 0; y < 25; ++y)
184
xio_get_line(w->xw, y, buf);
188
fprintf(fp, "#ifndef HELP_HEADER\n");
190
fprintf(fp, "#else\nHELP_HEADER\n#endif\n");
192
for (x = 0; x < 40; ++x)
193
if ((buf[x] & 0x7f) < 0x20 || buf[x] == 0x7f || buf[x] == '"')
195
if (x == 39 || buf[x+1] < '0' || buf[x+1] > '9')
196
fprintf(fp, "\\%o", buf[x]);
198
fprintf(fp, "\\%03o", buf[x]);
201
fprintf(fp, "%c", buf[x]);
202
fprintf(fp, "\",\n");
205
error("%s dumped", name);
209
save(struct edwin *w)
213
if (w->subno == ANY_SUB)
214
sprintf(name, "vt%03x.out", w->pgno);
216
sprintf(name, "vt%03x-%02x.out", w->pgno, w->subno & 0xff);
218
xio_get_line(w->xw, 24, w->tmpbuf);
219
w->edline = edline_new(w->xw, "Save as:\2", name, do_save, w);
224
edwin_new(struct xio *xio, struct vbi *vbi, int pgno, int subno)
231
if (not(w = malloc(sizeof(*w))))
234
if (not(w->xw = xio_open_win(xio, 0)))
240
vtp = vbi_query_page(vbi, pgno, subno);
242
for (i = 0; i < 25; ++i)
243
xio_put_line(w->xw, i, vtp->data[i]);
245
xio_clear_win(w->xw);
249
if (w->subno == ANY_SUB)
250
sprintf(buf, "Editor %03x", w->pgno);
252
sprintf(buf, "Editor %03x/%x", w->pgno, w->subno);
253
xio_title(w->xw, buf);
254
xio_set_concealed(w->xw, w->reveal = 1);
255
xio_set_handler(w->xw, edwin_event, w);
266
edwin_close(struct edwin *w)
269
edline_abort(w->edline);
270
xio_close_win(w->xw, 1);
275
ins_key(struct edwin *w, int key, int shift)
279
case '\17': /* ^O for the bullet */
295
cmd_key(struct edwin *w, int key, int shift)
300
case 'q': edwin_close(w); return 1;
302
case '\n': w->x = W; adv_cursor(w); return 1;
303
case '\t': w->mode = 1; return 2;
304
case KEY_F(1): save(w); return 1;
314
if (shift || w->x == 0)
326
case KEY_LEFT: cursor(w, w->x - 1, w->y); return 1;
327
case KEY_RIGHT: cursor(w, w->x + 1, w->y); return 1;
328
case KEY_UP: cursor(w, w->x, w->y - 1); return 1;
329
case KEY_DOWN: cursor(w, w->x, w->y + 1); return 1;
331
case 'k': /*black*/ set_char(w, 0x00); return 2;
332
case 'K': set_char(w, 0x10); return 2;
333
case 'r': /*red*/ set_char(w, 0x01); return 2;
334
case 'R': set_char(w, 0x11); return 2;
335
case 'g': /*green*/ set_char(w, 0x02); return 2;
336
case 'G': set_char(w, 0x12); return 2;
337
case 'y': /*yellow*/ set_char(w, 0x03); return 2;
338
case 'Y': set_char(w, 0x13); return 2;
339
case 'b': /*blue*/ set_char(w, 0x04); return 2;
340
case 'B': set_char(w, 0x14); return 2;
341
case 'v': /*violet*/ set_char(w, 0x05); return 2;
342
case 'V': set_char(w, 0x15); return 2;
343
case 'c': /*cyan*/ set_char(w, 0x06); return 2;
344
case 'C': set_char(w, 0x16); return 2;
345
case 'w': /*white*/ set_char(w, 0x07); return 2;
346
case 'W': set_char(w, 0x17); return 2;
348
case 's': /*new bg*/ set_char(w, 0x1d); return 2;
349
case 'S': /*blk bg*/ set_char(w, 0x1c); return 2;
350
case 'e': /*concealed*/ set_char(w, 0x18); return 2;
351
case 'E': xio_set_concealed(w->xw, w->reveal ^= 1); return 1;
353
case '0' ... '9': set_gfx(w, key - '0'); return 2;
355
case 'f': /*flash*/ set_mode(w, 0x08, 0x09); return 2;
356
case 'd': /*dbl*/ set_mode(w, 0x0d, 0x0c); return 2;
357
case 'h': /*hold gfx*/ set_mode(w, 0x1e, 0x1f); return 2;
358
case 'x': /*box*/ set_mode(w, 0x0b, 0x0a); return 2;
368
edwin_event(struct edwin *w, struct vt_event *ev)
381
i = ins_key(w, ev->i1, ev->i2);
383
i |= cmd_key(w, ev->i1, ev->i2);
385
cursor(w, w->x, w->y);
391
cursor(w, ev->i3, ev->i4);