diff options
author | Julian Andres Klode <julian.klode@canonical.com> | 2024-04-15 18:17:46 +0200 |
---|---|---|
committer | Julian Andres Klode <julian.klode@canonical.com> | 2024-04-19 20:49:05 +0200 |
commit | 31d328f10d13393936b4adb779a527befa289fa7 (patch) | |
tree | 805a4002899453fbef2041a099b8f57152a0ccfc | |
parent | ae1ff72fbee8b3f5d063e8baa86a64e3da11aeb2 (diff) |
Remove spurious newline inside `apt autoremove` message
Add a new `note` field to `ShowList` which contains a line to
be displayed after the list itself. This allows `ShowList` to
render a self-contained list block.
-rw-r--r-- | apt-private/private-install.cc | 23 | ||||
-rw-r--r-- | apt-private/private-output.h | 5 |
2 files changed, 17 insertions, 11 deletions
diff --git a/apt-private/private-install.cc b/apt-private/private-install.cc index 774c03d0a..60f8efae3 100644 --- a/apt-private/private-install.cc +++ b/apt-private/private-install.cc @@ -684,6 +684,16 @@ bool DoAutomaticRemove(CacheFile &Cache) // if we don't remove them, we should show them! if (doAutoRemove == false && autoRemoveCount != 0) { + std::string note; + std::string autocmd = "apt autoremove"; + if (getenv("SUDO_USER") != nullptr) + { + auto const envsudocmd = getenv("SUDO_COMMAND"); + auto const envshell = getenv("SHELL"); + if (envsudocmd == nullptr || envshell == nullptr || strcmp(envsudocmd, envshell) != 0) + autocmd = "sudo " + autocmd; + } + strprintf(note, P_("Use '%s' to remove it.", "Use '%s' to remove them.", autoRemoveCount), autocmd.c_str()); if (smallList == false) { // trigger marking now so that the package list is correct @@ -693,21 +703,14 @@ bool DoAutomaticRemove(CacheFile &Cache) "The following packages were automatically installed and are no longer required:", autoRemoveCount), Universe, [&Cache](pkgCache::PkgIterator const &Pkg) { return (*Cache)[Pkg].Garbage == true && (*Cache)[Pkg].Delete() == false; }, - &PrettyFullName, CandidateVersion(&Cache)); + &PrettyFullName, CandidateVersion(&Cache), "", note); } else + { ioprintf(c1out, P_("%lu package was automatically installed and is no longer required.\n", "%lu packages were automatically installed and are no longer required.\n", autoRemoveCount), autoRemoveCount); - std::string autocmd = "apt autoremove"; - if (getenv("SUDO_USER") != nullptr) - { - auto const envsudocmd = getenv("SUDO_COMMAND"); - auto const envshell = getenv("SHELL"); - if (envsudocmd == nullptr || envshell == nullptr || strcmp(envsudocmd, envshell) != 0) - autocmd = "sudo " + autocmd; + c1out << note << std::endl; } - ioprintf(c1out, P_("Use '%s' to remove it.", "Use '%s' to remove them.", autoRemoveCount), autocmd.c_str()); - c1out << std::endl; } return true; } diff --git a/apt-private/private-output.h b/apt-private/private-output.h index a3e961458..0eba6f4fb 100644 --- a/apt-private/private-output.h +++ b/apt-private/private-output.h @@ -43,7 +43,8 @@ template<class Container, class PredicateC, class DisplayP, class DisplayV> bool PredicateC Predicate, DisplayP PkgDisplay, DisplayV VerboseDisplay, - std::string colorName = "") + std::string colorName = "", + std::string Note = "") { size_t const ScreenWidth = (::ScreenWidth > 3) ? ::ScreenWidth - 3 : 0; int ScreenUsed = 0; @@ -105,6 +106,8 @@ template<class Container, class PredicateC, class DisplayP, class DisplayV> bool ShowWithColumns(out, PackageList, 2, ScreenWidth); out << resetColor; } + if (not Note.empty()) + out << Note << std::endl; if (_config->FindI("APT::Output-Version") >= 30) out << std::endl; return false; |