2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 /** @file autocompletion.h Generic auto-completion engine. */
10 #ifndef AUTOCOMPLETION_H
11 #define AUTOCOMPLETION_H
13 #include "textbuf_type.h"
15 class AutoCompletion
{
20 std::string initial_buf
; ///< Value of text buffer when we started current suggestion session.
22 std::string_view prefix
; ///< Prefix of the text before the last space.
23 std::string_view query
; ///< Last token of the text. This is used to based the suggestions on.
25 std::vector
<std::string
> suggestions
;
26 size_t current_suggestion_index
;
29 AutoCompletion(Textbuf
*textbuf
) : textbuf(textbuf
)
33 virtual ~AutoCompletion() = default;
35 // Returns true the textbuf was updated.
40 void InitSuggestions(std::string_view text
);
42 virtual std::vector
<std::string
> GetSuggestions(std::string_view prefix
, std::string_view query
) = 0;
43 virtual void ApplySuggestion(std::string_view prefix
, std::string_view suggestion
) = 0;
46 #endif /* AUTOCOMPLETION_H */