ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ncxx/application.cpp
Revision: 1.2
Committed: Mon Oct 18 14:11:47 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.1: +5 -5 lines
Log Message:
check and log but do not die when ncurses stuff fails

File Contents

# User Rev Content
1 sf-pippijn 1.1 /* application.cc
2     * This file is part of ncursesxx library
3     * Copyright (c) 2003,2004 by Stanislav Ievlev
4     *
5     * This file is covered by the GNU Library General Public License,
6     * which should be included with libncursesxx as the file COPYING.
7     */
8     #include <stdexcept>
9    
10     #include <term.h>
11    
12     #include <ncurses/application.hh>
13     #include <ncurses/assert.hh>
14    
15     using ncurses::application;
16    
17     application::application ()
18     {
19     /*
20     * init ncurses enviroment
21     * We use newterm/delscreen instead of initscr to reduce number of memory leaks
22     */
23     char const *name;
24    
25     if ((name = getenv ("TERM")) == NULL || !*name)
26     name = "unknown";
27     screen_ = newterm (const_cast<char *> (name), stdout, stdin);
28    
29     if (!screen_)
30     throw runtime_error ("newterm failed");
31    
32     def_prog_mode ();
33 sf-pippijn 1.2 return_unless (cbreak () == OK);
34     return_unless (noecho () == OK);
35     return_unless (nonl () == OK);
36     return_unless (notimeout (stdscr, true) == OK);
37 sf-pippijn 1.1
38     if (has_colors ())
39 sf-pippijn 1.2 return_unless (start_color () == OK);
40 sf-pippijn 1.1
41     mousemask (ALL_MOUSE_EVENTS | REPORT_MOUSE_POSITION, nullptr);
42     cursor_off (); /* turn off cursor, by default */
43     }
44    
45     application::~application ()
46     {
47     endwin ();
48     delscreen (screen_);
49     }
50    
51     int
52     application::width () const
53     {
54     return COLS;
55     }
56    
57     int
58     application::height () const
59     {
60     return LINES;
61     }
62    
63     void
64     application::cursor_on ()
65     {
66     /* first try to made cursor super visible, otherwise made it normal */
67     curs_set (cursor_visible ? 2 : 1);
68     }
69    
70     void
71     application::cursor_off ()
72     {
73     curs_set (0); /* turn on cursor */
74     }