CLI  2.9
shell.h
Go to the documentation of this file.
1 /*
2  Copyright (c) 2006-2018, Alexis Royer, http://alexis.royer.free.fr/CLI
3 
4  All rights reserved.
5 
6  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation
10  and/or other materials provided with the distribution.
11  * Neither the name of the CLI library project nor the names of its contributors may be used to endorse or promote products derived from this software
12  without specific prior written permission.
13 
14  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
18  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22  LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23  NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26 
27 
31 
32 #ifndef _CLI_SHELL_H_
33 #define _CLI_SHELL_H_
34 
35 #include "cli/namespace.h"
36 #include "cli/exec_context.h"
37 
38 
40 
41  // Forward declarations.
42  class Cli;
43  class Menu;
44  class Element;
45  class CmdLineEdition;
46  class CmdLineHistory;
47 
48 
50  class Shell : public ExecutionContext
51  {
52  private:
54  void InitObject(
55  const Cli& CLI_Cli
56  );
57 
58  public:
60  explicit Shell(
61  const Cli& CLI_Cli
62  );
63 
65  explicit Shell(
66  ExecutionContext& CLI_ParentContext,
67  const Cli& CLI_Cli
68  );
69 
71  virtual ~Shell(void);
72 
73  private:
75  explicit Shell(void);
77  Shell(const Shell&);
79  Shell& operator=(const Shell&);
80 
81  public:
84  const Cli& GetCli(void) const;
85 
87  void SetWelcomeMessage(
88  const ResourceString& CLI_WelcomeMessage
89  );
93  void SetByeMessage(
94  const ResourceString& CLI_ByeMessage
95  );
99  void SetPrompt(
100  const ResourceString& CLI_Prompt
101  );
105 
106  public:
109  const unsigned int GetHelpMargin(void) const;
110 
113  const unsigned int GetHelpOffset(void) const;
114 
115  private:
117  void PromptWelcomeMessage(void) const;
119  void PromptByeMessage(void) const;
121  void PromptMenu(void) const;
123  void PrintError(
124  const ResourceString& CLI_Location,
125  const ResourceString& CLI_ErrorMessage
126  ) const;
127 
128  public:
131  const Menu* const GetCurrentMenu(
132  const int I_MenuIndex
133  ) const;
138 
140  void EnterMenu(
141  const Menu& CLI_Menu,
142  const bool B_PromptMenu
143  );
146 
148  void ExitMenu(
149  const bool B_PromptMenu
150  );
153 
156  void Quit(void);
157 
159  void DisplayHelp(void);
160 
162  void PrintWorkingMenu(void);
163 
165  void CleanScreen(
166  const bool B_PromptMenu
167  );
170 
171  protected:
172  // Inherit doxygen comments from cli::ExecutionContext interface documentation.
173  virtual const bool OnStartExecution(void);
174  // Inherit doxygen comments from cli::ExecutionContext interface documentation.
175  virtual void OnKey(const KEY E_KeyCode);
176  // Inherit doxygen comments from cli::ExecutionContext interface documentation.
177  virtual const bool OnStopExecution(void);
178 
179  private:
181  void OnPrintableChar(const KEY E_KeyCode);
183  void OnKeyBegin(void);
185  void OnKeyEnd(void);
187  void OnKeyLeft(void);
189  void OnKeyRight(void);
191  void OnBackspace(void);
193  void OnSuppr(void);
195  void OnEscape(void);
197  void OnExit(
198  const bool B_PromptMenu
199  );
205  void OnHelp(
206  const bool B_PromptMenu,
207  const bool B_Completion
210  );
212  void OnExecute(void);
214  void OnHistory(
215  const int I_Navigation
216  );
219 
220  private:
222  void PrintHelp(
223  const Element& CLI_Element
224  );
225 
226  private:
228  const Cli& m_cliCli;
230  ResourceString m_cliWelcomeMessage;
232  ResourceString m_cliByeMessage;
234  ResourceString m_cliNoDefaultPrompt;
236  tk::Queue<const Menu*> m_qMenus;
238  CmdLineEdition& m_cliCmdLine;
240  CmdLineHistory& m_cliHistory;
241  };
242 
244 
245 #endif // _CLI_SHELL_H_
246 
Main namespace of the CLI library.
virtual ~Shell(void)
Destructor.
void EnterMenu(const Menu &CLI_Menu, const bool B_PromptMenu)
Enters a menu.
void ExitMenu(const bool B_PromptMenu)
Exits the current menu.
#define CLI_NS_END(__ns)
End a namespace definition.
Definition: namespace.h:45
void SetWelcomeMessage(const ResourceString &CLI_WelcomeMessage)
Welcome message setting.
ResourceString class.
virtual const bool OnStopExecution(void)
Execution termination handler.
const Menu *const GetCurrentMenu(const int I_MenuIndex) const
Current menu retrieval.
Namespace management.
Execution context class definition.
void SetByeMessage(const ResourceString &CLI_ByeMessage)
Bye message setting.
void DisplayHelp(void)
Displays help depending on the context of the current line.
Execution context.
Definition: exec_context.h:149
void Quit(void)
Terminates the shell.
Command line history objet.
Generic CLI element.
Definition: element.h:55
enum _KEY KEY
Input keys.
virtual const bool OnStartExecution(void)
Beginning of execution handler.
void CleanScreen(const bool B_PromptMenu)
Clean screen shortcut.
#define CLI_NS_BEGIN(__ns)
Begin a namespace definition.
Definition: namespace.h:38
Menu definition.
Definition: menu.h:51
const Cli & GetCli(void) const
Cli accessor.
const unsigned int GetHelpOffset(void) const
Help offset accessor.
void SetPrompt(const ResourceString &CLI_Prompt)
Prompt message positionning.
Command line edition objet.
void PrintWorkingMenu(void)
Prints the working menu.
const unsigned int GetHelpMargin(void) const
Help margin accessor.
CLI definition class.
Definition: cli.h:97
virtual void OnKey(const KEY E_KeyCode)
Handler called on character input.
Shell management.
Definition: shell.h:50