1 // Copyright (C) 2005 Derek Scherger <derek@echologic.com>
2 // Nathaniel Smith <njs@pobox.com>
3 //
4 // This program is made available under the GNU GPL version 2.0 or
5 // greater. See the accompanying file COPYING for details.
6 //
7 // This program is distributed WITHOUT ANY WARRANTY; without even the
8 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
9 // PURPOSE.
10
11 #include "../base.hh"
12 #include <stdlib.h>
13 #include <unistd.h>
14 #include <sys/ioctl.h>
15 #include <termios.h>
16
17 #include "../platform.hh"
18
have_smart_terminal()19 bool have_smart_terminal()
20 {
21 std::string term;
22 if (const char* term_cstr = getenv("TERM"))
23 term = term_cstr;
24 else
25 term = "";
26
27 // Emacs 22.2.1 on Windows sets TERM to "emacs", but on Debian Emacs sets
28 // TERM to "dumb". The fix is to set TERM in your ~/.emacs, not to mess
29 // with this logic.
30 if (term == "" || term == "dumb" || !isatty(2))
31 return false;
32 else
33 return true;
34 }
35
terminal_width()36 unsigned int terminal_width()
37 {
38 struct winsize ws;
39 int ret = ioctl(2, TIOCGWINSZ, &ws);
40 if (ret < 0)
41 {
42 // FIXME: it would be nice to log something here
43 // but we are called by the tick printing code, and trying to print
44 // things while in the middle of printing a tick line is a great way to
45 // break things.
46 return 0;
47 }
48 return ws.ws_col;
49 }
50
51 // Local Variables:
52 // mode: C++
53 // fill-column: 76
54 // c-file-style: "gnu"
55 // indent-tabs-mode: nil
56 // End:
57 // vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:
58