1#ifndef __CPP_CONSOLE_CURSOR_HPP__
2#define __CPP_CONSOLE_CURSOR_HPP__
30 CONSOLE_SCREEN_BUFFER_INFO cbsi;
31 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cbsi);
32 return {cbsi.dwCursorPosition.X, cbsi.dwCursorPosition.Y};
35 struct termios term, term_orig;
36 tcgetattr(STDIN_FILENO, &term);
39 term.c_lflag &= ~(ICANON | ECHO);
40 tcsetattr(STDIN_FILENO, TCSANOW, &term);
41 std::cout <<
"\033[6n";
45 std::cin >> ignore >> coord.
X;
49 tcsetattr(STDIN_FILENO, TCSANOW, &term_orig);
59 std::cout <<
"\033[H";
63 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
64 if (hConsole == INVALID_HANDLE_VALUE) {
65 std::cerr <<
"Error: Unable to get console handle." << std::endl;
68 COORD homeCoords = {0, 0};
69 SetConsoleCursorPosition(hConsole, homeCoords);
81 std::cout <<
"\033[" << std::to_string(row) <<
";"
82 << std::to_string(col) <<
"H";
86 HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
87 if (hConsole == INVALID_HANDLE_VALUE) {
88 std::cerr <<
"Error: Unable to get console handle." << std::endl;
94 SetConsoleCursorPosition(hConsole, coord);
105 std::cout <<
"\033[" << std::to_string(n) <<
"A";
121 std::cout <<
"\033[" << std::to_string(n) <<
"B";
137 std::cout <<
"\033[" << std::to_string(n) <<
"C";
153 std::cout <<
"\033[" << std::to_string(n) <<
"D";
169 std::cout <<
"\033[" << std::to_string(n) <<
"E";
185 std::cout <<
"\033[" << std::to_string(n) <<
"F";
201 std::cout <<
"\033[" << std::to_string(n) <<
"G";
Namespace Containing all console commands.
Definition ansi.hpp:16
void moveCursorLeft(int n)
Move the cursor left by n lines.
Definition cursor.hpp:151
ConsoleCoord getCursorPosition()
Gets the position of the cursor within the console.
Definition cursor.hpp:28
void moveCursorRight(int n)
Move the cursor right by n lines.
Definition cursor.hpp:135
void moveCursorToColumn(int n)
Moves cursor to column n.
Definition cursor.hpp:199
void moveCursorDown(int n)
Move the cursor down by n lines.
Definition cursor.hpp:119
void moveCursorDownAndToStart(int n)
Moves cursor to beginning of next line, n lines down.
Definition cursor.hpp:167
void moveCursorUpAndToStart(int n)
Moves cursor to beginning of previous line, n lines up.
Definition cursor.hpp:183
void moveCursorToPosition(int row, int col)
Move the cursor to the specified position in the console.
Definition cursor.hpp:79
void moveCursorUp(int n)
Move the cursor up by n lines.
Definition cursor.hpp:103
bool isANSIEnabled()
Checks if ANSI Codes are enable in windows.
Definition ansi.hpp:22
void moveCursorHome()
Moves cursor to home position (0, 0)
Definition cursor.hpp:57
A position on the console (row and column)
Definition data.hpp:13
int X
Definition data.hpp:14
int Y
Definition data.hpp:15