From 1ec70d116104854988f530201706997a3fda3f29 Mon Sep 17 00:00:00 2001 From: surtur Date: Thu, 3 Feb 2022 04:52:19 +0100 Subject: [PATCH] fortuna,generator({fmt}) print with colours --- fortuna.cpp | 11 +++++++++-- generator.cpp | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/fortuna.cpp b/fortuna.cpp index 4549995..27cb0a3 100644 --- a/fortuna.cpp +++ b/fortuna.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -93,7 +94,11 @@ auto Fortuna::random_data(const uint64_t n_bytes) -> void { s.clear(); } - fmt::print(stderr, "[i] fortuna: reseed ctr {}\n", get_reseed_ctr()); + fmt::print(stderr, "[i] fortuna: reseed ctr "); + fmt::print(stderr, + fmt::emphasis::bold | bg(fmt::color::hot_pink), + "{}\n", + get_reseed_ctr()); if (get_reseed_ctr() == 0) { fmt::print(stderr, "[!] ERROR: reseed ctr is 0, PRNG not seeded!\n"); @@ -112,7 +117,9 @@ auto Fortuna::random_data(const uint64_t n_bytes) -> void { const auto end{std::chrono::system_clock::now()}; const std::chrono::duration diff = end - start; fmt::print(stderr, "random_data done - {}\n", end); - fmt::print(stderr, "getting random data took {:.{}f}s\n", diff.count(), 12); + fmt::print(stderr, "getting random data "); + fmt::print( + stderr, bg(fmt::color::dark_cyan), "took {:.{}f}s\n", diff.count(), 12); } // random_data auto Fortuna::moar_random_data(const uint64_t& n_bytes) -> void { diff --git a/generator.cpp b/generator.cpp index fb2dbc9..e4725bb 100644 --- a/generator.cpp +++ b/generator.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -76,10 +77,11 @@ auto Generator::reseed(const std::string& s) -> void { std::string a{fortuna::Util::do_sha(da_key + s)}; std::memmove(G.k, fortuna::Util::de_hex(a).c_str(), G.k_length); Generator::ctr_inc(); - fmt::print(stderr, "[i] generator: reseeded\n"); + fmt::print(stderr, "[i] generator: "); + fmt::print(stderr, bg(fmt::color::rebecca_purple), "reseeded\n"); } catch (std::exception& e) { - fmt::print(stderr, "{}\n", e.what()); + fmt::print(stderr, bg(fmt::color::red), "{}\n", e.what()); throw; } }