packages.hpcstat: remove front color for disk usage

This commit is contained in:
陈浩南 2024-09-25 10:34:26 +08:00
parent 7bf49c8180
commit 72912c67cf
4 changed files with 20 additions and 16 deletions

View File

@ -11,8 +11,16 @@
openssh = (pkgs.pkgsStatic.openssh.override { withLdns = false; etcDir = null; }).overrideAttrs
(prev: { doCheck = false; patches = prev.patches ++ [ ../packages/hpcstat/openssh.patch ];});
duc = pkgs.pkgsStatic.duc.override { enableCairo = false; cairo = null; pango = null; };
# pkgsStatic.clangStdenv have a bug
# https://github.com/NixOS/nixpkgs/issues/177129
biu = pkgs.pkgsStatic.localPackages.biu.override { stdenv = pkgs.pkgsStatic.gcc14Stdenv; };
in pkgs.pkgsStatic.localPackages.hpcstat.override
{ inherit openssh duc; standalone = true; version = inputs.self.rev or "dirty"; };
{
inherit openssh duc biu;
standalone = true;
version = inputs.self.rev or "dirty";
stdenv = pkgs.pkgsStatic.gcc14Stdenv;
};
chn-bsub = pkgs.pkgsStatic.localPackages.chn-bsub;
blog = pkgs.callPackage inputs.blog { inherit (inputs) hextra; };
}

View File

@ -2,6 +2,7 @@
int main()
{
using namespace biu::literals;
struct student
{
int number;

View File

@ -12,10 +12,9 @@ endif()
set(HPCSTAT_VERSION "unknown" CACHE STRING "Version of the hpcstat")
find_package(Boost REQUIRED COMPONENTS headers filesystem)
find_package(Boost REQUIRED COMPONENTS url)
find_package(SqliteOrm REQUIRED)
find_package(nlohmann_json REQUIRED)
find_package(range-v3 REQUIRED)
find_package(date REQUIRED)
find_package(httplib REQUIRED)
find_package(termcolor REQUIRED)
@ -27,9 +26,8 @@ add_executable(hpcstat src/main.cpp src/env.cpp src/keys.cpp src/ssh.cpp src/sql
# target_compile_features(hpcstat PRIVATE cxx_std_26)
target_compile_options(hpcstat PRIVATE "-std=c++26")
target_include_directories(hpcstat PRIVATE ${PROJECT_SOURCE_DIR}/include)
target_link_libraries(hpcstat PRIVATE Boost::headers Boost::filesystem sqlite_orm::sqlite_orm
nlohmann_json::nlohmann_json range-v3::range-v3 date::date date::date-tz httplib::httplib
termcolor::termcolor biu::biu OpenXLSX::OpenXLSX)
target_link_libraries(hpcstat PRIVATE Boost::url sqlite_orm::sqlite_orm nlohmann_json::nlohmann_json date::date
date::date-tz httplib::httplib termcolor::termcolor biu::biu OpenXLSX::OpenXLSX)
target_compile_definitions(hpcstat PRIVATE HPCSTAT_VERSION="${HPCSTAT_VERSION}")
install(TARGETS hpcstat RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

View File

@ -53,23 +53,20 @@ int main(int argc, const char** argv)
double percent = disk_stat->Total / 800 * 100;
auto color = percent > 95 ? termcolor::red<char> :
percent > 80 ? termcolor::yellow<char> : termcolor::green<char>;
auto bgcolor = percent > 95 ? termcolor::on_red<char> :
percent > 80 ? termcolor::on_yellow<char> : termcolor::on_green<char>;
std::cout
<< color << "disk usage: " << termcolor::reset
<< bgcolor << termcolor::white
<< "{:.1f}% ({:.1f}GB / ~800GB)"_f(percent, disk_stat->Total) << termcolor::reset
<< color << " (estimated, counted at {})\n"_f(disk_stat->Time) << termcolor::reset;
// 设置背景色后有时会难以辨认,因此只设置前景色
std::cout << color
<< "disk usage: {:.1f}% ({:.1f}GB / ~800GB) (estimated, counted at {})\n"_f
(percent, disk_stat->Total, disk_stat->Time);
if (percent > 80)
{
std::cout << color << "Top 3 directories owned by teacher:\n";
std::cout << "Top 3 directories owned by teacher:\n";
for (auto& [name, size] : disk_stat->Teacher | ranges::views::take(3))
std::cout << " {:.1f}GB {}\n"_f(size, name);
std::cout << color << "Top 3 directories owned by student:\n";
std::cout << "Top 3 directories owned by student:\n";
for (auto& [name, size] : disk_stat->Student | ranges::views::take(3))
std::cout << " {:.1f}GB {}\n"_f(size, name);
std::cout << termcolor::reset;
}
std::cout << termcolor::reset;
}
}
}