cvsdist b24462
#!/usr/bin/perl -w 
cvsdist b24462
cvsdist b24462
#requires Gtk-Perl
cvsdist b24462
cvsdist b24462
use Gtk;
cvsdist b24462
use strict;
cvsdist b24462
cvsdist b24462
set_locale Gtk;
cvsdist b24462
init Gtk;
cvsdist b24462
cvsdist b24462
my $window = new Gtk::Window("toplevel");
cvsdist b24462
$window->signal_connect( "delete_event", \&CloseAppWindow );  
cvsdist b24462
my $table = new Gtk::Table( 20, 6, 0 );
cvsdist b24462
$window->border_width( 5 );
cvsdist b24462
#$window->add( $button );
cvsdist b24462
cvsdist b24462
cvsdist b24462
my $prompt = new Gtk::Entry( 128);
cvsdist b24462
my $log = new Gtk::Text();
cvsdist b24462
$log->set_usize(40,60);
cvsdist b24462
$log->show();
cvsdist b24462
$prompt->show();
cvsdist b24462
#$prompt->set_editable (1);
cvsdist b24462
$prompt->set_text("");
cvsdist b24462
$table->attach( $prompt,0,4,0,4,[ 'expand', 'shrink', 'fill' ],
cvsdist b24462
		'shrink',
cvsdist b24462
		0, 0 ); 
