[5971] | 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: |
---|
[5968] | 23 | * Oliver Scheuss |
---|
| 24 | * Reto Grieder |
---|
[5971] | 25 | * Co-authors: |
---|
| 26 | * ... |
---|
| 27 | * |
---|
| 28 | */ |
---|
| 29 | |
---|
| 30 | #ifndef _IOConsole_H__ |
---|
| 31 | #define _IOConsole_H__ |
---|
| 32 | |
---|
| 33 | #include "CorePrereqs.h" |
---|
| 34 | |
---|
[6037] | 35 | #include <sstream> |
---|
[6015] | 36 | #include <string> |
---|
| 37 | #include <vector> |
---|
[5971] | 38 | #include "util/Singleton.h" |
---|
| 39 | #include "core/Shell.h" |
---|
| 40 | |
---|
[6015] | 41 | #ifdef ORXONOX_PLATFORM_UNIX |
---|
[5971] | 42 | struct termios; |
---|
[6140] | 43 | #elif defined(ORXONOX_PLATFORM_WINDOWS) |
---|
| 44 | #define WIN32_LEAN_AND_MEAN |
---|
[6177] | 45 | #define NOMINMAX |
---|
[6140] | 46 | #include <windows.h> |
---|
[6015] | 47 | #endif |
---|
[5971] | 48 | |
---|
| 49 | namespace 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(); |
---|
[6013] | 63 | void getTerminalSize(); |
---|
[5995] | 64 | void printStatusLines(); |
---|
[6178] | 65 | static int extractLogLevel(std::string* text); |
---|
[5971] | 66 | |
---|
| 67 | // Methods from ShellListener |
---|
| 68 | void linesChanged(); |
---|
| 69 | void onlyLastLineChanged(); |
---|
| 70 | void lineAdded(); |
---|
| 71 | void inputChanged(); |
---|
| 72 | void cursorChanged(); |
---|
[5983] | 73 | void executed(); |
---|
[5971] | 74 | void exit(); |
---|
[6178] | 75 | |
---|
[6004] | 76 | Shell* shell_; |
---|
[5971] | 77 | InputBuffer* buffer_; |
---|
[6037] | 78 | std::ostream cout_; |
---|
| 79 | std::ostringstream origCout_; |
---|
[6178] | 80 | int terminalWidth_; |
---|
| 81 | int terminalHeight_; |
---|
| 82 | int lastTerminalWidth_; |
---|
| 83 | int lastTerminalHeight_; |
---|
[6177] | 84 | const std::string promptString_; |
---|
| 85 | |
---|
| 86 | #ifdef ORXONOX_PLATFORM_UNIX |
---|
| 87 | bool willPrintStatusLines(); |
---|
[6178] | 88 | void printInputLine(); |
---|
[6177] | 89 | void printOutputLine(const std::string& line); |
---|
| 90 | static void resetTerminalMode(); |
---|
| 91 | |
---|
[5995] | 92 | bool bPrintStatusLine_; |
---|
| 93 | bool bStatusPrinted_; |
---|
[6178] | 94 | std::vector<int> statusLineWidths_; |
---|
| 95 | int statusLineMaxWidth_; |
---|
[6179] | 96 | static const int minOutputLines_ = 3; |
---|
[6177] | 97 | termios* originalTerminalSettings_; |
---|
[5971] | 98 | |
---|
[6140] | 99 | #elif defined(ORXONOX_PLATFORM_WINDOWS) |
---|
[6177] | 100 | void resetTerminalMode(); |
---|
[6140] | 101 | void moveCursor(int dx, int dy); |
---|
[6177] | 102 | void writeText(const std::string& text, const COORD& pos, WORD attributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED); |
---|
[6178] | 103 | void createNewOutputLines(int lines); |
---|
[6177] | 104 | void printOutputLine(const std::string& line, const COORD& pos); |
---|
[6140] | 105 | |
---|
[6178] | 106 | static inline COORD makeCOORD(int x, int y) |
---|
| 107 | { |
---|
| 108 | COORD val = {x, y}; |
---|
| 109 | return val; |
---|
| 110 | } |
---|
| 111 | |
---|
[6140] | 112 | DWORD originalTerminalSettings_; |
---|
| 113 | HANDLE stdInHandle_; |
---|
| 114 | HANDLE stdOutHandle_; |
---|
[6177] | 115 | int inputLineRow_; |
---|
[6178] | 116 | int inputLineHeight_; |
---|
| 117 | const int statusLines_; |
---|
| 118 | int lastOutputLineHeight_; |
---|
[6177] | 119 | uint64_t lastRefreshTime_; |
---|
[6015] | 120 | #endif |
---|
| 121 | |
---|
[5971] | 122 | static IOConsole* singletonPtr_s; |
---|
| 123 | }; |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | #endif /* _IOConsole_H__ */ |
---|