diff options
| author | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-10-09 14:35:59 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan-sebastian.tuomi@aalto.fi> | 2016-10-09 14:50:24 +0300 |
| commit | 812f3f69c854a5376dc0d123c4e545cf67c8690c (patch) | |
| tree | c1005667afa8c79ef7e358a8ac3aadf9ed07709c /utils.cpp | |
| parent | da5ecb5de0ca0bc099258f7b77480fbb28b31392 (diff) | |
Fix printing issues
Diffstat (limited to 'utils.cpp')
| -rw-r--r-- | utils.cpp | 23 |
1 files changed, 22 insertions, 1 deletions
@@ -2,6 +2,8 @@ #include <unistd.h> //_getch #include <termios.h> //_getch #include <stdio.h> +#include <sys/ioctl.h> +#include <iostream> /* Thanks to StackOverflow user mf_ */ char Utils::getch(){ @@ -24,4 +26,23 @@ char Utils::getch(){ perror ("tcsetattr ~ICANON"); //printf("%c\n",buf); return buf; - } +} + +int Utils::window_height() { + struct winsize w; + ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); + + return w.ws_row; +} + +void Utils::clear_screen() { + int height = window_height(); + for (int i = 0; i < height; i++) { + std::cout << '\n'; + } +} + +int Utils::count_digits(int num) { + std::string repr = std::to_string(num); + return repr.size(); +} |
