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 <stdlib.h>
8#include <unistd.h>
9#include <sys/ioctl.h>
10#include <termios.h>
11
12#include <string>
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 == "emacs" || term == "dumb"
25 || !isatty(2))
26 return false;
27 else
28 return true;
29}
30
31unsigned int terminal_width()
32{
33 struct winsize ws;
34 int ret = ioctl(2, TIOCGWINSZ, &ws);
35 if (ret < 0)
36 {
37 // FIXME: it would be nice to log something here
38 // but we are called by the tick printing code, and trying to print
39 // things while in the middle of printing a tick line is a great way to
40 // break things.
41 return 0;
42 }
43 return ws.ws_col;
44}
45
46// Local Variables:
47// mode: C++
48// fill-column: 76
49// c-file-style: "gnu"
50// indent-tabs-mode: nil
51// End:
52// 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