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 |
---|
42 | struct termios; |
---|
43 | #elif defined(ORXONOX_PLATFORM_WINDOWS) |
---|
44 | #define WIN32_LEAN_AND_MEAN |
---|
45 | #include <windows.h> |
---|
46 | #endif |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | class _CoreExport IOConsole : public Singleton<IOConsole>, public ShellListener |
---|
51 | { |
---|
52 | friend class Singleton<IOConsole>; |
---|
53 | |
---|
54 | public: |
---|
55 | IOConsole(); |
---|
56 | ~IOConsole(); |
---|
57 | |
---|
58 | void update(const Clock& time); |
---|
59 | |
---|
60 | private: |
---|
61 | void setTerminalMode(); |
---|
62 | void resetTerminalMode(); |
---|
63 | void getTerminalSize(); |
---|
64 | bool willPrintStatusLines(); |
---|
65 | int extractLogLevel(std::string* text); |
---|
66 | |
---|
67 | void printLogText(const std::string& line); |
---|
68 | void printInputLine(); |
---|
69 | void printStatusLines(); |
---|
70 | |
---|
71 | // Methods from ShellListener |
---|
72 | void linesChanged(); |
---|
73 | void onlyLastLineChanged(); |
---|
74 | void lineAdded(); |
---|
75 | void inputChanged(); |
---|
76 | void cursorChanged(); |
---|
77 | void executed(); |
---|
78 | void exit(); |
---|
79 | Shell* shell_; |
---|
80 | InputBuffer* buffer_; |
---|
81 | std::ostream cout_; |
---|
82 | std::ostringstream origCout_; |
---|
83 | unsigned int terminalWidth_; |
---|
84 | unsigned int terminalHeight_; |
---|
85 | unsigned int lastTerminalWidth_; |
---|
86 | unsigned int lastTerminalHeight_; |
---|
87 | bool bPrintStatusLine_; |
---|
88 | bool bStatusPrinted_; |
---|
89 | std::vector<unsigned> statusLineWidths_; |
---|
90 | unsigned int statusLineMaxWidth_; |
---|
91 | const std::string promptString_; |
---|
92 | static const unsigned minOutputLines_ = 3; |
---|
93 | |
---|
94 | #ifdef ORXONOX_PLATFORM_UNIX |
---|
95 | termios* originalTerminalSettings_; |
---|
96 | #elif defined(ORXONOX_PLATFORM_WINDOWS) |
---|
97 | void moveCursor(int dx, int dy); |
---|
98 | void moveCursorYAndHome(int dy); |
---|
99 | void clearCurrentLine(); |
---|
100 | |
---|
101 | DWORD originalTerminalSettings_; |
---|
102 | HANDLE stdInHandle_; |
---|
103 | HANDLE stdOutHandle_; |
---|
104 | #endif |
---|
105 | |
---|
106 | static IOConsole* singletonPtr_s; |
---|
107 | }; |
---|
108 | } |
---|
109 | |
---|
110 | #endif /* _IOConsole_H__ */ |
---|