| 1 | package Psh::Strategy::Auto_resume; | ||
| 2 | |||
| 3 | =item * C<auto_resume> | ||
| 4 | |||
| 5 | If the input line matches the name of a stopped job | ||
| 6 | then brings that job to the foreground instead of starting | ||
| 7 | a new program with that name | ||
| 8 | |||
| 9 | =cut | ||
| 10 | |||
| 11 | require Psh::Strategy; | ||
| 12 | require Psh::Joblist; | ||
| 13 | |||
| 14 | @Psh::Strategy::Auto_resume::ISA=('Psh::Strategy'); | ||
| 15 | |||
| 16 | sub new { Psh::Strategy::new(@_) } | ||
| 17 | |||
| 18 | sub consumes { | ||
| 19 | return Psh::Strategy::CONSUME_TOKENS; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub applies { | ||
| 23 | my $fnname= ${$_[2]}[0]; | ||
| 24 | if( my($index, $pid, $call)= | ||
| 25 | Psh::Joblist::find_last_with_name($fnname,1)) | ||
| 26 | { | ||
| 27 | return "auto-resume $call"; | ||
| 28 | } | ||
| 29 | return ''; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub execute { | ||
| 33 | my $fnname= ${$_[2]}[0]; | ||
| 34 | my ($index)= Psh::Joblist::find_last_with_name($fnname,1); | ||
| 35 | Psh::OS::restart_job(1,$index); | ||
| 36 | return (1,undef); | ||
| 37 | } | ||
| 38 | |||
| 39 | sub runs_before { | ||
| 40 | return qw(perlscript executable); | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; |