Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/CursesDialog/cmCursesMainForm.h
5000 views
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
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 "cmCursesForm.h"
15
#include "cmCursesStandardIncludes.h"
16
#include "cmStateTypes.h"
17
18
class cmake;
19
class cmCursesCacheEntryComposite;
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(std::string const& key);
57
58
enum
59
{
60
MIN_WIDTH = 65,
61
MIN_HEIGHT = 6,
62
IDEAL_WIDTH = 80,
63
MAX_WIDTH = 512
64
};
65
66
void SetSearchMode(bool enable);
67
68
/**
69
* This method should normally be called only by the form. The only
70
* exception is during a resize. The optional argument specifies the
71
* string to be displayed in the status bar.
72
*/
73
void UpdateStatusBar() override { this->UpdateStatusBar(cm::nullopt); }
74
void UpdateStatusBar(cm::optional<std::string> message);
75
76
/**
77
* Display current commands and their keys on the toolbar. This
78
* method should normally called only by the form. The only
79
* exception is during a resize. If the optional argument process is
80
* specified and is either 1 (configure) or 2 (generate), then keys
81
* will be displayed accordingly.
82
*/
83
void PrintKeys(int process = 0);
84
85
/**
86
* During a CMake run, an error handle should add errors
87
* to be displayed afterwards.
88
*/
89
void AddError(std::string const& message, char const* title) override;
90
91
/**
92
* Write files to cache file without reconfiguring.
93
*/
94
void Write();
95
96
/**
97
* Used to do a configure. If argument is specified, it does only the check
98
* and not configure.
99
*/
100
int Configure(int noconfigure = 0);
101
102
/**
103
* Used to generate
104
*/
105
int Generate();
106
107
/**
108
* Used by main program
109
*/
110
int LoadCache(char const* dir);
111
112
/**
113
* Progress callback
114
*/
115
void UpdateProgress(std::string const& msg, float prog);
116
117
protected:
118
// Copy the cache values from the user interface to the actual
119
// cache.
120
void FillCacheManagerFromUI();
121
// Fix formatting of values to a consistent form.
122
void FixValue(cmStateEnums::CacheEntryType type, std::string const& in,
123
std::string& out) const;
124
// Re-post the existing fields. Used to toggle between
125
// normal and advanced modes. Render() should be called
126
// afterwards.
127
void RePost();
128
// Remove an entry from the interface and the cache.
129
void RemoveEntry(char const* value);
130
131
// Jump to the cache entry whose name matches the string.
132
void JumpToCacheEntry(char const* str);
133
void JumpToCacheEntry(char const* str, bool reverse);
134
135
// Clear and reset the output log and state
136
void ResetOutputs();
137
138
// Display the current progress and output
139
void DisplayOutputs(std::string const& newOutput);
140
141
// Copies of cache entries stored in the user interface
142
std::vector<cmCursesCacheEntryComposite> Entries;
143
144
// The form used to display logs during processing
145
std::unique_ptr<cmCursesLongMessageForm> LogForm;
146
// Output produced by the last pass
147
std::vector<std::string> Outputs;
148
// Did the last pass produced outputs of interest (errors, warnings, ...)
149
bool HasNonStatusOutputs = false;
150
// Last progress bar
151
std::string LastProgress;
152
153
// Command line arguments to be passed to cmake each time
154
// it is run
155
std::vector<std::string> Args;
156
// Message displayed when user presses 'h'
157
// It is: Welcome + info about current entry + common help
158
std::vector<std::string> HelpMessage;
159
160
// Common help
161
static char const* s_ConstHelpMessage;
162
163
// Fields displayed. Includes labels, new entry markers, entries
164
std::vector<FIELD*> Fields;
165
// Number of entries shown (depends on mode -normal or advanced-)
166
size_t NumberOfVisibleEntries = 0;
167
bool AdvancedMode = false;
168
// Did the iteration converge (no new entries) ?
169
bool OkToGenerate = false;
170
// Number of pages displayed
171
int NumberOfPages = 0;
172
bool IsEmpty = false;
173
std::unique_ptr<cmCursesCacheEntryComposite> EmptyCacheEntry;
174
175
int InitialWidth;
176
std::unique_ptr<cmake> CMakeInstance;
177
178
std::string SearchString;
179
std::string OldSearchString;
180
bool SearchMode = false;
181
};
182
183