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 <string> |
---|
36 | #include <vector> |
---|
37 | #include "util/Singleton.h" |
---|
38 | #include "core/Shell.h" |
---|
39 | |
---|
40 | #ifdef ORXONOX_PLATFORM_UNIX |
---|
41 | struct termios; |
---|
42 | #endif |
---|
43 | |
---|
44 | namespace orxonox |
---|
45 | { |
---|
46 | class _CoreExport IOConsole : public Singleton<IOConsole>, public ShellListener |
---|
47 | { |
---|
48 | friend class Singleton<IOConsole>; |
---|
49 | |
---|
50 | public: |
---|
51 | IOConsole(); |
---|
52 | ~IOConsole(); |
---|
53 | |
---|
54 | void update(const Clock& time); |
---|
55 | |
---|
56 | private: |
---|
57 | void setTerminalMode(); |
---|
58 | void resetTerminalMode(); |
---|
59 | void getTerminalSize(); |
---|
60 | bool willPrintStatusLines(); |
---|
61 | int extractLogLevel(std::string* text); |
---|
62 | |
---|
63 | void printLogText(const std::string& line); |
---|
64 | void printInputLine(); |
---|
65 | void printStatusLines(); |
---|
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 | Shell* shell_; |
---|
76 | InputBuffer* buffer_; |
---|
77 | unsigned int terminalWidth_; |
---|
78 | unsigned int terminalHeight_; |
---|
79 | unsigned int lastTerminalWidth_; |
---|
80 | unsigned int lastTerminalHeight_; |
---|
81 | bool bPrintStatusLine_; |
---|
82 | bool bStatusPrinted_; |
---|
83 | std::vector<unsigned> statusLineWidths_; |
---|
84 | unsigned int statusLineMaxWidth_; |
---|
85 | const std::string promptString_; |
---|
86 | static const unsigned minOutputLines_ = 3; |
---|
87 | |
---|
88 | #ifdef ORXONOX_PLATFORM_UNIX |
---|
89 | termios* originalTerminalSettings_; |
---|
90 | #endif |
---|
91 | |
---|
92 | static IOConsole* singletonPtr_s; |
---|
93 | }; |
---|
94 | } |
---|
95 | |
---|
96 | #endif /* _IOConsole_H__ */ |
---|