Skip to content

Commit

Permalink
use manual length printouts, fix data units being colorized
Browse files Browse the repository at this point in the history
  • Loading branch information
radj307 committed Feb 15, 2022
1 parent bb1c3ba commit a7a45ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 13 additions & 7 deletions conv2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char>& flag, const std::optional<std::string>& opt) {
if (flag.has_value() && opt.has_value())
Expand Down Expand Up @@ -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';
}
}
}
Expand Down Expand Up @@ -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';
}
}
}
Expand All @@ -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()) {
Expand Down
3 changes: 1 addition & 2 deletions convlib/include/unit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ namespace unit {
using Tuple = std::tuple<Unit, long double, Unit>;
using StrTuple = std::tuple<std::string, std::string, std::string>;
using NumberT = long double;
private:

Tuple _vars;
std::streamsize _min_indent{ 0ull };

Expand Down Expand Up @@ -349,7 +349,6 @@ namespace unit {
return convert(input_unit, input, output_unit);
}

public:
/// @brief Default constructor
Convert(std::tuple<std::string, std::string, std::string>&& vars, const std::streamsize& min_indent = 0ull) : _vars{ std::move(convert_tuple(std::move(vars))) }, _min_indent{ min_indent } {}
/**
Expand Down

0 comments on commit a7a45ea

Please sign in to comment.