cvsdist b24462
cvsdist b24462
$table->set_row_spacings( 5 ); 
cvsdist b24462
$table->set_col_spacings( 5 ); 
cvsdist b24462
cvsdist b24462
my $currDir = new Gtk::Button( "Current Directory" );
cvsdist b24462
$currDir->show();
cvsdist b24462
$table->attach_defaults( $currDir,0,1,4,6 );
cvsdist b24462
cvsdist b24462
my $errorCode = new Gtk::Button( "Last Return Code" );
cvsdist b24462
$errorCode->show();
cvsdist b24462
$table->attach_defaults( $errorCode,1,2,4,6 );
cvsdist b24462
cvsdist b24462
my $currTime = new Gtk::Button( "Time" );
cvsdist b24462
$currTime->show();
cvsdist b24462
$table->attach_defaults( $currTime,2,3,4,6 );
cvsdist b24462
cvsdist b24462
my $hist = new Gtk::Button( "History Number" );
cvsdist b24462
$hist->show();
cvsdist b24462
$table->attach_defaults( $hist,3,4,4,6 );
cvsdist b24462
cvsdist b24462
my $host = new Gtk::Button( "Hostname" );
cvsdist b24462
$host->show();
cvsdist b24462
$table->attach_defaults( $host,0,1,6,8 );
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
my $backgroundBlue = new Gtk::Button( "Blue Background" );
cvsdist b24462
$backgroundBlue->show();
cvsdist b24462
$table->attach_defaults( $backgroundBlue,0,1,8,10 );
cvsdist b24462
cvsdist b24462
my $backgroundRed = new Gtk::Button( "Red Background" );
cvsdist b24462
$backgroundRed->show();
cvsdist b24462
$table->attach_defaults( $backgroundRed,1,2,8,10 );
cvsdist b24462
cvsdist b24462
my $backgroundGreen = new Gtk::Button( "Green Background" );
cvsdist b24462
$backgroundGreen->show();
cvsdist b24462
$table->attach_defaults( $backgroundGreen,2,3,8,10 );
cvsdist b24462
cvsdist b24462
my $backgroundYellow = new Gtk::Button( "Yellow Background" );
cvsdist b24462
$backgroundYellow->show();
cvsdist b24462
$table->attach_defaults( $backgroundYellow,3,4,8,10 );
cvsdist b24462
cvsdist b24462
my $backgroundBlack = new Gtk::Button( "Black Background" );
cvsdist b24462
$backgroundBlack->show();
cvsdist b24462
$table->attach_defaults( $backgroundBlack,5,6,8,10 );
cvsdist b24462
cvsdist b24462
my $backgroundWhite = new Gtk::Button( "White Background" );
cvsdist b24462
$backgroundWhite->show();
cvsdist b24462
$table->attach_defaults( $backgroundWhite,6,7,8,10 );
cvsdist b24462
cvsdist b24462
my $backgroundPink = new Gtk::Button( "Pink Background" );
cvsdist b24462
$backgroundPink->show();
cvsdist b24462
$table->attach_defaults( $backgroundPink,7,8,8,10 );
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
my $textBlue = new Gtk::Button( "Blue Text" );
cvsdist b24462
$textBlue->show();
cvsdist b24462
$table->attach_defaults( $textBlue,0,1,10,12 );
cvsdist b24462
cvsdist b24462
my $textRed = new Gtk::Button( "Red Text" );
cvsdist b24462
$textRed->show();
cvsdist b24462
$table->attach_defaults( $textRed,1,2,10,12 );
cvsdist b24462
cvsdist b24462
my $textGreen = new Gtk::Button( "Green Text" );
cvsdist b24462
$textGreen->show();
cvsdist b24462
$table->attach_defaults( $textGreen,2,3,10,12 );
cvsdist b24462
cvsdist b24462
my $textYellow = new Gtk::Button( "Yellow Text" );
cvsdist b24462
$textYellow->show();
cvsdist b24462
$table->attach_defaults( $textYellow,3,4,10,12 );
cvsdist b24462
cvsdist b24462
my $textBlack = new Gtk::Button( "Black Text" );
cvsdist b24462
$textBlack->show();
cvsdist b24462
$table->attach_defaults( $textBlack,5,6,10,12 );
cvsdist b24462
cvsdist b24462
my $textWhite = new Gtk::Button( "White Text" );
cvsdist b24462
$textWhite->show();
cvsdist b24462
$table->attach_defaults( $textWhite,6,7,10,12 );
cvsdist b24462
cvsdist b24462
my $textPink = new Gtk::Button( "Pink Text" );
cvsdist b24462
$textPink->show();
cvsdist b24462
$table->attach_defaults( $textPink,7,8,10,12 );
cvsdist b24462
cvsdist b24462
cvsdist b24462
my $textDefault = new Gtk::Button( "Default Text" );
cvsdist b24462
$textDefault->show();
cvsdist b24462
$table->attach_defaults( $textDefault,0,1,12,14 );
cvsdist b24462
cvsdist b24462
my $backgroundDefault = new Gtk::Button( "Default Background" );
cvsdist b24462
$backgroundDefault->show();
cvsdist b24462
$table->attach_defaults( $backgroundDefault,1,2,12,14 );
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
my $set = new Gtk::Button( "Save Settings" );
cvsdist b24462
$set->show();
cvsdist b24462
$table->attach_defaults( $set,0,1,16,18 );
cvsdist b24462
cvsdist b24462
my $xterm = new Gtk::Button( "Test saved settings" );
cvsdist b24462
$xterm->show();
cvsdist b24462
$table->attach_defaults( $xterm,1,2,16,18 );
cvsdist b24462
cvsdist b24462
$table->attach_defaults( $log,0,6,18,20 );
cvsdist b24462
cvsdist b24462
cvsdist b24462
$currDir->signal_connect( "clicked", \&insertButtonText, "%1/" );
cvsdist b24462
$errorCode->signal_connect( "clicked", \&insertButtonText, "%?" );
cvsdist b24462
$currTime->signal_connect( "clicked", \&insertButtonText, "%T" );
cvsdist b24462
$hist->signal_connect( "clicked", \&insertButtonText, "%!" );
cvsdist b24462
$host->signal_connect( "clicked", \&insertButtonText, "%m" );
cvsdist b24462
cvsdist b24462
$backgroundBlue->signal_connect( "clicked", \&insertButtonText, "%{\$bg[blue]%}" );
cvsdist b24462
$backgroundRed->signal_connect( "clicked", \&insertButtonText, "%{\$bg[red]%}" );
cvsdist b24462
$backgroundGreen->signal_connect( "clicked", \&insertButtonText, "%{\$bg[green]%}" );
cvsdist b24462
$backgroundYellow->signal_connect( "clicked", \&insertButtonText, "%{\$bg[yellow]%}" );
cvsdist b24462
$backgroundBlack->signal_connect( "clicked", \&insertButtonText, "%{\$bg[black]%}" );
cvsdist b24462
$backgroundWhite->signal_connect( "clicked", \&insertButtonText, "%{\$bg[white]%}" );
cvsdist b24462
$backgroundPink->signal_connect( "clicked", \&insertButtonText, "%{\$bg[magenta]%}" );
cvsdist b24462
$backgroundDefault->signal_connect( "clicked", \&insertButtonText, "%{\$bg[default]%}" );
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
$textBlue->signal_connect( "clicked", \&insertButtonText, "%{\$fg[blue]%}" );
cvsdist b24462
$textRed->signal_connect( "clicked", \&insertButtonText, "%{\$fg[red]%}" );
cvsdist b24462
$textGreen->signal_connect( "clicked", \&insertButtonText, "%{\$fg[green]%}" );
cvsdist b24462
$textYellow->signal_connect( "clicked", \&insertButtonText, "%{\$fg[yellow]%}" );
cvsdist b24462
$textBlack->signal_connect( "clicked", \&insertButtonText, "%{\$fg[black]%}" );
cvsdist b24462
$textWhite->signal_connect( "clicked", \&insertButtonText, "%{\$fg[white]%}" );
cvsdist b24462
$textPink->signal_connect( "clicked", \&insertButtonText, "%{\$fg[magenta]%}" );
cvsdist b24462
$textDefault->signal_connect( "clicked", \&insertButtonText, "%{\$fg[default]%}" );
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
$set->signal_connect( "clicked", \&pushEnv );
cvsdist b24462
$xterm->signal_connect( "clicked", \&xterm );
cvsdist b24462
cvsdist b24462
sub xterm
cvsdist b24462
{
cvsdist b24462
my $string="xterm -e zsh -li&";
cvsdist b24462
#$string.=$prompt->get_text();
cvsdist b24462
cvsdist b24462
#$string.="' zsh -li\"& ";
cvsdist b24462
cvsdist b24462
system($string);
cvsdist b24462
# $prompt->append_text( $string );
cvsdist b24462
$log->insert( "", "white", "black", "executing:\n $string\n");
cvsdist b24462
}
cvsdist b24462
cvsdist b24462
cvsdist b24462
sub pushEnv
cvsdist b24462
{
cvsdist b24462
chdir("~");
cvsdist b24462
use Env qw(PS1);
cvsdist b24462
my $pNotSet=0;
cvsdist b24462
open(PROMPT, "+<", ".prompt") or $pNotSet=1;
cvsdist b24462
cvsdist b24462
cvsdist b24462
if($pNotSet)
cvsdist b24462
{
cvsdist b24462
    #$prompt->insert( "", "white", "black", "prompt is not set");
cvsdist b24462
    open(ZSHRC, '>>','.zshrc') or die "cannot open zshrc";
cvsdist b24462
    print ZSHRC ". ~/.prompt\n";
cvsdist b24462
    close (ZSHRC);
cvsdist b24462
}
cvsdist b24462
close (PROMPT);
cvsdist b24462
open(PROMPT, ">", ".prompt");
cvsdist b24462
print PROMPT "export PS1=\"",$prompt->get_text(),"\"\n";
cvsdist b24462
cvsdist b24462
#$prompt->insert( "", "white", "black", $PS1);
cvsdist b24462
cvsdist b24462
close(PROMPT);
cvsdist b24462
close(ZSHRC);
cvsdist b24462
$prompt->grab_focus();
cvsdist b24462
cvsdist b24462
}
cvsdist b24462
$prompt->can_default(1);
cvsdist b24462
$prompt->grab_default();
cvsdist b24462
$table->show();
cvsdist b24462
$window->add( $table );
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
cvsdist b24462
$window->show();
cvsdist b24462
$prompt->grab_focus();
cvsdist b24462
main Gtk;
cvsdist b24462
cvsdist b24462
exit( 0 );
cvsdist b24462
cvsdist b24462
sub CloseAppWindow
cvsdist b24462
{
cvsdist b24462
   Gtk->exit( 0 );
cvsdist b24462
   return 0;
cvsdist b24462
}
cvsdist b24462
cvsdist b24462
cvsdist b24462
sub insertButtonText 
cvsdist b24462
{
cvsdist b24462
    my ($widget, $txt) = @_;
cvsdist b24462
 $prompt->append_text( $txt );
cvsdist b24462
$prompt->grab_focus();
cvsdist b24462
}