Skip to content

Commit

Permalink
predict: Show skip row for --first
Browse files Browse the repository at this point in the history
This one turned out to be trivial. Removing the "hidden" count from the summary line, as it seems
redundant and less clear.
  • Loading branch information
vincentdephily committed Oct 31, 2024
1 parent 1481285 commit 0f8c759
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 24 deletions.
9 changes: 5 additions & 4 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,11 @@ pub fn cmd_predict(gc: Conf, mut sc: ConfPred) -> Result<bool, Error> {
}
}
}
let lastskip = totcount.saturating_sub(sc.first);
if sc.show.merge && gc.showskip && lastskip > 0 {
tbl.skiprow(&[&gc.skip, &"(skip last ", &lastskip, &")"]);
}
// Print summary line
if totcount > 0 {
if sc.show.tot {
let mut s: Vec<&dyn Disp> = vec![&"Estimate for ",
Expand All @@ -454,10 +459,6 @@ pub fn cmd_predict(gc: Conf, mut sc: ConfPred) -> Result<bool, Error> {
if totunknown > 0 {
s.extend::<[&dyn Disp; 5]>([&", ", &gc.cnt, &totunknown, &gc.clr, &" unknown"]);
}
let tothidden = totcount.saturating_sub(sc.first.min(last - 1));
if tothidden > 0 {
s.extend::<[&dyn Disp; 5]>([&", ", &gc.cnt, &tothidden, &gc.clr, &" hidden"]);
}
let e = FmtDur(totelapsed);
if totelapsed > 0 {
s.extend::<[&dyn Disp; 4]>([&", ", &e, &gc.clr, &" elapsed"]);
Expand Down
4 changes: 2 additions & 2 deletions src/config/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ pub fn build_cli() -> Command {
.help_heading("Filter")
.help("Show only the last <num> entries")
.long_help("Show only the last <num> entries\n \
(empty)|1: last entry\n \
5: last 5 entries\n");
(empty)|1: last entry\n \
5: last 5 entries\n");
let h = "Use main, backup, either, or no portage resume list\n\
This is ignored if STDIN is a piped `emerge -p` output\n \
(default)|auto|a: Use main or backup resume list, if currently emerging\n \
Expand Down
65 changes: 47 additions & 18 deletions tests/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,26 +211,55 @@ fn predict_tty() {
#[ignore]
#[test]
fn predict_emerge_p() {
let t = [// Check garbage input
("blah blah\n", format!("No pretended merge found\n"), 1),
// Check all-unknowns
("[ebuild R ~] dev-lang/unknown-1.42\n",
format!("dev-lang/unknown-1.42 ? \n\
Estimate for 1 ebuild, 1 unknown 10 @ {}\n",
ts(10)),
0),
// Check that unknown ebuild don't wreck alignment. Remember that times are {:>9}
("[ebuild R ~] dev-qt/qtcore-5.9.4-r2\n\
let t =
[// Check garbage input
("%F10000.log p --date unix -oc",
"blah blah\n",
format!("No pretended merge found\n"),
1),
// Check all-unknowns
("%F10000.log p --date unix -oc",
"[ebuild R ~] dev-lang/unknown-1.42\n",
format!("dev-lang/unknown-1.42 ? \n\
Estimate for 1 ebuild, 1 unknown 10 @ {}\n",
ts(10)),
0),
// Check that unknown ebuild don't wreck alignment. Remember that times are {:>9}
("%F10000.log p --date unix -oc",
"[ebuild R ~] dev-qt/qtcore-5.9.4-r2\n\
[ebuild R ~] dev-lang/unknown-1.42\n\
[ebuild R ~] dev-qt/qtgui-5.9.4-r3\n",
format!("dev-qt/qtcore-5.9.4-r2 3:45 \n\
dev-lang/unknown-1.42 ? \n\
dev-qt/qtgui-5.9.4-r3 4:24 \n\
Estimate for 3 ebuilds, 1 unknown 8:19 @ {}\n",
ts(8 * 60 + 9 + 10)),
0)];
for (i, o, e) in t {
emlop("%F10000.log p --date unix -oc").write_stdin(i).assert().code(e).stdout(o);
format!("dev-qt/qtcore-5.9.4-r2 3:45 \n\
dev-lang/unknown-1.42 ? \n\
dev-qt/qtgui-5.9.4-r3 4:24 \n\
Estimate for 3 ebuilds, 1 unknown 8:19 @ {}\n",
ts(8 * 60 + 9 + 10)),
0),
// Check skip rows
("%F10000.log p --date unix -oc --show m --first 2",
"[ebuild R ~] dev-qt/qtcore-1\n\
[ebuild R ~] dev-qt/qtcore-2\n\
[ebuild R ~] dev-qt/qtcore-3\n\
[ebuild R ~] dev-qt/qtcore-4\n\
[ebuild R ~] dev-qt/qtcore-5\n",
"dev-qt/qtcore-1 3:45\n\
dev-qt/qtcore-2 3:45\n\
(skip last 3) \n"
.into(),
0),
("%F10000.log p --date unix -oc --show m --first 2 --last 1",
"[ebuild R ~] dev-qt/qtcore-1\n\
[ebuild R ~] dev-qt/qtcore-2\n\
[ebuild R ~] dev-qt/qtcore-3\n\
[ebuild R ~] dev-qt/qtcore-4\n\
[ebuild R ~] dev-qt/qtcore-5\n",
"(skip first 1)\n\
dev-qt/qtcore-2 3:45\n\
(skip last 3) \n"
.into(),
0)];
for (a, i, o, e) in t {
emlop(a).write_stdin(i).assert().code(e).stdout(o);
}
}

Expand Down

0 comments on commit 0f8c759

Please sign in to comment.