NAME
BQCommandConsole - BRTT Qt graphics extension for making a user typein command console
SYNOPSIS
$(QTNATIVELIBS) -lbqplot_native -lbanner -lbrttutil -lbumapdata $(DBLIBS) $(TRLIBS)
#include "BQ.h"
DESCRIPTION
BQCommandConsole objects are used to provide a user interface for typing commands.
This class inherits the BQConfigure class which is itself a subclass of the BUConfigure class
with extensions to process Qt colors and fonts. The Qconfigure methods are implemented
in the BUConfigure parent (see BUConfigure(3)).
INHERITS FROM
QTextEdit,
BQConfigure
CONSTRUCTOR
BQCommandConsole(QWidget *parent);
Where "parent" is the QWidget parent for this object.
METHODS INHERITED FROM BQConfigure
-
void configure (Pf *params);
An Antelope parameter file object pointer that contains the BQCommandConsole object
parameters. The parameters are described below.
-
void configure (...);
A variable argument list composed entirely of character string key-value pairs with
a single NULL terminating argument. This is an alternate method for specifying
the BQCommandConsole object parameters. The parameters are described below.
BQCommandConsole METHODS
-
void sendCommand (QString command, int echo_command=1, int echo_output=1);
This causes a command string, command, to be processed as if it were typed interactively. If echo_command
is set, then the command will be echoed in the BQCommandConsole GUI.
If echo_output is set, then the any output produced by the command will be echoed in the BQCommandConsole GUI.
-
void printLineOutput (QString command, QString line, int error_output_flag, int output_done_flag);
This will cause a line of output, line, to be displayed for command command in the BQCommandConsole GUI.
If error_output_flag is set, then the line will be displayed with the error color.
If output_done_flag is set, then after the line is displayed a normal prompt will be displayed for further
user input.
-
int importFromFile (QString file_name, int echo=1);
This will cause commands to be read from file with name file_name and alll executed using
the sendCommand method described above. If echo is set, then the commands will
be echoed in the BQCommandConsole GUI. A return of -1 indicates an error opening
or reading the file.
-
QString getCommand (int command_index);
This will retrieve a prior command from the internal command history queue for index command_index.
Note that the index is in reverse order of when the command was entered so that index 0 corresponds to
the most recent command.
-
void setCommandCallback (std::function<BQ_commandCallback> commandCallback, BQ_ClientData client_data=NULL);
This will register into an internal callback queue a callback function, commandCallback, along with user data, clientData,
which will be called with the following syntax:
typedef void (BQ_commandCallback) (QString command, BQ_ClientData client_data);
-
where command is the last entered command, either through the GUI or remotely through sendCommand.
The application program will take the appropriate action, based upon command, and optionally
call printLineOutput, defined previously, to cause normal or error output to be displayed.
-
void removeCommandCallback (std::function<BQ_commandCallback> commandCallback);
This will cause the callback function commandCallback to be removed from the internal callback queue.
OBJECT CONFIGURATION PARAMETERS
-
font textFont
Specifies a font to use for displaying the command and output text strings.
Fonts are specified as "<family>[,<size>[,<weight>[,<italic?>]]]",
where <family> is a font family name, <size>size is a font size in integer points, <weight>
is an integer weight or can be one of Light, Normal, DemiBold, Bold or Black,
and <italic?> is a boolean (yes or no) to indicate if the font is in italics. System defaults
for <size>, <weight> and <italic?> are used if not specified.
This defaults to "courier,14".
-
color_foreground textColor
Specifies a color to use for drawing the command text.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "blue".
-
color_foreground_selection textSelectionColor
Specifies a color to use for drawing the command text characters when they are selected.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "lightyellow".
-
color_background backgroundColor
Specifies a color to use for filling the command text background.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "lightyellow".
-
color_background_selection backgroundSelectionColor
Specifies a color to use for filling the command text background characters when they are selected.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "blue".
-
color_background_outline outlineColor
Specifies a color to use for drawing an outline box around the text.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "".
-
color_output outputColor
Specifies a color to use for drawing the output text.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "black".
-
color_erroroutput erroroutputColor
Specifies a color to use for drawing the error output text.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "red".
-
color_prompt promptColor
Specifies a color to use for drawing the prompt characters.
Can be specified in any of the forms documented in BQ_ParseColor(3).
This defaults to "orange".
-
prompt promptString
Specifies a string to use for drawing the prompt.
This defaults to ">".
EXAMPLE
Following is a simple c++ example.
/I>
#include "BQ.h"
int
main (int argc, char **argv)
{
QApplication qapp(argc, argv);
qapp.setApplicationName("bqplot_test_commandconsole");
QWidget *widget = new QWidget();
widget->setWindowTitle("bqplot_test_commandconsole");
widget->show();
widget->resize (500, 200);
QGridLayout *layout = new QGridLayout (widget);
layout->setSpacing (0);
layout->setContentsMargins (0, 0, 0, 0);
widget->setLayout (layout);
BQCommandConsole *cc = new BQCommandConsole (widget);
cc->setCommandCallback ( [cc](QString command, BQ_ClientData client_data) {
char syscommand[512];
sprintf (syscommand, "(%s >test.stdout) >&test.stderr\n", command.BQ_QString2char);
system (syscommand);
QFile stdout("test.stdout");
QFile stderr("test.stderr");
QString line;
if (stdout.open(QIODevice::ReadOnly | QIODevice::Text)) {
while (!stdout.atEnd()) {
line = QString::fromLatin1(stdout.readLine().data());
cc->printLineOutput ("", line, 0, 0);
}
stdout.close();
system ("rm -f test.stdout");
}
if (stderr.open(QIODevice::ReadOnly | QIODevice::Text)) {
while (!stderr.atEnd()) {
line = QString::fromLatin1(stderr.readLine().data());
cc->printLineOutput ("", line, 1, 0);
}
stderr.close();
system ("rm -f test.stderr");
}
line.clear();
cc->printLineOutput ("", line, 0, 1);
} );
layout->addWidget (cc, 0, 0, 1, 1);
qapp.exec();
exit (0);
}
/I>
SEE ALSO
bqplot(3),
BQConfigure(3)
AUTHOR
Danny Harvey, BRTT