Console class reference
[Base module]
Declaration
#include <QtLua/Console>
namespace QtLua {
class Console;
};
This class is a member of the QtLua namespace.
Description
This class provides an easy to use console widget for use in QtLua based applications.
This widget is a general purpose console widget with history and completion capabilities.
The qtlua interpreter uses this widget.
When used with a State lua interpreter object, it only needs a few signals connections to get a working lua based shell:
// code from examples/cpp/console/console.cc:25
MainWindow::MainWindow()
: QMainWindow()
{
state = new QtLua::State();
console = new QtLua::Console();
setCentralWidget(console);
connect(console, SIGNAL(line_validate(const QString&)),
state, SLOT(exec(const QString&)));
connect(console, SIGNAL(get_completion_list(const QString &, QStringList &, int &)),
state, SLOT(fill_completion_list(const QString &, QStringList &, int &)));
connect(state, SIGNAL(output(const QString&)),
console, SLOT(print(const QString&)));
}
Members
Functions
- Console(QWidget *parent = [...], const QString &prompt = [...], const QStringList &history = [...])
- const QStringList & get_history() const
- int get_history_size() const
- const QString & get_prompt() const
- int get_scroll_back() const
- int get_text_height() const
- int get_text_width() const
- void load_history(QSettings &s, const QString &key = [...])
- void save_history(QSettings &s, const QString &key = [...]) const
- void set_completion_regexp(const QRegExp ®exp)
- void set_history(const QStringList &h)
- void set_history_size(int history_size)
- void set_prompt(const QString &p)
- void set_scroll_back(int scroll_back)
- void set_text_height(int height)
- void set_text_width(int width)
Slot
- void print(const QString &str)
Signals
- void get_completion_list(const QString &prefix, QStringList &list, int &cursor_offset)
- void line_validate(const QString &str)
Members detail
Console(QWidget *parent = 0, const QString &prompt = QString("$"), const QStringList &history = QStringList())
Create a console widget and restore history
void get_completion_list(const QString &prefix, QStringList &list, int &cursor_offset)
This member is a Qt signal.
Signal emited to query completion list.
Parameters list:
- prefix: text extracted before cursor.
- list: must be filled with completion matches by completion slot function.
- cursor_offset: may be decreased by completion slot function to move cursor backward on completed text. (only used on single match)
const QStringList & get_history() const
Get current history.
Get console max history entries count
const QString & get_prompt() const
Get console prompt.
Get number of lines in the scrollback buffer.
Get console height in character count
Get console width in character count
void line_validate(const QString &str)
This member is a Qt signal.
Signal emited when text line is validated with enter key
Load history from QSettings object and keep a QPointer to QSettings for subsequent call to the Console::save_history function.
void print(const QString &str)
This member is a Qt slot.
Display text on the console
Save history using QSettings object previously passed to Console::load_history function.
void set_completion_regexp(const QRegExp ®exp)
Set Qt regular expression used to extract text before cursor to pass to completion signal.
The default regexp [_.:a-zA-Z0-9]+$ is suited to extract lua identifiers and table member access statements.
void set_history(const QStringList &h)
Set current history.
Set console max history entries count
void set_prompt(const QString &p)
Set console prompt.
Set number of lines in the scrollback buffer. Changes will take effect next time a line is entered or a Console::print is performed. Default value is 1000.
Set console height in character count
Set console width in character count