2025-09-25 15:29:55 +08:00
|
|
|
#include "manual.hpp"
|
|
|
|
#include "../termcolor.hpp"
|
|
|
|
#include "../../patch/stream.hpp"
|
2025-09-25 15:52:28 +08:00
|
|
|
#include "../../patch/format.hpp"
|
2025-10-01 20:53:43 +08:00
|
|
|
#include "../../string/op.hpp"
|
|
|
|
#include <ranges>
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
#define CLAP ::yycc::carton::clap
|
|
|
|
#define TABULATE ::yycc::carton::tabulate
|
|
|
|
#define TERMCOLOR ::yycc::carton::termcolor
|
2025-10-01 20:53:43 +08:00
|
|
|
#define OP ::yycc::string::op
|
2025-09-25 15:52:28 +08:00
|
|
|
#define FORMAT ::yycc::patch::format
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
using namespace ::yycc::patch::stream;
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
namespace yycc::carton::clap::manual {
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
#pragma region Manual Translation
|
|
|
|
|
|
|
|
ManualTr::ManualTr() :
|
|
|
|
author_and_version(u8"Invented by {0}. Version {1}."), usage_title(u8"Usage:"), usage_body(u8"{0} <options> ..."),
|
|
|
|
avail_opt(u8"Available options:"), avail_var(u8"Available environment variables:") {}
|
|
|
|
|
|
|
|
ManualTr::~ManualTr() {}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
#pragma region Manual
|
|
|
|
|
|
|
|
using Application = CLAP::application::Application;
|
|
|
|
using Tabulate = TABULATE::Tabulate;
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
static constexpr char8_t INDENT[] = u8" ";
|
|
|
|
|
2025-09-25 15:29:55 +08:00
|
|
|
Manual::Manual(const Application &app, ManualTr &&trctx) : trctx(std::move(trctx)), app(app), opt_printer(3), var_printer(2) {
|
|
|
|
this->setup_table();
|
|
|
|
this->fill_opt_table();
|
|
|
|
this->fill_var_table();
|
|
|
|
}
|
|
|
|
|
|
|
|
Manual::~Manual() {}
|
|
|
|
|
|
|
|
void Manual::setup_table() {
|
|
|
|
this->opt_printer.show_header(false);
|
|
|
|
this->opt_printer.show_bar(false);
|
2025-09-25 15:52:28 +08:00
|
|
|
this->opt_printer.set_prefix(INDENT);
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
this->var_printer.show_header(false);
|
|
|
|
this->var_printer.show_bar(false);
|
2025-09-25 15:52:28 +08:00
|
|
|
this->var_printer.set_prefix(INDENT);
|
2025-09-25 15:29:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manual::fill_opt_table() {
|
|
|
|
const auto &options = app.get_options();
|
|
|
|
for (const auto ®_opt : options.all_options()) {
|
|
|
|
const auto &opt = reg_opt.get_option();
|
2025-10-01 20:53:43 +08:00
|
|
|
|
|
|
|
//for (const auto [index, item] : std::views::enumerate(header)) {
|
|
|
|
//
|
|
|
|
//}
|
2025-09-25 15:29:55 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Manual::fill_var_table() {}
|
|
|
|
|
|
|
|
void Manual::print_version(std::ostream &dst) const {
|
|
|
|
const auto &summary = this->app.get_summary();
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
TERMCOLOR::cprintln(summary.get_name(), TERMCOLOR::Color::Yellow, TERMCOLOR::Color::Default, TERMCOLOR::Attribute::Default, dst);
|
|
|
|
dst << summary.get_name() << std::endl;
|
|
|
|
dst << FORMAT::format(trctx.author_and_version, summary.get_author(), summary.get_version()) << std::endl;
|
2025-09-25 15:29:55 +08:00
|
|
|
dst << summary.get_description() << std::endl;
|
|
|
|
dst << std::endl;
|
|
|
|
}
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
void Manual::print_help(std::ostream &dst) const {
|
|
|
|
this->print_version();
|
|
|
|
|
|
|
|
TERMCOLOR::cprintln(trctx.usage_title, TERMCOLOR::Color::Yellow, TERMCOLOR::Color::Default, TERMCOLOR::Attribute::Default, dst);
|
|
|
|
dst << INDENT << FORMAT::format(trctx.usage_body, app.get_summary().get_bin_name()) << std::endl;
|
|
|
|
|
|
|
|
const auto &variables = app.get_variables();
|
|
|
|
if (!variables.empty()) {
|
|
|
|
TERMCOLOR::cprintln(trctx.avail_var, TERMCOLOR::Color::Yellow, TERMCOLOR::Color::Default, TERMCOLOR::Attribute::Default, dst);
|
|
|
|
this->var_printer.print(dst);
|
|
|
|
dst << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
const auto &options = app.get_options();
|
|
|
|
if (!options.empty()) {
|
|
|
|
TERMCOLOR::cprintln(trctx.avail_opt, TERMCOLOR::Color::Yellow, TERMCOLOR::Color::Default, TERMCOLOR::Attribute::Default, dst);
|
|
|
|
this->opt_printer.print(dst);
|
|
|
|
dst << std::endl;
|
|
|
|
}
|
|
|
|
}
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
} // namespace yycc::carton::clap::manual
|