Geogram  Version 1.9.1-rc
A programming library of geometric algorithms
console.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2000-2022 Inria
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright notice,
11  * this list of conditions and the following disclaimer in the documentation
12  * and/or other materials provided with the distribution.
13  * * Neither the name of the ALICE Project-Team nor the names of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  *
29  * Contact: Bruno Levy
30  *
31  * https://www.inria.fr/fr/bruno-levy
32  *
33  * Inria,
34  * Domaine de Voluceau,
35  * 78150 Le Chesnay - Rocquencourt
36  * FRANCE
37  *
38  */
39 
40 #ifndef H_GEOGRAM_GFX_GUI_CONSOLE_H
41 #define H_GEOGRAM_GFX_GUI_CONSOLE_H
42 
44 #include <geogram_gfx/imgui_ext/imgui_ext.h>
45 #include <geogram/basic/logger.h>
46 
52 namespace GEO {
53 
60 
61  public:
62 
68  Console(bool* visible_flag = nullptr);
69 
73  void div(const std::string& value) override;
74 
78  void out(const std::string& value) override;
79 
83  void warn(const std::string& value) override;
84 
88  void err(const std::string& value) override;
89 
93  void status(const std::string& value) override;
94 
98  void clear();
99 
103  virtual void printf(const char* fmt, ...) /* IM_FMTARGS(1) */;
104 
113  virtual void draw(bool* visible=nullptr, bool with_window=true);
114 
115  int TextEditCallback(ImGuiInputTextCallbackData* data);
116 
117  void show() {
118  *visible_flag_ = true;
119  }
120 
121  void hide() {
122  *visible_flag_ = false;
123  }
124 
125  typedef void (*CompletionCallback)(
126  Console* console,
127  const std::string& line, index_t startw, index_t endw,
128  const std::string& cmpword, std::vector<std::string>& matches
129  );
130 
131  void set_completion_callback(CompletionCallback CB) {
132  completion_callback_ = CB;
133  }
134 
135  typedef void (*HistoryCallback)(
136  Console* console,
137  index_t index,
138  std::string& command
139  );
140 
141  void set_history_callback(HistoryCallback CB) {
142  history_callback_ = CB;
143  }
144 
145  void set_history_size(index_t n) {
146  if(n != max_history_index_) {
147  history_index_ = n;
148  }
149  max_history_index_ = n;
150  }
151 
152  void show_command_prompt() {
153  command_prompt_ = true;
154  }
155 
156  void hide_command_prompt() {
157  command_prompt_ = false;
158  }
159 
160  protected:
168  virtual void notify_error(const std::string& err);
169 
170  virtual bool exec_command(const char* command);
171 
175  virtual void update();
176 
177  bool command_prompt_;
178  ImGuiTextBuffer buf_;
179  ImGuiTextFilter filter_;
181  ImVector<int> line_offsets_;
182  index_t scroll_to_bottom_;
183  bool* visible_flag_;
184  char input_buf_[geo_imgui_string_length];
185  CompletionCallback completion_callback_;
186  HistoryCallback history_callback_;
187  index_t history_index_;
188  index_t max_history_index_;
189  };
190 
192 }
193 
194 #endif
A console, that displays logger messages, and where the user can enter commands.
Definition: console.h:59
void status(const std::string &value) override
Handles a status message.
virtual void notify_error(const std::string &err)
This function is called whenever an error is displayed using err()
ImVector< int > line_offsets_
Index to lines offset.
Definition: console.h:181
Console(bool *visible_flag=nullptr)
Console constructor.
void clear()
Clears the contents of the console.
void err(const std::string &value) override
Handles an error message.
void div(const std::string &value) override
Creates a new division.
void out(const std::string &value) override
Handles an information message.
virtual void printf(const char *fmt,...)
Displays a formatted string to the console.
virtual void update()
Redraws the GUI.
void warn(const std::string &value) override
Handles a warning message.
virtual void draw(bool *visible=nullptr, bool with_window=true)
Draws the console and handles the gui.
Logger client base class.
Definition: logger.h:156
#define GEOGRAM_GFX_API
Linkage declaration for geogram symbols.
Definition: defs.h:55
Common include file, providing basic definitions. Should be included before anything else by all head...
Generic logging mechanism.
Global Vorpaline namespace.
Definition: basic.h:55
geo_index_t index_t
The type for storing and manipulating indices.
Definition: numeric.h:329