12#include <magic_enum.hpp>
34 std::cin.tie(&std::cout);
35 std::ios_base::sync_with_stdio(
true);
58 std::cout << std::endl;
63 const std::string tag =
68#if defined(DESIGNLAB_USE_COLOR_OUTPUT)
71 std::cout <<
"\x1b[31m";
74 std::cout <<
"\x1b[33m";
77 std::cout <<
"\x1b[36m";
80 std::cout <<
"\x1b[32m";
88 const std::string space(tag.size(),
' ');
93 for (
size_t i = 0; i < line.size(); i++) {
102 std::cout << line[i] << std::endl;
105#if defined(DESIGNLAB_USE_COLOR_OUTPUT)
106 std::cout <<
"\x1b[0m";
119 std::stringstream ss(str);
122 while (std::getline(ss, line)) {
126 const int space_num =
129 for (
int i = 0; i < space_num; ++i) {
133 Output(space + line, detail);
142 std::stringstream ss(str);
145 while (std::getline(ss, line)) {
149 const int space_num =
152 for (
int i = 0; i < space_num; ++i) {
156 Output(space + line, detail);
168 for (
int i = 0; i < num; i++) {
175 if (line_visual.size() != 1) {
197 if (output_copy_right) {
198 OutputRight(
"(C) 2023 Design Engineering Laboratory ", detail);
214 const std::string& str) {
219 std::string input_str;
220 std::cout <<
">>" << std::flush;
221 std::cin >> input_str;
223 int res = default_num;
226 res = std::stoi(input_str);
228 if (res < min || res > max) {
230 "The entered value '{}' is out of range. Use the default "
232 input_str, default_num);
239 "The entered value '{}' cannot be evaluated. Use the default "
241 input_str, default_num);
253 std::string input_str;
254 std::cout <<
">>" << std::flush;
255 std::cin >> input_str;
257 if (input_str ==
"y" || input_str ==
"yes" || input_str ==
"Y" ||
258 input_str ==
"Yes" || input_str ==
"YES") {
260 }
else if (input_str ==
"n" || input_str ==
"no" || input_str ==
"N" ||
261 input_str ==
"No" || input_str ==
"NO") {
266 "The entered value '{}' cannot be evaluated. Enter 'y' or 'n'.",
274 const std::vector<std::string> invalid_chars = {
"\\",
"/",
":",
"*",
"?",
275 "\"",
"<",
">",
"|"};
276 constexpr int kMaxDirNameLength = 255;
279 std::string input_str;
280 std::cout <<
">>" << std::flush;
281 std::cin >> input_str;
283 bool is_invalid =
true;
285 for (
const auto& invalid_char : invalid_chars) {
286 if (input_str.find(invalid_char) != std::string::npos) {
288 "Directory names cannot contain the following characters : \\ / : "
295 if (input_str.find(
" ") != std::string::npos) {
300 if (input_str.length() > kMaxDirNameLength) {
302 "The entered value '{}' is too long. Enter a value of {} "
303 "characters or less.",
304 input_str, kMaxDirNameLength);
308 if (input_str.length() == 0) {
void OutputF(OutputDetail detail, const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数, format した文字列を出力する. SetOutputLimit() で設定した出力の許可範囲内であれば出力される.
std::string InputDirName(const std::string &str="Enter a directory name. (Japanese is not recommended).")
ディレクトリ名を入力させる関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される. ディレクトリ名には次の文字は使えない....
void SpacedOutput(const std::string &str, OutputDetail detail)
コマンドラインに文字を出力する関数. 前と後ろに改行を挿入する.
void OutputHorizontalLine(const std::string &line_visual, OutputDetail detail)
コマンドラインに水平線を出力する関数.
void OutputCenter(const std::string &str, OutputDetail detail)
中央に文字を出力する関数. 文字列が長すぎる場合は普通に左詰めで出力される.
void WaitAnyKey(const std::string &str="Waiting for input.")
入力待ちをする関数. 出力される文字列は, 必ず OutputDetail::kSystem で出力される.
void SystemOutput(const std::string &str)
コマンドラインに文字を出力する関数. System 用の出力.
void OutputRight(const std::string &str, OutputDetail detail)
右端に文字を出力する関数. 文字列が長すぎる場合は普通に左詰めで出力される.
int InputInt(int min, int max, int default_num, const std::string &str="Please enter an integer.")
整数を入力させる関数. 出力される文字列は, 必ず OutputDetail::kSystem で出力される.
void OutputNewLine(int num, OutputDetail detail)
コマンドラインで改行をする関数.
void OutputTitle(const std::string &title_name, bool output_copy_right=false)
コマンドラインにこのソフトのタイトルを出力する関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
void DoOutput(bool do_output)
そもそも出力をするかを設定する関数. false に設定しても システムメッセージは出力される.
void Output(const std::string &str, OutputDetail detail)
コマンドラインに文字を出力する関数. SetOutputLimit 関数で設定した出力の許可範囲内であれば出力される.
constexpr int kHorizontalLineLength
水平線の長さ.
void SetOutputLimit(OutputDetail limit)
出力するメッセージをどこまで許可するかを設定する関数. この関数を呼び出してから出ないと,他の関数を使えない. 例えば kError に設定すると, kError 未満の出力( kInfo とか...
bool InputYesNo(const std::string &str="Are you sure?")
yesかnoを入力させる関数.返り値で yes なら true, no なら false を返す. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
std::vector< std::string > Split(const std::string &str, const std::string &separator)
文字列を分割する関数.指定した文字で文字列を分割する. 分割した結果,空白が含まれる場合や文字列がない場合は,そのまま返す. 最後が区切り文字で終わる場合は,...
std::string EnumToStringRemoveTopK(const T &enum_value)
enumを文字列に変換する関数. Google C++ coding style だと enumの要素は 先頭にkをつけてキャメルケースで書くことが推奨されている....
OutputDetail
コマンドラインに文字を出力する際に,その詳細を指定するための列挙体.
@ kSystem
システムメッセージ,常に出力する.
@ kDebug
デバッグ時のみ出力,一番優先度が低い.
@ kWarning
警告メッセージ,エラーではないが注意が必要なメッセージ.
OutputDetail output_limit