Skip to content

カラークラスを追加し、フォントおよび背景色の設定機能を実装#38

Draft
SanaeProject wants to merge 2 commits intomainfrom
feature/CNN
Draft

カラークラスを追加し、フォントおよび背景色の設定機能を実装#38
SanaeProject wants to merge 2 commits intomainfrom
feature/CNN

Conversation

@SanaeProject
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings April 2, 2026 02:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

端末出力向けに ANSI エスケープシーケンスをまとめたカラー用ヘッダを追加し、フォント色・背景色の設定(固定色+RGB指定)を利用できるようにする PR です。

Changes:

  • FontColor / BgColor を追加し、基本色と RGB 指定のエスケープ文字列を生成
  • フォント色用(38;2)と背景色用(48;2)の RGB コード生成を実装

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


class FontColor {
public:
static constexpr const char* CLEAR = "\033[0m";
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FontColor::CLEAR is set to "\033[0m", which resets all attributes (foreground, background, styles). If the intent is to clear only the font (foreground) color, use the ANSI default-foreground reset code ("\033[39m") or rename this constant to something like RESET_ALL to match its behavior.

Copilot uses AI. Check for mistakes.

class BgColor {
public:
static constexpr const char* CLEAR = "\033[0m";
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BgColor::CLEAR is set to "\033[0m", which resets all attributes (foreground, background, styles). If the intent is to clear only the background color, use the ANSI default-background reset code ("\033[49m") or rename this constant to something like RESET_ALL to match its behavior.

Suggested change
static constexpr const char* CLEAR = "\033[0m";
static constexpr const char* CLEAR = "\033[49m";

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +24
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();
Copy link

Copilot AI Apr 2, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +44
static std::string RGB(uint8_t R, uint8_t G, uint8_t B){
std::stringstream buf;
buf << "\033[48;2;" << std::to_string(R) << ";" << std::to_string(G) << ";" << std::to_string(B) << "m";

return buf.str();
Copy link

Copilot AI Apr 2, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +26
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();
}
};
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FontColor and BgColor duplicate the same RGB formatting logic and the same CLEAR value. Consider extracting shared pieces (e.g., a small internal helper to format "\033[...;2;R;G;Bm") so changes (like fixing CLEAR semantics) don’t need to be applied in multiple places.

Copilot uses AI. Check for mistakes.
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){
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter names in RGB() are uppercase (R/G/B), which is inconsistent with the lower-case parameter naming used elsewhere in this codebase (e.g., forward(const Matrix& in), backward(const Matrix& dout)). Consider renaming parameters to r/g/b for consistency.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants