Imported Upstream version 3.17.1
[platform/upstream/cmake.git] / Source / CursesDialog / cmCursesMainForm.h
1 /* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2    file Copyright.txt or https://cmake.org/licensing for details.  */
3 #ifndef cmCursesMainForm_h
4 #define cmCursesMainForm_h
5
6 #include "cmConfigure.h" // IWYU pragma: keep
7
8 #include <cstddef>
9 #include <memory>
10 #include <string>
11 #include <vector>
12
13 #include <cm/optional>
14
15 #include "cmCursesCacheEntryComposite.h"
16 #include "cmCursesForm.h"
17 #include "cmCursesStandardIncludes.h"
18 #include "cmStateTypes.h"
19
20 class cmake;
21 class cmCursesLongMessageForm;
22
23 /** \class cmCursesMainForm
24  * \brief The main page of ccmake
25  *
26  * cmCursesMainForm is the main page of ccmake.
27  */
28 class cmCursesMainForm : public cmCursesForm
29 {
30 public:
31   cmCursesMainForm(std::vector<std::string> args, int initwidth);
32   ~cmCursesMainForm() override;
33
34   cmCursesMainForm(cmCursesMainForm const&) = delete;
35   cmCursesMainForm& operator=(cmCursesMainForm const&) = delete;
36
37   /**
38    * Set the widgets which represent the cache entries.
39    */
40   void InitializeUI();
41
42   /**
43    * Handle user input.
44    */
45   void HandleInput() override;
46
47   /**
48    * Display form. Use a window of size width x height, starting
49    * at top, left.
50    */
51   void Render(int left, int top, int width, int height) override;
52
53   /**
54    * Returns true if an entry with the given key is in the
55    * list of current composites.
56    */
57   bool LookForCacheEntry(const std::string& key);
58
59   enum
60   {
61     MIN_WIDTH = 65,
62     MIN_HEIGHT = 6,
63     IDEAL_WIDTH = 80,
64     MAX_WIDTH = 512
65   };
66
67   /**
68    * This method should normally be called only by the form.  The only
69    * exception is during a resize. The optional argument specifies the
70    * string to be displayed in the status bar.
71    */
72   void UpdateStatusBar() override { this->UpdateStatusBar(cm::nullopt); }
73   void UpdateStatusBar(cm::optional<std::string> message);
74
75   /**
76    * Display current commands and their keys on the toolbar.  This
77    * method should normally called only by the form.  The only
78    * exception is during a resize. If the optional argument process is
79    * specified and is either 1 (configure) or 2 (generate), then keys
80    * will be displayed accordingly.
81    */
82   void PrintKeys(int process = 0);
83
84   /**
85    * During a CMake run, an error handle should add errors
86    * to be displayed afterwards.
87    */
88   void AddError(const std::string& message, const char* title) override;
89
90   /**
91    * Used to do a configure. If argument is specified, it does only the check
92    * and not configure.
93    */
94   int Configure(int noconfigure = 0);
95
96   /**
97    * Used to generate
98    */
99   int Generate();
100
101   /**
102    * Used by main program
103    */
104   int LoadCache(const char* dir);
105
106   /**
107    * Progress callback
108    */
109   void UpdateProgress(const std::string& msg, float prog);
110
111 protected:
112   // Copy the cache values from the user interface to the actual
113   // cache.
114   void FillCacheManagerFromUI();
115   // Fix formatting of values to a consistent form.
116   void FixValue(cmStateEnums::CacheEntryType type, const std::string& in,
117                 std::string& out) const;
118   // Re-post the existing fields. Used to toggle between
119   // normal and advanced modes. Render() should be called
120   // afterwards.
121   void RePost();
122   // Remove an entry from the interface and the cache.
123   void RemoveEntry(const char* value);
124
125   // Jump to the cache entry whose name matches the string.
126   void JumpToCacheEntry(const char* str);
127
128   // Clear and reset the output log and state
129   void ResetOutputs();
130
131   // Display the current progress and output
132   void DisplayOutputs(std::string const& newOutput);
133
134   // Copies of cache entries stored in the user interface
135   std::vector<cmCursesCacheEntryComposite> Entries;
136
137   // The form used to display logs during processing
138   std::unique_ptr<cmCursesLongMessageForm> LogForm;
139   // Output produced by the last pass
140   std::vector<std::string> Outputs;
141   // Did the last pass produced outputs of interest (errors, warnings, ...)
142   bool HasNonStatusOutputs;
143   // Last progress bar
144   std::string LastProgress;
145
146   // Command line arguments to be passed to cmake each time
147   // it is run
148   std::vector<std::string> Args;
149   // Message displayed when user presses 'h'
150   // It is: Welcome + info about current entry + common help
151   std::vector<std::string> HelpMessage;
152
153   // Common help
154   static const char* s_ConstHelpMessage;
155
156   // Fields displayed. Includes labels, new entry markers, entries
157   std::vector<FIELD*> Fields;
158   // Number of entries shown (depends on mode -normal or advanced-)
159   size_t NumberOfVisibleEntries;
160   bool AdvancedMode;
161   // Did the iteration converge (no new entries) ?
162   bool OkToGenerate;
163   // Number of pages displayed
164   int NumberOfPages;
165
166   int InitialWidth;
167   std::unique_ptr<cmake> CMakeInstance;
168
169   std::string SearchString;
170   std::string OldSearchString;
171   bool SearchMode;
172 };
173
174 #endif // cmCursesMainForm_h