File: console.cc

package info (click to toggle)
snapper 0.2.4-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,576 kB
  • ctags: 2,049
  • sloc: cpp: 15,605; sh: 11,424; ansic: 1,401; makefile: 287; python: 159
file content (36 lines) | stat: -rw-r--r-- 815 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*---------------------------------------------------------------------------*\
                          ____  _ _ __ _ __  ___ _ _
                         |_ / || | '_ \ '_ \/ -_) '_|
                         /__|\_, | .__/ .__/\___|_|
                             |__/|_|  |_|
\*---------------------------------------------------------------------------*/

/** \file console.cc
 * Miscellaneous console utilities.
 */

#include <unistd.h>
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>

using namespace std;

unsigned get_screen_width()
{
  if (!::isatty(STDOUT_FILENO))
    return -1; // no clipping

  int width = 80;

  const char *cols_env = getenv("COLUMNS");
  if (cols_env)
    width  = ::atoi (cols_env);

  // safe default
  if (!width)
    width = 80;

  return width;
}