OpenTTD Source 20260206-master-g4d4e37dbf1
AutoCompletion Class Referenceabstract
Inheritance diagram for AutoCompletion:
ConsoleAutoCompletion NetworkChatAutoCompletion

Public Member Functions

 AutoCompletion (Textbuf *textbuf)
bool AutoComplete ()
void Reset ()

Protected Attributes

Textbuftextbuf

Private Member Functions

void InitSuggestions (std::string_view text)
virtual std::vector< std::string > GetSuggestions (std::string_view prefix, std::string_view query)=0
 Get suggestions for auto completion with the given 'query' input text.
virtual void ApplySuggestion (std::string_view prefix, std::string_view suggestion)=0
 Format the given suggestion after the given prefix, and write that to the buffer.

Private Attributes

std::string initial_buf
 Value of text buffer when we started current suggestion session.
std::string_view prefix
 Prefix of the text before the last space.
std::string_view query
 Last token of the text. This is used to based the suggestions on.
std::vector< std::string > suggestions
size_t current_suggestion_index

Detailed Description

Definition at line 15 of file autocompletion.h.

Constructor & Destructor Documentation

◆ AutoCompletion()

AutoCompletion::AutoCompletion ( Textbuf * textbuf)
inline

Definition at line 29 of file autocompletion.h.

Member Function Documentation

◆ ApplySuggestion()

virtual void AutoCompletion::ApplySuggestion ( std::string_view prefix,
std::string_view suggestion )
privatepure virtual

Format the given suggestion after the given prefix, and write that to the buffer.

For example, in case of a name in chat format '{name}: ' when the prefix is empty, otherwise '{prefix}{name}'.

Parameters
prefixThe text before the token that was auto completed on.
suggestionThe chosen suggestion.

Implemented in ConsoleAutoCompletion, and NetworkChatAutoCompletion.

References prefix.

Referenced by AutoComplete().

◆ AutoComplete()

bool AutoCompletion::AutoComplete ( )
Returns
true, if the textbuf was updated.

Definition at line 23 of file autocompletion.cpp.

References ApplySuggestion(), initial_buf, and prefix.

Referenced by NetworkChatWindow::ChatTabCompletion().

◆ GetSuggestions()

virtual std::vector< std::string > AutoCompletion::GetSuggestions ( std::string_view prefix,
std::string_view query )
privatepure virtual

Get suggestions for auto completion with the given 'query' input text.

Parameters
prefixThe text before the token that is auto completed on.
queryThe token to perform the auto completion on.
Returns
All potential auto complete suggestions.

Implemented in ConsoleAutoCompletion, and NetworkChatAutoCompletion.

References prefix, and query.

◆ InitSuggestions()

void AutoCompletion::InitSuggestions ( std::string_view text)
private

Definition at line 55 of file autocompletion.cpp.

◆ Reset()

void AutoCompletion::Reset ( )

Definition at line 46 of file autocompletion.cpp.

Field Documentation

◆ current_suggestion_index

size_t AutoCompletion::current_suggestion_index
private

Definition at line 26 of file autocompletion.h.

◆ initial_buf

std::string AutoCompletion::initial_buf
private

Value of text buffer when we started current suggestion session.

Definition at line 20 of file autocompletion.h.

Referenced by AutoComplete().

◆ prefix

◆ query

std::string_view AutoCompletion::query
private

Last token of the text. This is used to based the suggestions on.

Definition at line 23 of file autocompletion.h.

Referenced by GetSuggestions(), ConsoleAutoCompletion::GetSuggestions(), and NetworkChatAutoCompletion::GetSuggestions().

◆ suggestions

std::vector<std::string> AutoCompletion::suggestions
private

Definition at line 25 of file autocompletion.h.

◆ textbuf

Textbuf* AutoCompletion::textbuf
protected

Definition at line 17 of file autocompletion.h.


The documentation for this class was generated from the following files: