diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 967a6f0049..f23a2b711d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") include_directories(../ext-src/gtest/fused-src impl) link_directories(${monad_native_BINARY_DIR}) -set(LIB_SOURCE_FILES impl/getcurrentprocessorid.cpp impl/getusername.cpp) +set(LIB_SOURCE_FILES impl/getcurrentprocessorid.cpp impl/getusername.cpp impl/terminal.cpp) set(TEST_SOURCE_FILES tests/test-getcurrentprocessid.cpp) set(SOURCE_FILES main.cpp ../ext-src/gtest/fused-src/gtest/gtest-all.cc) diff --git a/src/impl/pal.h b/src/impl/pal.h index 1cfc776302..f981088843 100644 --- a/src/impl/pal.h +++ b/src/impl/pal.h @@ -54,6 +54,7 @@ typedef char BOOL; typedef unsigned short WCHAR_T; typedef unsigned int UINT32; + typedef int INT32; typedef unsigned long HRESULT; typedef const wchar_t *PCWSTR; typedef wchar_t *PWSTR; diff --git a/src/impl/terminal.cpp b/src/impl/terminal.cpp new file mode 100644 index 0000000000..c321928020 --- /dev/null +++ b/src/impl/terminal.cpp @@ -0,0 +1,21 @@ +#include "terminal.h" +#include + +INT32 GetTerminalWidth() +{ + struct winsize ws; + if (-1 == ioctl(0,TIOCGWINSZ,&ws)) + return -1; + + return ws.ws_col; +} + +INT32 GetTerminalHeight() +{ + struct winsize ws; + if (-1 == ioctl(0,TIOCGWINSZ,&ws)) + return -1; + + return ws.ws_row; +} + diff --git a/src/impl/terminal.h b/src/impl/terminal.h new file mode 100644 index 0000000000..00332e9bf5 --- /dev/null +++ b/src/impl/terminal.h @@ -0,0 +1,11 @@ +#pragma once + +#include "pal.h" + +PAL_BEGIN_EXTERNC + +INT32 GetTerminalWidth(); +INT32 GetTerminalHeight(); + +PAL_END_EXTERNC +