1/*
2 * Copyright 2011-2016, Rene Gollent, rene@gollent.com.
3 * Copyright 2012, Ingo Weinhold, ingo_weinhold@gmx.de.
4 * Distributed under the terms of the MIT License.
5 */
6#ifndef COMMAND_LINE_USER_INTERFACE_H
7#define COMMAND_LINE_USER_INTERFACE_H
8
9
10#include <ObjectList.h>
11#include <String.h>
12
13#include "CliContext.h"
14#include "UserInterface.h"
15
16
17class CliCommand;
18
19
20class CommandLineUserInterface : public UserInterface {
21public:
22								CommandLineUserInterface();
23	virtual						~CommandLineUserInterface();
24
25	virtual	const char*			ID() const;
26
27	virtual	status_t			Init(Team* team,
28									UserInterfaceListener* listener);
29	virtual	void				Show();
30	virtual	void				Terminate();
31									// shut down the UI *now* -- no more user
32									// feedback
33
34	virtual	UserInterface*		Clone() const;
35
36	virtual	bool				IsInteractive() const;
37
38	virtual status_t			LoadSettings(const TeamUiSettings* settings);
39	virtual status_t			SaveSettings(TeamUiSettings*& settings)	const;
40
41	virtual	void				NotifyUser(const char* title,
42									const char* message,
43									user_notification_type type);
44	virtual	void				NotifyBackgroundWorkStatus(
45									const char* message);
46	virtual	int32				SynchronouslyAskUser(const char* title,
47									const char* message, const char* choice1,
48									const char* choice2, const char* choice3);
49	virtual	status_t			SynchronouslyAskUserForFile(entry_ref* _ref);
50
51			void				Run();
52									// Called by the main thread, when
53									// everything has been set up. Enters the
54									// input loop.
55
56private:
57			struct CommandEntry;
58			typedef BObjectList<CommandEntry> CommandList;
59
60			struct HelpCommand;
61
62			// GCC 2 support
63			friend struct HelpCommand;
64
65private:
66			status_t			_InputLoop();
67
68			status_t			_RegisterCommands();
69			bool				_RegisterCommand(const BString& name,
70									CliCommand* command);
71			void				_ExecuteCommand(int argc,
72									const char* const* argv);
73			CommandEntry*		_FindCommand(const char* commandName);
74			void				_PrintHelp(const char* commandName);
75	static	int					_CompareCommandEntries(
76									const CommandEntry* command1,
77									const CommandEntry* command2);
78
79private:
80			CliContext*			fContext;
81			CommandList			fCommands;
82			sem_id				fShowSemaphore;
83			bool				fShown;
84	volatile bool				fTerminating;
85};
86
87
88#endif	// COMMAND_LINE_USER_INTERFACE_H
89