GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
cmdio_util.h
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#ifndef DESIGNLAB_CMDIO_UTIL_H_
9#define DESIGNLAB_CMDIO_UTIL_H_
10
11#include <format>
12#include <string>
13#include <utility>
14
15#include "boot_mode.h"
16#include "output_detail.h"
17
18// ----------------------------------------------------------------
19//
20// 色付きで出力をしたくない場合,あるいはうまく動作しない場合は,
21// 以下のマクロをコメントアウトすること.
22//
23// ----------------------------------------------------------------
24
25#define DESIGNLAB_USE_COLOR_OUTPUT
26
28
37
41void DoOutput(bool do_output);
42
47void Output(const std::string& str, OutputDetail detail);
48
51inline void DebugOutput(const std::string& str) {
53}
54
57inline void InfoOutput(const std::string& str) {
59}
60
63inline void WarningOutput(const std::string& str) {
65}
66
69inline void ErrorOutput(const std::string& str) {
71}
72
75inline void SystemOutput(const std::string& str) {
77}
78
83void SpacedOutput(const std::string& str, OutputDetail detail);
84
90template <typename... Args>
91void OutputF(OutputDetail detail, const std::format_string<Args...> str,
92 Args&&... args) {
93 const std::string formatted_str =
94 std::format(str, std::forward<Args>(args)...);
95 Output(formatted_str, detail);
96}
97
101template <typename... Args>
102inline void DebugOutputF(const std::format_string<Args...> str,
103 Args&&... args) {
104 OutputF(OutputDetail::kDebug, str, std::forward<Args>(args)...);
105}
106
110template <typename... Args>
111inline void InfoOutputF(const std::format_string<Args...> str, Args&&... args) {
112 OutputF(OutputDetail::kInfo, str, std::forward<Args>(args)...);
113}
114
118template <typename... Args>
119inline void WarningOutputF(const std::format_string<Args...> str,
120 Args&&... args) {
121 OutputF(OutputDetail::kWarning, str, std::forward<Args>(args)...);
122}
123
127template <typename... Args>
128inline void ErrorOutputF(const std::format_string<Args...> str,
129 Args&&... args) {
130 OutputF(OutputDetail::kError, str, std::forward<Args>(args)...);
131}
132
136template <typename... Args>
137inline void SystemOutputF(const std::format_string<Args...> str,
138 Args&&... args) {
139 OutputF(OutputDetail::kSystem, str, std::forward<Args>(args)...);
140}
141
147template <typename... Args>
148void SpacedOutputF(OutputDetail detail, const std::format_string<Args...> str,
149 Args&&... args) {
150 const std::string formatted_str =
151 std::format(str, std::forward<Args>(args)...);
152 SpacedOutput(formatted_str, detail);
153}
154
159void OutputCenter(const std::string& str, OutputDetail detail);
160
165void OutputRight(const std::string& str, OutputDetail detail);
166
170void OutputNewLine(int num, OutputDetail detail);
171
176void OutputHorizontalLine(const std::string& line_visual, OutputDetail detail);
177
183void OutputTitle(const std::string& title_name, bool output_copy_right = false);
184
188void WaitAnyKey(const std::string& str = "Waiting for input.");
189
197int InputInt(int min, int max, int default_num,
198 const std::string& str = "Please enter an integer.");
199
205bool InputYesNo(const std::string& str = "Are you sure?");
206
214std::string InputDirName(
215 const std::string& str =
216 "Enter a directory name. (Japanese is not recommended).");
217
218constexpr int kHorizontalLineLength = 100;
219
220} // namespace designlab::cmdio
221
222#endif // DESIGNLAB_CMDIO_UTIL_H_
void OutputF(OutputDetail detail, const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数, format した文字列を出力する. SetOutputLimit() で設定した出力の許可範囲内であれば出力される.
Definition cmdio_util.h:91
void ErrorOutput(const std::string &str)
コマンドラインに文字を出力する関数. Error 用の出力.
Definition cmdio_util.h:69
std::string InputDirName(const std::string &str="Enter a directory name. (Japanese is not recommended).")
ディレクトリ名を入力させる関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される. ディレクトリ名には次の文字は使えない....
void WarningOutputF(const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数. Warning 用の出力. format した文字列を出力する.
Definition cmdio_util.h:119
void SpacedOutput(const std::string &str, OutputDetail detail)
コマンドラインに文字を出力する関数. 前と後ろに改行を挿入する.
void DebugOutput(const std::string &str)
コマンドラインに文字を出力する関数. Debug 用の出力.
Definition cmdio_util.h:51
void OutputHorizontalLine(const std::string &line_visual, OutputDetail detail)
コマンドラインに水平線を出力する関数.
void OutputCenter(const std::string &str, OutputDetail detail)
中央に文字を出力する関数. 文字列が長すぎる場合は普通に左詰めで出力される.
void SystemOutputF(const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数. System 用の出力. format した文字列を出力する.
Definition cmdio_util.h:137
void WarningOutput(const std::string &str)
コマンドラインに文字を出力する関数. Warning 用の出力.
Definition cmdio_util.h:63
void InfoOutputF(const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数. Info 用の出力. format した文字列を出力する.
Definition cmdio_util.h:111
void WaitAnyKey(const std::string &str="Waiting for input.")
入力待ちをする関数. 出力される文字列は, 必ず OutputDetail::kSystem で出力される.
void DebugOutputF(const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数. Debug 用の出力. format した文字列を出力する.
Definition cmdio_util.h:102
void SystemOutput(const std::string &str)
コマンドラインに文字を出力する関数. System 用の出力.
Definition cmdio_util.h:75
void ErrorOutputF(const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数. Error 用の出力. format した文字列を出力する.
Definition cmdio_util.h:128
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 InfoOutput(const std::string &str)
コマンドラインに文字を出力する関数. Info 用の出力.
Definition cmdio_util.h:57
void OutputNewLine(int num, OutputDetail detail)
コマンドラインで改行をする関数.
void OutputTitle(const std::string &title_name, bool output_copy_right=false)
コマンドラインにこのソフトのタイトルを出力する関数. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
void SpacedOutputF(OutputDetail detail, const std::format_string< Args... > str, Args &&... args)
コマンドラインに文字を出力する関数, format した文字列を出力する. SetOutputLimit 関数で設定した出力の許可範囲内であれば出力される.
Definition cmdio_util.h:148
void DoOutput(bool do_output)
そもそも出力をするかを設定する関数. false に設定しても システムメッセージは出力される.
void Output(const std::string &str, OutputDetail detail)
コマンドラインに文字を出力する関数. SetOutputLimit 関数で設定した出力の許可範囲内であれば出力される.
constexpr int kHorizontalLineLength
水平線の長さ.
Definition cmdio_util.h:218
void SetOutputLimit(OutputDetail limit)
出力するメッセージをどこまで許可するかを設定する関数. この関数を呼び出してから出ないと,他の関数を使えない. 例えば kError に設定すると, kError 未満の出力( kInfo とか...
bool InputYesNo(const std::string &str="Are you sure?")
yesかnoを入力させる関数.返り値で yes なら true, no なら false を返す. 出力される文字列は,必ず OutputDetail::kSystem で出力される.
OutputDetail
コマンドラインに文字を出力する際に,その詳細を指定するための列挙体.
@ kInfo
優先度低めの情報.
@ kSystem
システムメッセージ,常に出力する.
@ kDebug
デバッグ時のみ出力,一番優先度が低い.
@ kError
エラーメッセージ.
@ kWarning
警告メッセージ,エラーではないが注意が必要なメッセージ.
bool do_output