koutil
Loading...
Searching...
No Matches
commands.h
Go to the documentation of this file.
1#ifndef KOUTIL_TERM_COMMANDS_H
2#define KOUTIL_TERM_COMMANDS_H
3
4#include "koutil/util/utils.h"
5#include <ostream>
6
7namespace koutil::term {
11struct CursorPos {
12 unsigned short line;
13 unsigned short column;
14};
15
19struct CursorMove {
23 enum Type : char {
24 MOVE_UP = 'A',
25 MOVE_DOWN = 'B',
26 MOVE_LEFT = 'C',
31 };
32
33 unsigned short move;
35};
36
40enum class CursorCommand {
41 MOVE_HOME,
42 SAVE,
43 RESTORE,
44 HIDE,
45 SHOW,
46};
47
51enum class BufferCommand : char {
54};
55
67
68std::ostream& operator<<(std::ostream& stream, CursorPos pos) {
69 stream << util::ESC << '[' << pos.line << ';' << pos.column << 'H';
70 return stream;
71}
72
73std::ostream& operator<<(std::ostream& stream, CursorMove move) {
74 stream << util::ESC << '[' << move.move << static_cast<char>(move.type);
75 return stream;
76}
77
78std::ostream& operator<<(std::ostream& stream, CursorCommand cmd) {
79 stream << util::ESC;
80
81 switch (cmd) {
83 stream << "[H";
84 break;
86 stream << " 7";
87 break;
89 stream << " 8";
90 break;
92 stream << "[?25l";
93 break;
95 stream << "[?25h";
96 break;
97 }
98
99 return stream;
100}
101
102std::ostream& operator<<(std::ostream& stream, BufferCommand cmd) {
103 stream << util::ESC << "[?1049" << static_cast<char>(cmd);
104 return stream;
105}
106
107std::ostream& operator<<(std::ostream& stream, EraseCommand cmd) {
108 stream << util::ESC << '[';
109
110 switch (cmd) {
112 stream << "0J";
113 break;
115 stream << "1J";
116 break;
118 stream << "2J";
119 break;
121 stream << "0K";
122 break;
124 stream << "1K";
125 break;
127 stream << "2K";
128 break;
129 }
130
131 return stream;
132}
133
134}
135
136#endif
Definition color.h:11
std::ostream & operator<<(std::ostream &stream, ColorBG bg)
Definition color_operators.h:52
CursorCommand
Enumerates different cursor commands.
Definition commands.h:40
BufferCommand
Enumerates different buffer commands.
Definition commands.h:51
EraseCommand
Enumerates different erase commands.
Definition commands.h:59
constexpr char ESC
Definition utils.h:20
Represents a cursor movement command.
Definition commands.h:19
Type type
Definition commands.h:34
unsigned short move
Definition commands.h:33
Type
Enumerates different types of cursor movements.
Definition commands.h:23
@ MOVE_DOWN_BEGIN_LINE
Definition commands.h:28
@ MOVE_LEFT
Definition commands.h:26
@ MOVE_UP
Definition commands.h:24
@ MOVE_DOWN
Definition commands.h:25
@ MOVE_COLUMN
Definition commands.h:30
@ MOVE_RIGHT
Definition commands.h:27
@ MOVE_UP_BEGIN_LINE
Definition commands.h:29
Represents a cursor movement command.
Definition commands.h:11
unsigned short column
Definition commands.h:13
unsigned short line
Definition commands.h:12