Skip to content
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions src/include/color.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef SANAE_COLOR_HPP
#define SANAE_COLOR_HPP
Comment thread
SanaeProject marked this conversation as resolved.

#include <cstdint>
#include <string>
#include <sstream>

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.
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){
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.
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
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
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.

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.
static constexpr const char* BLACK = "\033[40m";
static constexpr const char* RED = "\033[41m";
static constexpr const char* GREEN = "\033[42m";
static constexpr const char* YELLOW = "\033[43m";
static constexpr const char* BLUE = "\033[44m";
static constexpr const char* PURPLE = "\033[45m";
static constexpr const char* CYAN = "\033[46m";
static constexpr const char* WHITE = "\033[47m";

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();
Comment on lines +40 to +44
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.
}
};

#endif // SANAE_COLOR_HPP
Loading