GTM
view release on metacpan or search on metacpan
45678910111213141516171819202122230.5 Thu Feb 18 09:22:42 MET 2010
- added Global Output (
%GO
)
- added GTM::Run
0.4 Fri Feb 12 14:08:49 MET 2010
- code cleanup
- implemented a global selector
0.3 Thu Feb 11 12:39:25 MET 2010
- traffic light blinks
if
busy
- fixed a
lock
issue (missing callback)
- console defaults to x-terminal-emulator
use
: update-alternatives --config x-terminal-emulator
0.2 Wed Feb 10 11:16:41 MET 2010
- added console (Alt-C)
0.1 Wed Feb 10 09:03:27 MET 2010
- initial version
2728293031323334353637383940414243444546=head1 FILES
~/.gtmrc
preferences (you can source it).
=cut
BEGIN {
our
@EXPORT_OK
=
qw(set_busy output %override save_prefs)
;
our
@EXPORT
= ();
}
use
GTM::Run ();
our
%override
;
our
(
$gtm_version
,
$gtm_utf8
);
our
@gtm_variables
= (
qw/gtm_dist gtmroutines gtmgbldir gtm_log gtm_chset gtm_icu_version/
);
956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993my
$main_scroll
;
sub
output {
my
$lines
=
join
""
,
@_
;
return
unless
length
$lines
;
scrollarea_output (
$main_scroll
,
$lines
);
}
sub
gtm_run ($@) {
set_busy (1);
local
%ENV
= (
%ENV
,
%override
);
my
(
$cmd
,
%rest
) =
@_
;
if
(
ref
$cmd
eq
"ARRAY"
) {
$cmd
->[0] =
"$ENV{gtm_dist}/$cmd->[0]"
unless
$cmd
->[0] =~ m@^/@;
}
else
{
$cmd
=
"$ENV{gtm_dist}/$cmd"
unless
$cmd
=~ m@^/@;
}
output
"#"
x 78 .
"\n"
;
output
"# running: "
,
ref
$cmd
eq
"ARRAY"
?
join
" "
,
@$cmd
:
$cmd
;
output
"\n"
.
"#"
x 78 .
"\n"
;
my
$cv
= run_cmd (
$cmd
,
%rest
);
$cv
->cb (
sub
{
shift
->
recv
and
do
{
warn
"error running cmd: $!\n"
; set_busy (0);
return
; };
$rest
{cb}->()
if
exists
$rest
{cb};
set_busy (0);
}
);
}
sub
gtm_run_out (@) {
my
(
$cmd
,
%r
) = (
shift
,
">"
=>
sub
{ output (
@_
); },
"2>"
=>
sub
{ output (
@_
); },
@_
112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
$main_window
->signal_connect (
destroy
=>
sub
{ main_quit Gtk2; });
win_size (
$main_window
,
"main_window"
, 960, 600);
my
$v
= new Gtk2::VBox;
$v
->pack_start (
$menu
->{widget}, 0, 0, 0);
$v
->pack_start (
$button
, 0, 0, 0);
$v
->add (
$main_scroll
);
$main_window
->add (
$v
);
$main_window
->add_accel_group (
$menu
->{accel_group});
load_prefs;
set_busy (0);
get_gtm_version();
$main_window
;
}
my
$was_busy
= 1;
my
$timer
;
my
$counter
= 0;
my
(
$red
,
$green
,
$off
);
$button
= new Gtk2::Button;
$green
= new_from_file Gtk2::Image (findfile (
"GTM/images/ampel-green.png"
));
$red
= new_from_file Gtk2::Image (findfile (
"GTM/images/ampel-red.png"
));
$off
= new_from_file Gtk2::Image (findfile (
"GTM/images/ampel-off.png"
));
sub
set_busy ($) {
my
$busy
=
shift
;
return
if
$was_busy
==
$busy
;
if
(
$busy
== 0) {
undef
$timer
;
$button
->set_image (
$green
);
}
else
{
$counter
= 0;
$timer
= AnyEvent->timer (
after
=> 0,
interval
=> .25,
cb
=>
sub
{
$button
->set_image (++
$counter
% 2 ?
$red
:
$off
);
}
);
}
$was_busy
=
$busy
;
}
=head1 SEE ALSO
L<GTM::Run>
=head1 AUTHOR
Stefan Traby <stefan@hello-penguin.com>
lib/GTM/Run.pm view on Meta::CPAN
282930313233343536373839404142434445464748=cut
package GTM::Run;
use common::sense;
use AnyEvent;
use AnyEvent::Util;
use AnyEvent::Handle;
use POSIX qw(setsid dup2 _exit waitpid);
use re 'eval';
use GTM qw(set_busy output %override);
our $VERSION = $GTM::VERSION;
our $midx;
=item $handle = B<new> GTM::Run ($command)
Creates a GTM::Run object.
The $command is either a single string, which is then passed to a shell, or an arrayref,
which is passed to the "execvp" function.
If command is not a fully qualified command (ie: starts not with /) $ENV{gtm_dist} will be prepended.
lib/GTM/Run.pm view on Meta::CPAN
828384858687888990919293949596979899100101102
no_delay
=> 1,
on_error
=>
sub
{
my
(
$hdl
,
$fatal
,
$msg
) =
@_
;
die
"on_error fatal=$fatal msg=\"$msg\"\n"
;
$hdl
->destroy;
},
);
$self
->{pid} =
$pid
;
$self
->{hdl} =
$hdl
;
set_busy (1);
$self
;
}
sub
merge_regexp (@) {
my
@re
=
@_
;
@re
=
map
{
qr{(?:$_(?{$GTM::Run::midx= mArK;}
))}x }
@re
;
my
$r
=
join
"|"
,
@re
;
$r
=~ s/mArK/
$_
/
for
(0 ..
@re
- 1);
$r
;
}
lib/GTM/Run.pm view on Meta::CPAN
111112113114115116117118119120121122123124125126127128129130sub
close
($) {
my
$self
=
shift
;
my
$hdl
=
$self
->{hdl};
die
"already closed"
if
$self
->{closed};
$hdl
->on_eof (
undef
);
$hdl
->on_error (
sub
{ });
$hdl
->on_read (
sub
{ });
$self
->flush;
$hdl
->destroy;
waitpid
(
$self
->{pid}, 0)
if
kill
(0,
$self
->{pid});
set_busy (0);
$self
->{closed} = 1;
}
=item $handle->B<write> ($data, ...)
writes $data to the process
=cut
( run in 0.248 second using v1.01-cache-2.11-cpan-1dc43b0fbd2 )