From 812f3f69c854a5376dc0d123c4e545cf67c8690c Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 9 Oct 2016 14:35:59 +0300 Subject: Fix printing issues --- utils.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'utils.cpp') diff --git a/utils.cpp b/utils.cpp index f118fc5..aa19c4f 100644 --- a/utils.cpp +++ b/utils.cpp @@ -2,6 +2,8 @@ #include //_getch #include //_getch #include +#include +#include /* 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(); +} -- cgit v1.3