summaryrefslogtreecommitdiff
path: root/src/terminal.cc
blob: fd7bf98a97968a3dfb9a10aef3bbbbe1edf31466 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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 };
}