diff options
| author | Joel Klinghed <the_jk@yahoo.com> | 2017-02-28 21:50:44 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@yahoo.com> | 2017-02-28 21:50:44 +0100 |
| commit | c029d90d1975e124d237605f1edb2be16bd05b5d (patch) | |
| tree | 9df87ffb365354bdb74a969440b32c8304bdbcb7 /src/terminal.cc | |
Initial commit
Diffstat (limited to 'src/terminal.cc')
| -rw-r--r-- | src/terminal.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/terminal.cc b/src/terminal.cc new file mode 100644 index 0000000..fd7bf98 --- /dev/null +++ b/src/terminal.cc @@ -0,0 +1,20 @@ +// -*- mode: c++; c-basic-offset: 2; -*- + +#include "common.hh" + +#include <cstring> +#include <sys/ioctl.h> +#include <unistd.h> + +#include "terminal.hh" + +// static +Terminal::Size Terminal::size() { + struct winsize size; + memset(&size, 0, sizeof(size)); + ioctl(STDOUT_FILENO, TIOCGWINSZ, &size); + if (size.ws_col == 0 || size.ws_row == 0) { + return { .width = 80, .height = 25 }; + } + return { .width = size.ws_col, .height = size.ws_row }; +} |
