support full-width/composite characters and true color palette in terminal (#1386)
[far2l.git] / WinPort / src / Backend / TTY / TTYOutput.h
blob7ff4b3dfd5dc1f9b79de15a809bd274ea5eb1df2
1 #pragma once
2 #include <stdexcept>
3 #include <vector>
4 #include <map>
5 #include <WinCompat.h>
6 #include <StackSerializer.h>
8 class TTYOutput
10 struct Cursor
12 unsigned int y = -1, x = -1;
13 bool visible = false;
14 } _cursor;
16 std::vector<char> _rawbuf;
17 struct {
18 WCHAR wch = 0;
19 unsigned int count = 0;
20 std::string tmp;
21 } _same_chars;
23 struct TrueColors {
24 void AppendSuffix(std::string &out, DWORD rgb);
25 std::map<DWORD, BYTE> _colors256_lookup;
26 } _true_colors;
28 int _out;
29 bool _far2l_tty, _kernel_tty;
30 bool _prev_attr_valid{false};
31 DWORD64 _prev_attr{};
32 std::string _tmp_attrs;
34 void WriteReally(const char *str, int len);
35 void FinalizeSameChars();
36 void WriteWChar(WCHAR wch);
37 void Write(const char *str, int len);
38 void Format(const char *fmt, ...);
40 void AppendTrueColorSuffix(std::string &out, DWORD rgb);
41 void WriteUpdatedAttributes(DWORD64 new_attr, bool is_space);
43 public:
44 TTYOutput(int out, bool far2l_tty);
45 ~TTYOutput();
47 void Flush();
49 void ChangeCursorHeight(unsigned int height);
50 void ChangeCursor(bool visible, bool force = false);
51 int WeightOfHorizontalMoveCursor(unsigned int y, unsigned int x) const;
52 void MoveCursorStrict(unsigned int y, unsigned int x);
53 void MoveCursorLazy(unsigned int y, unsigned int x);
54 void WriteLine(const CHAR_INFO *ci, unsigned int cnt);
55 void ChangeKeypad(bool app);
56 void ChangeMouse(bool enable);
57 void ChangeTitle(std::string title);
59 void SendFar2lInterract(const StackSerializer &stk_ser);