On Sun, 2014-10-05 at 12:32 +0800, Paul Wise wrote: > As promised here is a patch to make `mr -j1 -m foo` output continuously.
Unfortunately the patch had a bug, mr -m -j1 update would not output the \n that usually comes after output from a command, fixed in this patch. -- bye, pabs https://wiki.debian.org/PaulWise
From 320f99d0c1ba247f5b835e073d04a8835aeca84c Mon Sep 17 00:00:00 2001 From: Paul Wise <p...@debian.org> Date: Sun, 5 Oct 2014 12:21:39 +0800 Subject: [PATCH] Make output continuous in minimal mode when there is only one job Design choices include: Duplicate the loop to not check $continous for each output line. Make $continous an internal choice of terminal_friendly_spawn based on all the parameters so that each call of it behaves the same. Signed-off-by: Paul Wise <p...@debian.org> --- mr | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/mr b/mr index 7319f98..ce9dcf3 100755 --- a/mr +++ b/mr @@ -743,13 +743,27 @@ sub terminal_friendly_spawn { my $sh = shift; my $quiet = shift; my $minimal = shift; + my $jobs = shift; + my $continous = !$quiet && $minimal && 1 == $jobs; my $output = ""; + my $continous_output = 0; if ($terminal) { my $pty = IO::Pty::Easy->new; $pty->spawn($sh); - while ($pty->is_active) { - my $data = $pty->read(); - $output .= $data if defined $data; + if ($continous) { + while ($pty->is_active) { + my $data = $pty->read(); + if ($data) { + print "$actionmsg\n" if ($actionmsg && !$continous_output); + $continous_output = 1; + print $data; + } + } + } else { + while ($pty->is_active) { + my $data = $pty->read(); + $output .= $data if defined $data; + } } $pty->close; } else { @@ -763,7 +777,7 @@ sub terminal_friendly_spawn { print "$actionmsg\n" if $actionmsg; print $output; } - return ($ret, $output ? 1 : 0); + return ($ret, ($output || $continous_output) ? 1 : 0); } sub action { @@ -868,7 +882,7 @@ sub action { $command, \@ARGV, sub { my $sh=shift; if (!$jobs || $jobs > 1 || $quiet || $minimal) { - return terminal_friendly_spawn($actionmsg, $sh, $quiet, $minimal); + return terminal_friendly_spawn($actionmsg, $sh, $quiet, $minimal, $jobs); } else { system($sh); @@ -933,7 +947,7 @@ sub hook { my ($ret,$out)=runsh $hook, $topdir, $subdir, $command, [], sub { my $sh=shift; if (!$jobs || $jobs > 1 || $quiet || $minimal) { - return terminal_friendly_spawn(undef, $sh, $quiet, $minimal); + return terminal_friendly_spawn(undef, $sh, $quiet, $minimal, $jobs); } else { system($sh); -- 2.1.1
signature.asc
Description: This is a digitally signed message part