summaryrefslogtreecommitdiff
path: root/src/kernel/ui/vt.h
blob: 8a169b44ad5d032849bfc46057f803a455794fb3 (plain) (blame)
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
#ifndef DEF_UI_VT_H
#define DEF_UI_VT_H

#include <vfs/node.h>
#include <dev/display.h>
#include <dev/keyboard.h>

#define KBD_BUFFER_SIZE 256

struct vt_char {
	int ch;
	uint8_t fgcolor, bgcolor;
};

class vt : public node {
	private:
	display *output;
	int w, h, csr_l, csr_c, save_csr_l, save_csr_c;
	vt_char *text;

	void put_at(int l, int c, int ch);
	bool cursor_visible;

	int kbd_buffer_filled;
	char kbd_buffer[KBD_BUFFER_SIZE];
	thread *kbd_waiter;

	public:
	uint8_t fgcolor, bgcolor;

	vt(node* parent, int w, int h);
	virtual ~vt() {}
	virtual vt* as_vt() { return this; }

	// internal use
	void put(int c);
	void clear();
	void scroll(int l);
	void writeStr(char* str) { write(0, strlen(str), str); }
	void writeHex(uint32_t v);
	void writeDec(int v);
	// shortcuts
	vt& operator<< (char* str) { writeStr(str); return *this; }
	vt& operator<< (uint32_t t) { writeHex(t); return *this; }
	vt& operator<< (int i) { writeDec(i); return *this; }


	void outputTo(display *display);
	void keyboardInput(keypress kp, keyboard* from);

	virtual int write(size_t offset, size_t len, char* buffer);
	virtual int read(size_t offset, size_t len, char* buffer);		// get keyboard input
	virtual size_t get_size();
	virtual int link(node* to, int mode);
};

extern vt *ke_vt, *home_vt;
#define NL ke_vt->writeStr("\n");
#define TAB ke_vt->writeStr("\t");
#define WHERE { ke_vt->writeStr("(ke:");	\
				ke_vt->writeStr(__FILE__);	\
				ke_vt->writeStr(":");		\
				ke_vt->writeDec(__LINE__);	\
				ke_vt->writeStr(")  "); }

#endif