ezEngine Release 26.3
Loading...
Searching...
No Matches
ezConsole Class Reference

Base console system for command input, output display, and history management. More...

#include <Console.h>

Inheritance diagram for ezConsole:

Public Member Functions

Console Display
virtual void AddConsoleString (ezStringView sText, ezConsoleString::Type type=ezConsoleString::Type::Default)
 Adds a string to the console.
 
virtual void RenderConsole (bool bIsOpen)
 Display the console state.
 

Events

ezEvent< const ezConsoleEvent & > m_Events
 The console event variable, to attach to.
 
const ezEvent< const ezConsoleEvent & > & Events () const
 Grants access to subscribe and unsubscribe from console events.
 

Helpers

ezMutex m_Mutex
 
ezMutexGetMutex () const
 Returns the mutex that's used to prevent multi-threaded access.
 
static void SetMainConsole (ezConsole *pConsole)
 
static ezConsoleGetMainConsole ()
 

Command Interpreter

ezSharedPtr< ezCommandInterpreterm_pCommandInterpreter
 
void SetCommandInterpreter (const ezSharedPtr< ezCommandInterpreter > &pInterpreter)
 Replaces the current command interpreter.
 
const ezSharedPtr< ezCommandInterpreter > & GetCommandInterpreter () const
 Returns the currently used command interpreter.
 
virtual bool AutoComplete (ezStringBuilder &ref_sText)
 Auto-completes the given text.
 
virtual void ExecuteCommand (ezStringView sInput)
 Executes the given input string.
 

Input

ezInt32 m_iCurrentInputHistoryElement = -1
 
ezStaticArray< ezString, 16 > m_InputHistory
 
virtual void HandleInput (bool bIsOpen)
 Update the console with the latest input.
 
void AddToInputHistory (ezStringView sText)
 Adds an item to the input history.
 
const ezStaticArray< ezString, 16 > & GetInputHistory () const
 Returns the current input history.
 
void RetrieveInputHistory (ezInt32 iHistoryUp, ezStringBuilder &ref_sResult)
 Replaces the input line by the next (or previous) history item.
 
ezResult SaveInputHistory (ezStringView sFile)
 Writes the current input history to a text file.
 
void LoadInputHistory (ezStringView sFile)
 Reads the text file and appends all lines to the input history.
 

Detailed Description

Base console system for command input, output display, and history management.

Provides infrastructure for command execution through pluggable interpreters, maintains input history, and broadcasts events when output is added. Thread-safe through internal mutex protection.

This base class handles core functionality but doesn't store output strings. Derived classes typically provide persistent storage and visual representation.

Member Function Documentation

◆ AddConsoleString()

void ezConsole::AddConsoleString ( ezStringView  sText,
ezConsoleString::Type  type = ezConsoleString::Type::Default 
)
virtual

Adds a string to the console.

The base class only broadcasts an event, but does not store the string anywhere.

Reimplemented in ezQuakeConsole.

◆ AutoComplete()

bool ezConsole::AutoComplete ( ezStringBuilder ref_sText)
virtual

Auto-completes the given text.

Returns true, if the string was modified in any way. Adds additional strings to the console output, if there are further auto-completion suggestions.

◆ ExecuteCommand()

void ezConsole::ExecuteCommand ( ezStringView  sInput)
virtual

Executes the given input string.

The command is forwarded to the set command interpreter.

Reimplemented in ezQuakeConsole.

◆ GetInputHistory()

const ezStaticArray< ezString, 16 > & ezConsole::GetInputHistory ( ) const
inline

Returns the current input history.

Make sure to lock the console's mutex while working with the history.

◆ HandleInput()

virtual void ezConsole::HandleInput ( bool  bIsOpen)
inlinevirtual

Update the console with the latest input.

Reimplemented in ezQuakeConsole.

◆ RenderConsole()

virtual void ezConsole::RenderConsole ( bool  bIsOpen)
inlinevirtual

Display the console state.

Reimplemented in ezQuakeConsole.

◆ SetCommandInterpreter()

void ezConsole::SetCommandInterpreter ( const ezSharedPtr< ezCommandInterpreter > &  pInterpreter)
inline

Replaces the current command interpreter.

This base class doesn't set any default interpreter, but derived classes may do so.


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