-
Notifications
You must be signed in to change notification settings - Fork 0
カラークラスを追加し、フォントおよび背景色の設定機能を実装 #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,48 @@ | ||||||
| #ifndef SANAE_COLOR_HPP | ||||||
| #define SANAE_COLOR_HPP | ||||||
|
|
||||||
| #include <cstdint> | ||||||
| #include <string> | ||||||
| #include <sstream> | ||||||
|
|
||||||
| class FontColor { | ||||||
| public: | ||||||
| static constexpr const char* CLEAR = "\033[0m"; | ||||||
|
||||||
| static constexpr const char* BLACK = "\033[30m"; | ||||||
| static constexpr const char* RED = "\033[31m"; | ||||||
| static constexpr const char* GREEN = "\033[32m"; | ||||||
| static constexpr const char* YELLOW = "\033[33m"; | ||||||
| static constexpr const char* BLUE = "\033[34m"; | ||||||
| static constexpr const char* PURPLE = "\033[35m"; | ||||||
| static constexpr const char* CYAN = "\033[36m"; | ||||||
| static constexpr const char* WHITE = "\033[37m"; | ||||||
|
|
||||||
| static std::string RGB(uint8_t R, uint8_t G, uint8_t B){ | ||||||
|
||||||
| std::stringstream buf; | ||||||
| buf << "\033[38;2;" << std::to_string(R) << ";" << std::to_string(G) << ";" << std::to_string(B) << "m"; | ||||||
|
|
||||||
| return buf.str(); | ||||||
|
Comment on lines
+20
to
+24
|
||||||
| } | ||||||
| }; | ||||||
|
Comment on lines
+8
to
+26
|
||||||
|
|
||||||
| class BgColor { | ||||||
| public: | ||||||
| static constexpr const char* CLEAR = "\033[0m"; | ||||||
|
||||||
| static constexpr const char* CLEAR = "\033[0m"; | |
| static constexpr const char* CLEAR = "\033[49m"; |
Copilot
AI
Apr 2, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RGB() builds the escape sequence via std::stringstream and std::to_string, which incurs multiple temporary std::string allocations. Since you only write to the stream, prefer std::ostringstream and stream the numeric values directly (cast uint8_t to int) to reduce overhead, especially if this is used in hot paths.
Uh oh!
There was an error while loading. Please reload this page.