From 9dc43cc866664c5116f4519b2c1457d708a00f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Sun, 3 Mar 2024 18:34:18 +0100 Subject: [PATCH] Implement interactive mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolás Ortega Froysa --- pacundo.pl | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/pacundo.pl b/pacundo.pl index 537da2f..f417ceb 100755 --- a/pacundo.pl +++ b/pacundo.pl @@ -110,3 +110,48 @@ while ($found_txs < $num_txs && defined(my $line = $pacman_log->readline)) { } } } + + +# Interactive mode +if (!$r_flag) { + print("Last changes:\n"); + my $n = 1; + foreach my $tx (@undo_txs) { + if ($tx->{action} =~ /(upgraded|downgraded)/) { + format UPGRFORMAT = + @|| @<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<< -> @<<<<<<<<<<<<< +$n, $tx->{action}, $tx->{pkg_name}, $tx->{oldver}, $tx->{newver} +. + $~ = "UPGRFORMAT"; + } else { + format INSTFORMAT = + @|| @<< @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< +$n, $tx->{action}, $tx->{pkg_name} +. + $~ = "INSTFORMAT"; + } + write(); + $n++; + } + + print("Select transactions to undo (e.g. '1 2 3', '1-3')\n"); + print("> "); + my @sel = split(' ', ); + + foreach my $i (@sel) { + if ($i =~ /[0-9]-[0-9]/) { + my ($start, $end) = $i =~ /([0-9])-([0-9])/; + push(@sel, ($start..$end)); + } + } + + @sel = sort grep(!/[0-9]-[0-9]/, @sel); + + my @sel_undo; + + foreach my $i (@sel) { + push(@sel_undo, $undo_txs[$i-1]); + } + + @undo_txs = @sel_undo; +}