summaryrefslogtreecommitdiff
path: root/src/user/app/vterm/vterm.c
blob: 76f6a17c2c314277e2a55af3898ef230ef1b4427 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "vterm.h"
#include <camellia/syscalls.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <camellia/compat.h>

struct point cursor = {0};

void in_char(char c) {
	switch (c) {
		case '\n':
			cursor.x = 0;
			cursor.y++;
			break;
		case '\b':
			if (cursor.x > 0) cursor.x--;
			break;
		default:
			font_blit(c, cursor.x, cursor.y);
			cursor.x++;
	}

	if (cursor.x * font.w >= fb.width) {
		cursor.x = 0;
		cursor.y++;
	}
	while ((cursor.y + 1) * font.h >= fb.height) scroll();
}

int main(void) {
	if (fb_setup(&fb, "/kdev/video/") < 0) {
		eprintf("fb_setup error");
		return 1;
	}
	font_load("/init/font.psf");

	static char buf[512];
	struct ufs_request res;
	while (!c0_fs_wait(buf, sizeof buf, &res)) {
		switch (res.op) {
			case VFSOP_OPEN:
				// TODO check path
				c0_fs_respond(NULL, 0, 0);
				break;

			case VFSOP_WRITE:
				if (res.flags) {
					c0_fs_respond(NULL, -1, 0);
				} else {
					for (size_t i = 0; i < res.len; i++)
						in_char(buf[i]);
					dirty_flush(&dirty, &fb);
					c0_fs_respond(NULL, res.len, 0);
				}
				break;

			default:
				c0_fs_respond(NULL, -1, 0);
				break;
		}
	}

	return 1;
}