monotone

monotone Mtn Source Tree

Root/unix/terminal.cc

1// copyright (C) 2005 derek scherger <derek@echologic.com>
2// copyright (C) 2005 nathaniel smith <njs@pobox.com>
3// all rights reserved.
4// licensed to the public under the terms of the GNU GPL (>= 2)
5// see the file COPYING for details
6
7#include "base.hh"
8#include <stdlib.h>
9#include <unistd.h>
10#include <sys/ioctl.h>
11#include <termios.h>
12
13
14#include "platform.hh"
15
16bool have_smart_terminal()
17{
18 std::string term;
19 if (const char* term_cstr = getenv("TERM"))
20 term = term_cstr;
21 else
22 term = "";
23
24 if (term == "" || term == "dumb" || !isatty(2))
25 return false;
26 else
27 return true;
28}
29
30unsigned int terminal_width()
31{
32 struct winsize ws;
33 int ret = ioctl(2, TIOCGWINSZ, &ws);
34 if (ret < 0)
35 {
36 // FIXME: it would be nice to log something here
37 // but we are called by the tick printing code, and trying to print
38 // things while in the middle of printing a tick line is a great way to
39 // break things.
40 return 0;
41 }
42 return ws.ws_col;
43}
44
45// Local Variables:
46// mode: C++
47// fill-column: 76
48// c-file-style: "gnu"
49// indent-tabs-mode: nil
50// End:
51// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status