From a7a45ea626815639fd25ef4098fb66897b0582aa Mon Sep 17 00:00:00 2001 From: radj307 Date: Mon, 14 Feb 2022 20:20:15 -0500 Subject: [PATCH] use manual length printouts, fix data units being colorized --- conv2/main.cpp | 20 +++++++++++++------- convlib/include/unit.hpp | 3 +-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/conv2/main.cpp b/conv2/main.cpp index cdfe4a5..8d5ea0c 100644 --- a/conv2/main.cpp +++ b/conv2/main.cpp @@ -59,7 +59,7 @@ int main(const int argc, char** argv) }; try { - opt::ParamsAPI2 args{ argc, argv, 'F', "FOV"}; + opt::ParamsAPI2 args{ argc, argv, 'F', "FOV" }; const auto& getarg_any{ [&args](const std::optional& flag, const std::optional& opt) { if (flag.has_value() && opt.has_value()) @@ -105,13 +105,13 @@ int main(const int argc, char** argv) const auto in{ conv._in.value().get() }; buffer << color(OUTCOLOR::INPUT) << in->_value << color() - << ' ' << color(OUTCOLOR::INPUT) << in->_type << color() + << ' ' << in->_type << color(OUTCOLOR::OPERATOR) << " = " << color(); } const auto out{ conv._out.value().get() }; buffer << color(OUTCOLOR::OUTPUT) << out->_value << color() - << ' ' << color(OUTCOLOR::OUTPUT) << out->_type << color() << '\n'; + << ' ' << out->_type << '\n'; } } } @@ -176,7 +176,11 @@ int main(const int argc, char** argv) } }; for (auto it{ parameters.begin() }; it != parameters.end(); ++it) { if (std::distance(it, parameters.end()) >= 2ll) { - buffer << unit::Convert(get_tuple(it)) << '\n'; + const auto [in_unit, value, out_unit] { unit::Convert(get_tuple(it))._vars }; + const auto result{ unit::Convert::getResult(in_unit, value, out_unit) }; + if (!quiet) + buffer << color(OUTCOLOR::INPUT) << value << color() << ' ' << in_unit << ' ' << color(OUTCOLOR::OPERATOR) << '=' << color() << ' '; + buffer << color(OUTCOLOR::OUTPUT) << result << color() << '\n'; } } } @@ -199,13 +203,15 @@ int main(const int argc, char** argv) if (!quiet) { buffer << color(OUTCOLOR::INPUT) << v << color() << ' '; if (in_radians) - buffer << "rad" << ' '; - buffer << color(OUTCOLOR::OPERATOR) << '=' << color() << ' '; + buffer << "rad"; + else + buffer << "deg"; + buffer << ' ' << color(OUTCOLOR::OPERATOR) << '=' << color() << ' '; } if (in_radians) buffer << color(OUTCOLOR::OUTPUT) << toRadians(v) << color() << ' ' << "rad" << '\n'; else - buffer << color(OUTCOLOR::OUTPUT) << toDegrees(v) << color() << '\n'; + buffer << color(OUTCOLOR::OUTPUT) << toDegrees(v) << color() << ' ' << "deg" << '\n'; } } else if (const auto& fov{ getarg_any('F', "FOV") }; fov.has_value()) { diff --git a/convlib/include/unit.hpp b/convlib/include/unit.hpp index e3e7d1f..53abf5a 100644 --- a/convlib/include/unit.hpp +++ b/convlib/include/unit.hpp @@ -319,7 +319,7 @@ namespace unit { using Tuple = std::tuple; using StrTuple = std::tuple; using NumberT = long double; - private: + Tuple _vars; std::streamsize _min_indent{ 0ull }; @@ -349,7 +349,6 @@ namespace unit { return convert(input_unit, input, output_unit); } - public: /// @brief Default constructor Convert(std::tuple&& vars, const std::streamsize& min_indent = 0ull) : _vars{ std::move(convert_tuple(std::move(vars))) }, _min_indent{ min_indent } {} /**