Package: myrepos
Severity: wishlist
Usertags: sentpatch

As promised here is a patch to make `mr -j1 -m foo` output continuously.

    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.

-- 
bye,
pabs

https://wiki.debian.org/PaulWise

From 30bdc7b11ebbf93d4a5cb8a61cc912722c84873e Mon Sep 17 00:00:00 2001
From: Paul Wise <[email protected]>
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 <[email protected]>
---
 mr | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/mr b/mr
index 7319f98..40cb550 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 = "";
 	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) {
+			my $first = 1;
+			while ($pty->is_active) {
+				my $data = $pty->read();
+				if ($data) {
+					print "$actionmsg\n" if ($actionmsg && $first);
+					$first = 0;
+					print $data;
+				}
+			}
+		} else {
+			while ($pty->is_active) {
+				my $data = $pty->read();
+				$output .= $data if defined $data;
+			}
 		}
 		$pty->close;
 	} else {
@@ -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

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to