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