summaryrefslogtreecommitdiff
path: root/Source/Library/Userland/Binding/VirtualTerminal.class.h
blob: 2a38abd3dc1ada1674fff4127409519164c4e6a1 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef DEF_VIRTUALTERMINAL_CLASS_H
#define DEF_VIRTUALTERMINAL_CLASS_H

#include <Syscall/RessourceCaller.class.h>

#include <VirtualTerminal.iface.h>
#include <Kbd.iface.h>

#include <OStream.proto.h>
#include <IStream.proto.h>
#include <WChar.class.h>

class VirtualTerminal : public RessourceCaller, public OStream, public IStream {
	private:
	bool m_eof;

	public:
	static VirtualTerminal getIn() {
		u32int id = RessourceCaller::sCall(VTIF_OBJTYPE, VTIF_SGETPRINVT);
		return VirtualTerminal(id);
	}
	static VirtualTerminal getOut() {
		u32int id = RessourceCaller::sCall(VTIF_OBJTYPE, VTIF_SGETPROUTVT);
		return VirtualTerminal(id);
	}
	VirtualTerminal(u32int id) : RessourceCaller(id, VTIF_OBJTYPE) { m_eof = false; }

	/*void writeHex(u32int number) {
		doCall(VTIF_WRITEHEX, number);
	}
	void writeDec(s64int number) {
		doCall(VTIF_WRITEDEC, (number >> 32), number);
	}*/
	void write(const String &s) {
		doCall(VTIF_WRITE, (u32int)&s);
	}
	String read() {
		if (m_eof) return "";
		String ret = String::unserialize(doCall(VTIF_READLINE, 1));
		if (ret[ret.size() - 1] == WChar(EOF)) {
			ret = ret.substr(0, ret.size() - 1);
			if (ret.empty()) return "";
			m_eof = true;
		}
		return ret += "\n";
	}
	keypress_t getKeypress(bool show = true, bool block = true) {
		keypress_t* ptr = (keypress_t*)doCall(VTIF_GETKEYPRESS, (show ? 1 : 0) | (block ? 2 : 0));
		return *ptr;
	}
	String readLine(bool show = true) {
		flush();
		return String::unserialize(doCall(VTIF_READLINE, (show ? 1 : 0)));
	}
	void setColor(u8int fg, u8int bg = 0xFF) {
		doCall(VTIF_SETCOLOR, (fg << 8) | bg);
	}
	void setCsrLine(u32int line) {
		doCall(VTIF_SETCSRLINE, line);
	}
	void setCsrCol(u32int col) {
		doCall(VTIF_SETCSRCOL, col);
	}
	bool isBoxed() {
		return doCall(VTIF_ISBOXED) != 0;
	}
	u8int height() {
		return doCall(VTIF_GETHEIGHT);
	}
	u8int width() {
		return doCall(VTIF_GETWIDTH);
	}
	void put(WChar c) {
		doCall(VTIF_PUT, c);
	}
	void moveCursor(u8int line, u8int col) {
		doCall(VTIF_LOCATE, line, col);
	}
	void put(u8int line, u8int col, WChar c) {
		moveCursor(line, col); put(c);
	}
};

#endif