aboutsummaryrefslogtreecommitdiffstats
path: root/utils.cpp
diff options
context:
space:
mode:
authorJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-10-09 14:35:59 +0300
committerJan Tuomi <jan-sebastian.tuomi@aalto.fi>2016-10-09 14:50:24 +0300
commit812f3f69c854a5376dc0d123c4e545cf67c8690c (patch)
treec1005667afa8c79ef7e358a8ac3aadf9ed07709c /utils.cpp
parentda5ecb5de0ca0bc099258f7b77480fbb28b31392 (diff)
Fix printing issues
Diffstat (limited to 'utils.cpp')
-rw-r--r--utils.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/utils.cpp b/utils.cpp
index f118fc5..aa19c4f 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -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();
+}