/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying1file LICENSE.rst or https://cmake.org/licensing for details. */2#pragma once34#include "cmConfigure.h" // IWYU pragma: keep56#include <cstddef>7#include <memory>8#include <string>9#include <vector>1011#include <cm/optional>1213#include "cmCursesForm.h"14#include "cmCursesStandardIncludes.h"15#include "cmStateTypes.h"1617class cmake;18class cmCursesCacheEntryComposite;19class cmCursesLongMessageForm;2021/** \class cmCursesMainForm22* \brief The main page of ccmake23*24* cmCursesMainForm is the main page of ccmake.25*/26class cmCursesMainForm : public cmCursesForm27{28public:29cmCursesMainForm(std::vector<std::string> args, int initwidth);30~cmCursesMainForm() override;3132cmCursesMainForm(cmCursesMainForm const&) = delete;33cmCursesMainForm& operator=(cmCursesMainForm const&) = delete;3435/**36* Set the widgets which represent the cache entries.37*/38void InitializeUI();3940/**41* Handle user input.42*/43void HandleInput() override;4445/**46* Display form. Use a window of size width x height, starting47* at top, left.48*/49void Render(int left, int top, int width, int height) override;5051/**52* Returns true if an entry with the given key is in the53* list of current composites.54*/55bool LookForCacheEntry(std::string const& key);5657enum58{59MIN_WIDTH = 65,60MIN_HEIGHT = 6,61IDEAL_WIDTH = 80,62MAX_WIDTH = 51263};6465void SetSearchMode(bool enable);6667/**68* This method should normally be called only by the form. The only69* exception is during a resize. The optional argument specifies the70* string to be displayed in the status bar.71*/72void UpdateStatusBar() override { this->UpdateStatusBar(cm::nullopt); }73void UpdateStatusBar(cm::optional<std::string> message);7475/**76* Display current commands and their keys on the toolbar. This77* method should normally called only by the form. The only78* exception is during a resize. If the optional argument process is79* specified and is either 1 (configure) or 2 (generate), then keys80* will be displayed accordingly.81*/82void PrintKeys(int process = 0);8384/**85* During a CMake run, an error handle should add errors86* to be displayed afterwards.87*/88void AddError(std::string const& message, char const* title) override;8990/**91* Write files to cache file without reconfiguring.92*/93void Write();9495/**96* Used to do a configure. If argument is specified, it does only the check97* and not configure.98*/99int Configure(int noconfigure = 0);100101/**102* Used to generate103*/104int Generate();105106/**107* Used by main program108*/109int LoadCache(char const* dir);110111/**112* Progress callback113*/114void UpdateProgress(std::string const& msg, float prog);115116protected:117// Copy the cache values from the user interface to the actual118// cache.119void FillCacheManagerFromUI();120// Fix formatting of values to a consistent form.121void FixValue(cmStateEnums::CacheEntryType type, std::string const& in,122std::string& out) const;123// Re-post the existing fields. Used to toggle between124// normal and advanced modes. Render() should be called125// afterwards.126void RePost();127// Remove an entry from the interface and the cache.128void RemoveEntry(char const* value);129130// Jump to the cache entry whose name matches the string.131void JumpToCacheEntry(char const* str);132void JumpToCacheEntry(char const* str, bool reverse);133134// Clear and reset the output log and state135void ResetOutputs();136137// Display the current progress and output138void DisplayOutputs(std::string const& newOutput);139140// Copies of cache entries stored in the user interface141std::vector<cmCursesCacheEntryComposite> Entries;142143// The form used to display logs during processing144std::unique_ptr<cmCursesLongMessageForm> LogForm;145// Output produced by the last pass146std::vector<std::string> Outputs;147// Did the last pass produced outputs of interest (errors, warnings, ...)148bool HasNonStatusOutputs = false;149// Last progress bar150std::string LastProgress;151152// Command line arguments to be passed to cmake each time153// it is run154std::vector<std::string> Args;155// Message displayed when user presses 'h'156// It is: Welcome + info about current entry + common help157std::vector<std::string> HelpMessage;158159// Common help160static char const* s_ConstHelpMessage;161162// Fields displayed. Includes labels, new entry markers, entries163std::vector<FIELD*> Fields;164// Number of entries shown (depends on mode -normal or advanced-)165size_t NumberOfVisibleEntries = 0;166bool AdvancedMode = false;167// Did the iteration converge (no new entries) ?168bool OkToGenerate = false;169// Number of pages displayed170int NumberOfPages = 0;171bool IsEmpty = false;172std::unique_ptr<cmCursesCacheEntryComposite> EmptyCacheEntry;173174int InitialWidth;175std::unique_ptr<cmake> CMakeInstance;176177std::string SearchString;178std::string OldSearchString;179bool SearchMode = false;180};181182183