1 | /*! |
---|
2 | * @file shell_input.h |
---|
3 | * @brief Shell Input is an InputLine for the Shell. |
---|
4 | * |
---|
5 | * @todo move around in the InputText with the cursor (SDLK_LEFT/SDLK_RIGHT) |
---|
6 | * @todo blinking curson (can blink with the speed of the RepeatDelay) |
---|
7 | */ |
---|
8 | |
---|
9 | #ifndef _SHELL_INPUT_H |
---|
10 | #define _SHELL_INPUT_H |
---|
11 | |
---|
12 | #include "text.h" |
---|
13 | #include "event_listener.h" |
---|
14 | #include "shell_completion.h" |
---|
15 | |
---|
16 | #include <list> |
---|
17 | |
---|
18 | namespace OrxShell |
---|
19 | { |
---|
20 | // FORWARD DECLARATION |
---|
21 | class ShellCompletion; |
---|
22 | |
---|
23 | //! An InputLine for the Shell |
---|
24 | /** |
---|
25 | * The ShellInput has the ability to catch and display user input. |
---|
26 | * The ShellInput is auto-completed after the user presses [TAB] |
---|
27 | * The ShellInput is executed (and sent back to the Application) on Pressing [ENTER] |
---|
28 | * [UP] and [DOWN] move through the history of allready given commands. |
---|
29 | */ |
---|
30 | class ShellInput : public Text, public EventListener |
---|
31 | { |
---|
32 | ObjectListDeclaration(ShellInput); |
---|
33 | |
---|
34 | public: |
---|
35 | ShellInput(); |
---|
36 | virtual ~ShellInput(); |
---|
37 | |
---|
38 | /** @returns the inputLine */ |
---|
39 | const std::string& getInput() const { return this->inputLine; }; |
---|
40 | |
---|
41 | // InputLine |
---|
42 | void setInputText(const std::string& text); |
---|
43 | void addCharacter(char character); |
---|
44 | void addCharacters(const std::string& characters); |
---|
45 | void removeCharacters(unsigned int characterCount = 1); |
---|
46 | void flush(); |
---|
47 | |
---|
48 | void setRepeatDelay(float repeatDelay, float repeatRate); |
---|
49 | |
---|
50 | bool executeCommand(); |
---|
51 | |
---|
52 | /** sets the count of the History's entries */ |
---|
53 | void setHistoryLength(unsigned int historyLength) { this->historyLength = historyLength; }; |
---|
54 | void historyMoveUp(); |
---|
55 | void historyMoveDown(); |
---|
56 | |
---|
57 | void help(const std::string& className = "", const std::string& function = ""); |
---|
58 | |
---|
59 | virtual void tick(float dt); |
---|
60 | virtual void process(const Event &event); |
---|
61 | |
---|
62 | private: |
---|
63 | // HANDLING TEXT INPUT |
---|
64 | ShellCompletion completion; //!< The Completion Interface. |
---|
65 | |
---|
66 | std::string inputLine; //!< the Char-Array of the Buffer |
---|
67 | float repeatRate; //!< The Repeat-Delay. |
---|
68 | float repeatDelay; //!< The delay of the first Character of a given Character. |
---|
69 | float delayed; //!< how much of the delay is remaining. |
---|
70 | Uint16 pressedKey; //!< the pressed key that will be repeated. |
---|
71 | Uint16 pressedEvent; //!< The Event, that lead to the pressing of the Key. |
---|
72 | |
---|
73 | static std::list<std::string> history; //!< The history of given commands. |
---|
74 | std::list<std::string>::iterator historyIT; //!< The locator that tells us, where we are in the history. |
---|
75 | unsigned int historyLength; //!< The maximum length of the InputHistory. |
---|
76 | bool historyScrolling; //!< true if we are scrolling through the history. |
---|
77 | }; |
---|
78 | |
---|
79 | } |
---|
80 | |
---|
81 | #endif /* _SHELL_INPUT_H */ |
---|