feat: add utf8 format
- move utf8 stream and format patch from string to patch namespace. - add ordinay format alias and utf8 format in our format patch. - add char8_t and char inter-cast in string reinterpret namespace. - fix bug of utf8 formatter. - add test for utf8 format.
This commit is contained in:
@ -1,12 +1,12 @@
|
||||
#include "application.hpp"
|
||||
|
||||
#define NS_YYCC_CLAP ::yycc::carton::clap
|
||||
#define CLAP ::yycc::carton::clap
|
||||
|
||||
namespace yycc::carton::clap::application {
|
||||
|
||||
using Summary = NS_YYCC_CLAP::summary::Summary;
|
||||
using OptionCollection = NS_YYCC_CLAP::option::OptionCollection;
|
||||
using VariableCollection = NS_YYCC_CLAP::variable::VariableCollection;
|
||||
using Summary = CLAP::summary::Summary;
|
||||
using OptionCollection = CLAP::option::OptionCollection;
|
||||
using VariableCollection = CLAP::variable::VariableCollection;
|
||||
|
||||
Application::Application(Summary &&summary, OptionCollection &&options, VariableCollection &&variables) :
|
||||
summary(std::move(summary)), options(std::move(options)), variables(std::move(variables)) {}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#include "summary.hpp"
|
||||
#include "option.hpp"
|
||||
#include "variable.hpp"
|
||||
#include "../../macro/class_copy_move.hpp"
|
||||
|
||||
#define NS_YYCC_CLAP ::yycc::carton::clap
|
||||
|
||||
|
||||
69
src/yycc/carton/clap/manual.cpp
Normal file
69
src/yycc/carton/clap/manual.cpp
Normal file
@ -0,0 +1,69 @@
|
||||
#include "manual.hpp"
|
||||
#include "../termcolor.hpp"
|
||||
#include "../../patch/stream.hpp"
|
||||
#include "../../string/op.hpp"
|
||||
|
||||
#define CLAP ::yycc::carton::clap
|
||||
#define TABULATE ::yycc::carton::tabulate
|
||||
#define TERMCOLOR ::yycc::carton::termcolor
|
||||
#define OP ::yycc::carton::op
|
||||
|
||||
using namespace ::yycc::patch::stream;
|
||||
|
||||
namespace yycc::carton::clap::manual::Manual {
|
||||
|
||||
#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;
|
||||
|
||||
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);
|
||||
this->opt_printer.set_prefix(u8" ");
|
||||
|
||||
this->var_printer.show_header(false);
|
||||
this->var_printer.show_bar(false);
|
||||
this->var_printer.set_prefix(u8" ");
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
void Manual::fill_var_table() {}
|
||||
|
||||
void Manual::print_version(std::ostream &dst) const {
|
||||
const auto &summary = this->app.get_summary();
|
||||
|
||||
dst << std::format
|
||||
dst << summary.get_description() << std::endl;
|
||||
dst << std::endl;
|
||||
}
|
||||
|
||||
void Manual::print_help(std::ostream &dst) const {}
|
||||
|
||||
#pragma endregion
|
||||
|
||||
} // namespace yycc::carton::clap::manual::Manual
|
||||
49
src/yycc/carton/clap/manual.hpp
Normal file
49
src/yycc/carton/clap/manual.hpp
Normal file
@ -0,0 +1,49 @@
|
||||
#pragma once
|
||||
#include "application.hpp"
|
||||
#include "../../macro/class_copy_move.hpp"
|
||||
#include "../tabulate.hpp"
|
||||
#include <iostream>
|
||||
|
||||
#define NS_YYCC_CLAP ::yycc::carton::clap
|
||||
#define NS_YYCC_TABULATE ::yycc::carton::tabulate
|
||||
|
||||
namespace yycc::carton::clap::manual::Manual {
|
||||
|
||||
struct ManualTr {
|
||||
public:
|
||||
ManualTr();
|
||||
~ManualTr();
|
||||
YYCC_DEFAULT_COPY_MOVE(ManualTr);
|
||||
|
||||
public:
|
||||
std::u8string author_and_version;
|
||||
std::u8string usage_title, usage_body;
|
||||
std::u8string avail_opt, avail_var;
|
||||
};
|
||||
|
||||
class Manual {
|
||||
public:
|
||||
Manual(const NS_YYCC_CLAP::application::Application& app, ManualTr&& trctx = ManualTr());
|
||||
~Manual();
|
||||
YYCC_DEFAULT_COPY_MOVE(Manual);
|
||||
|
||||
private:
|
||||
void setup_table();
|
||||
void fill_opt_table();
|
||||
void fill_var_table();
|
||||
|
||||
public:
|
||||
void print_version(std::ostream& dst = std::cout) const;
|
||||
void print_help(std::ostream& dst = std::cout) const;
|
||||
|
||||
private:
|
||||
ManualTr trctx;
|
||||
const NS_YYCC_CLAP::application::Application app;
|
||||
NS_YYCC_TABULATE::Tabulate opt_printer;
|
||||
NS_YYCC_TABULATE::Tabulate var_printer;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#undef NS_YYCC_TABULATE
|
||||
#undef NS_YYCC_CLAP
|
||||
@ -1,6 +1,6 @@
|
||||
#include "option.hpp"
|
||||
#include "../../string/op.hpp"
|
||||
#include "../../string/format.hpp"
|
||||
#include "../../patch/format.hpp"
|
||||
#include <stdexcept>
|
||||
#include <format>
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "variable.hpp"
|
||||
#include "../../string/format.hpp"
|
||||
#include "../../patch/format.hpp"
|
||||
#include <stdexcept>
|
||||
#include <format>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user