The CommandWidget is nearly like a
terminal and allows the user to issue commands to a shell
and view the result in a GtkTextView widget.
Details
This widget can be used if you want to run some
commands in the background and never use any more any
printf. Or if you have some text output at
console the and would like to see it in a window.
CommandWidget can do that for you.
CommandWidget is a external process or a
shell connected to a GtkTextview to display
results. This connexion is made throught a pipe.
You can read and write to this external process. This can be a
(nearly) full interactive process, just like terminals
(command.com for Windows). There is a
special class with output only and really easy to use. It could be
used to proide feedback to some management tasks using
external commands (say, tar for example).
Example of use
The code below wil create a window just like the one on top
of this page. You can send commands using the text entry field
at the bottom of the windows, and the results are displayed on
the top part (a GtkTextView widget).
Text color is higlighted for commands and errors.
<?php
# create the main window
$window = new GtkWindow();
$window->set_size_request(400, 500);
$window->set_position(Gtk::WIN_POS_CENTER);
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
$window->set_title('CommandWidget demo');
# putenv('TERM=dumb');
$window->add(new CommandWidget('/bin/bash'));
$window->show_all();
Gtk::main();
?>
ShellCommandWidget
ShellCommandWidget is a derived class to
simplify usage for text output only for external commands.
This widget has no entry widget, so commands can only sent from
a script. This widget creates a pipe with a standard shell
waiting for commands to be executed. Here is an example of
use (this is a bit similar to CommandWidget:
<?php
# create the main window
$window = new GtkWindow();
$window->set_size_request(40, 50);
$window->set_position(Gtk::WIN_POS_CENTER);
$window->connect_simple('destroy', array('Gtk', 'main_quit'));
$window->add($shell = new ShellCommandWidget());
$window->show_all();
$shell->exec('ls -al ; ps -aef');
$shell->exec('ls -al /etc | grep ".conf"');
$shell->exec('who am I');
$shell->exec('whoami');
$shell->exec('make love'); # echo to stderr (not working now)
Gtk::main();
?>
Full source code
See the attached sources file below
Bugs
See on source code header
Recent comments
6 weeks 2 days ago
12 weeks 1 day ago
13 weeks 6 days ago
20 weeks 2 days ago
21 weeks 4 days ago
21 weeks 6 days ago
22 weeks 6 days ago
23 weeks 5 days ago
34 weeks 4 days ago
34 weeks 4 days ago