cmCursesMainForm.h 4.9 KB

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