Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation2/src/libraries/core/IOConsole.h @ 6179

Last change on this file since 6179 was 6179, checked in by rgrieder, 14 years ago

Fixed Linux build and removed a warning

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Oliver Scheuss
24 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30#ifndef _IOConsole_H__
31#define _IOConsole_H__
32
33#include "CorePrereqs.h"
34
35#include <sstream>
36#include <string>
37#include <vector>
38#include "util/Singleton.h"
39#include "core/Shell.h"
40
41#ifdef ORXONOX_PLATFORM_UNIX
42struct termios;
43#elif defined(ORXONOX_PLATFORM_WINDOWS)
44#define WIN32_LEAN_AND_MEAN
45#define NOMINMAX
46#include <windows.h>
47#endif
48
49namespace orxonox
50{
51    class _CoreExport IOConsole : public Singleton<IOConsole>, public ShellListener
52    {
53        friend class Singleton<IOConsole>;
54
55    public:
56        IOConsole();
57        ~IOConsole();
58
59        void update(const Clock& time);
60
61    private:
62        void setTerminalMode();
63        void getTerminalSize();
64        void printStatusLines();
65        static int extractLogLevel(std::string* text);
66
67        // Methods from ShellListener
68        void linesChanged();
69        void onlyLastLineChanged();
70        void lineAdded();
71        void inputChanged();
72        void cursorChanged();
73        void executed();
74        void exit();
75
76        Shell*                  shell_;
77        InputBuffer*            buffer_;
78        std::ostream            cout_;
79        std::ostringstream      origCout_;
80        int                     terminalWidth_;
81        int                     terminalHeight_;
82        int                     lastTerminalWidth_;
83        int                     lastTerminalHeight_;
84        const std::string       promptString_;
85
86#ifdef ORXONOX_PLATFORM_UNIX
87        bool willPrintStatusLines();
88        void printInputLine();
89        void printOutputLine(const std::string& line);
90        static void resetTerminalMode();
91
92        bool                    bPrintStatusLine_;
93        bool                    bStatusPrinted_;
94        std::vector<int>        statusLineWidths_;
95        int                     statusLineMaxWidth_;
96        static const int        minOutputLines_ = 3;
97        termios*                originalTerminalSettings_;
98
99#elif defined(ORXONOX_PLATFORM_WINDOWS)
100        void resetTerminalMode();
101        void moveCursor(int dx, int dy);
102        void writeText(const std::string& text, const COORD& pos, WORD attributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED);
103        void createNewOutputLines(int lines);
104        void printOutputLine(const std::string& line, const COORD& pos);
105
106        static inline COORD makeCOORD(int x, int y)
107        {
108            COORD val = {x, y};
109            return val;
110        }
111
112        DWORD                   originalTerminalSettings_;
113        HANDLE                  stdInHandle_;
114        HANDLE                  stdOutHandle_;
115        int                     inputLineRow_;
116        int                     inputLineHeight_;
117        const int               statusLines_;
118        int                     lastOutputLineHeight_;
119        uint64_t                lastRefreshTime_;
120#endif
121
122        static IOConsole* singletonPtr_s;
123    };
124}
125
126#endif /* _IOConsole_H__ */
Note: See TracBrowser for help on using the repository browser.