Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Performance and robustness improvements for the IOConsole under Windows.
There should only be one way to screw the console now: Change the console properties manually at runtime (right click on the taskbar icon), esp. screen buffer size.
If you can find another bug, please let me know.

  • Property svn:eol-style set to native
File size: 3.7 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        int extractLogLevel(std::string* text);
65
66        void printStatusLines();
67
68        // Methods from ShellListener
69        void linesChanged();
70        void onlyLastLineChanged();
71        void lineAdded();
72        void inputChanged();
73        void cursorChanged();
74        void executed();
75        void exit();
76        Shell*                  shell_;
77        InputBuffer*            buffer_;
78        std::ostream            cout_;
79        std::ostringstream      origCout_;
80        unsigned int            terminalWidth_;
81        unsigned int            terminalHeight_;
82        unsigned int            lastTerminalWidth_;
83        unsigned int            lastTerminalHeight_;
84        const std::string       promptString_;
85
86#ifdef ORXONOX_PLATFORM_UNIX
87        bool willPrintStatusLines();
88        void printOutputLine(const std::string& line);
89        void printInputLine();
90        static void resetTerminalMode();
91
92        bool                    bPrintStatusLine_;
93        bool                    bStatusPrinted_;
94        std::vector<unsigned>   statusLineWidths_;
95        unsigned int            statusLineMaxWidth_;
96        static const unsigned   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(unsigned int lines);
104        void printOutputLine(const std::string& line, const COORD& pos);
105
106        DWORD                   originalTerminalSettings_;
107        HANDLE                  stdInHandle_;
108        HANDLE                  stdOutHandle_;
109        int                     inputLineRow_;
110        unsigned int            inputLineHeight_;
111        const unsigned int      statusLines_;
112        unsigned int            lastOutputLineHeight_;
113        uint64_t                lastRefreshTime_;
114#endif
115
116        static IOConsole* singletonPtr_s;
117    };
118}
119
120#endif /* _IOConsole_H__ */
Note: See TracBrowser for help on using the repository browser.