cmCursesMainForm.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <cstddef>
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include <cm/optional>
  10. #include "cmCursesCacheEntryComposite.h"
  11. #include "cmCursesForm.h"
  12. #include "cmCursesStandardIncludes.h"
  13. #include "cmStateTypes.h"
  14. class cmake;
  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(const std::string& key);
  46. enum
  47. {
  48. MIN_WIDTH = 65,
  49. MIN_HEIGHT = 6,
  50. IDEAL_WIDTH = 80,
  51. MAX_WIDTH = 512
  52. };
  53. /**
  54. * This method should normally be called only by the form. The only
  55. * exception is during a resize. The optional argument specifies the
  56. * string to be displayed in the status bar.
  57. */
  58. void UpdateStatusBar() override { this->UpdateStatusBar(cm::nullopt); }
  59. void UpdateStatusBar(cm::optional<std::string> message);
  60. /**
  61. * Display current commands and their keys on the toolbar. This
  62. * method should normally called only by the form. The only
  63. * exception is during a resize. If the optional argument process is
  64. * specified and is either 1 (configure) or 2 (generate), then keys
  65. * will be displayed accordingly.
  66. */
  67. void PrintKeys(int process = 0);
  68. /**
  69. * During a CMake run, an error handle should add errors
  70. * to be displayed afterwards.
  71. */
  72. void AddError(const std::string& message, const char* title) override;
  73. /**
  74. * Used to do a configure. If argument is specified, it does only the check
  75. * and not configure.
  76. */
  77. int Configure(int noconfigure = 0);
  78. /**
  79. * Used to generate
  80. */
  81. int Generate();
  82. /**
  83. * Used by main program
  84. */
  85. int LoadCache(const char* dir);
  86. /**
  87. * Progress callback
  88. */
  89. void UpdateProgress(const std::string& msg, float prog);
  90. protected:
  91. // Copy the cache values from the user interface to the actual
  92. // cache.
  93. void FillCacheManagerFromUI();
  94. // Fix formatting of values to a consistent form.
  95. void FixValue(cmStateEnums::CacheEntryType type, const std::string& in,
  96. std::string& out) const;
  97. // Re-post the existing fields. Used to toggle between
  98. // normal and advanced modes. Render() should be called
  99. // afterwards.
  100. void RePost();
  101. // Remove an entry from the interface and the cache.
  102. void RemoveEntry(const char* value);
  103. // Jump to the cache entry whose name matches the string.
  104. void JumpToCacheEntry(const char* str);
  105. // Clear and reset the output log and state
  106. void ResetOutputs();
  107. // Display the current progress and output
  108. void DisplayOutputs(std::string const& newOutput);
  109. // Copies of cache entries stored in the user interface
  110. std::vector<cmCursesCacheEntryComposite> Entries;
  111. // The form used to display logs during processing
  112. std::unique_ptr<cmCursesLongMessageForm> LogForm;
  113. // Output produced by the last pass
  114. std::vector<std::string> Outputs;
  115. // Did the last pass produced outputs of interest (errors, warnings, ...)
  116. bool HasNonStatusOutputs;
  117. // Last progress bar
  118. std::string LastProgress;
  119. // Command line arguments to be passed to cmake each time
  120. // it is run
  121. std::vector<std::string> Args;
  122. // Message displayed when user presses 'h'
  123. // It is: Welcome + info about current entry + common help
  124. std::vector<std::string> HelpMessage;
  125. // Common help
  126. static const char* s_ConstHelpMessage;
  127. // Fields displayed. Includes labels, new entry markers, entries
  128. std::vector<FIELD*> Fields;
  129. // Number of entries shown (depends on mode -normal or advanced-)
  130. size_t NumberOfVisibleEntries;
  131. bool AdvancedMode;
  132. // Did the iteration converge (no new entries) ?
  133. bool OkToGenerate;
  134. // Number of pages displayed
  135. int NumberOfPages;
  136. int InitialWidth;
  137. std::unique_ptr<cmake> CMakeInstance;
  138. std::string SearchString;
  139. std::string OldSearchString;
  140. bool SearchMode;
  141. };