summaryrefslogtreecommitdiff
path: root/Source/Kernel/VTManager/VirtualTerminal.class.h
blob: 6a140807c56871924afd491f9cf94412dcc635f4 (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
#ifndef DEF_VIRTUALTERMINAL_CLASS_H
#define DEF_VIRTUALTERMINAL_CLASS_H

#include <Core/common.wtf.h>
#include <Library/String.class.h>
#include <TaskManager/Mutex.class.h>
#include <DeviceManager/Kbd.ns.h>
#include <Library/Vector.class.h>

struct chr {
	u8int color;
	wchar c;
	};

class VirtualTerminal {
	private:
	chr* m_buff;
	u32int m_rows, m_cols;
	u8int m_color;

	u32int m_maprow, m_mapcol;
	bool m_mapped;
	
	u32int m_csrlin, m_csrcol;

	Mutex m_kbdMutex;
	Vector<Kbd::keypress_t> m_kbdbuff;	//Key press events buffer

	public:
	VirtualTerminal(u32int rows, u32int cols, u8int fgcolor = 7, u8int bgcolor = 0);
	~VirtualTerminal();

	void setColor(u8int fgcolor, u8int bgcolor = 0xFF);
	void putChar(u32int row, u32int col, wchar c);
	void clear();

	void map(s32int row = -1, s32int col = -1);
	void unmap();
	void redraw();
	void scroll();	//Scrolls 1 line

	void updateCursor();
	void moveCursor(u32int row, u32int col);
	void setCursorLine(u32int line);
	void setCursorCol(u32int col);

	//Display functions
	void put(wchar c, bool updatecsr = true);
	void write(String s, bool updatecsr = true);
	void writeDec(s32int i, bool updatecsr = true);
	void writeHex(u32int i, bool updatecsr = true);
	
	inline VirtualTerminal& operator<<(String s) { write(s); return *this; }
	//inline VirtualTerminal& operator<<(wchar c) { put(c); return *this; }
	inline VirtualTerminal& operator<<(s32int i) { writeDec(i); return *this; }
	inline VirtualTerminal& operator<<(u32int i) { writeHex(i); return *this; }

	//Keyboard functions
	void keyPress(Kbd::keypress_t kp);	//Called by Kbd:: when a key is pressed
	Kbd::keypress_t getKeypress(bool show = true, bool block = true);	//Block : must we wait for a key to be pressed ?
	String readLine(bool show = true);
};

#endif