Files
indicators/include/indicators/cursor_movement.hpp
Pranav Srinivas Kumar 296bde6088 Minor bug fixes and updates:
* Removed progress bar sample that progresses in reverse direction - This needs a class of its own
* Fixed a casting error in progress_bar class when dealing with max_progress variable
* Minor update to the cursor movement functions in linux
* Updated single include to include these changes
2020-05-08 15:14:52 -05:00

46 lines
1.1 KiB
C++
Executable File

#pragma once
#if defined(_MSC_VER)
#if !defined(NOMINMAX)
#define NOMINMAX
#endif
#include <io.h>
#include <windows.h>
#else
#include <iostream>
#endif
namespace indicators {
#ifdef _MSC_VER
void move(int x, int y) {
auto hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
if (!hStdout)
return;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
GetConsoleScreenBufferInfo(hStdout, &csbiInfo);
COORD cursor;
cursor.X = csbiInfo.dwCursorPosition.X + x;
cursor.Y = csbiInfo.dwCursorPosition.Y + y;
SetConsoleCursorPosition(hStdout, cursor);
}
void move_up(int lines) { move(0, -lines); }
void move_down(int lines) { move(0, -lines); }
void move_right(int cols) { move(cols, 0); }
void move_left(int cols) { move(-cols, 0); }
#else
void move_up(int lines) { std::cout << "\033[" << lines << "A"; }
void move_down(int lines) { std::cout << "\033[" << lines << "B"; }
void move_right(int cols) { std::cout << "\033[" << cols << "C"; }
void move_left(int cols) { std::cout << "\033[" << cols << "D"; }
#endif
} // namespace indicators