MCPcopy Create free account
hub / github.com/LiteLDev/LeviLamina / getMcCodeFromTextStyle

Function getMcCodeFromTextStyle

src/ll/api/utils/StringUtils_win.cpp:131–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129// clang-format on
130
131std::string getMcCodeFromTextStyle(fmt::text_style style) {
132 std::string res;
133 bool hasMcStyle = false;
134 if (style.has_emphasis()) {
135 hasMcStyle = true;
136 if ((uchar)(fmt::emphasis::blink) & (uchar)(style.get_emphasis())) {
137 res += cf::OBFUSCATED;
138 }
139 if ((uchar)(fmt::emphasis::bold) & (uchar)(style.get_emphasis())) {
140 res += cf::BOLD;
141 }
142 if ((uchar)(fmt::emphasis::italic) & (uchar)(style.get_emphasis())) {
143 res += cf::ITALIC;
144 }
145 }
146 if (style.has_foreground()) {
147 hasMcStyle = true;
148 auto fg = style.get_foreground();
149 if (!fg.is_terminal_color()) {
150 auto color = mce::Color(fg.value());
151 double minDis = std::numeric_limits<double>::max();
152 std::string_view minStr;
153 for (auto& [k, v] : formatColorPairs) {
154 auto dis = v.distanceTo(color);
155 if (dis < minDis) {
156 minDis = dis;
157 minStr = k;
158 }
159 }
160 res += minStr;
161 } else {
162 switch ((fmt::terminal_color)(fg.value())) {
163 // clang-format off
164 case fmt::terminal_color::black: res += cf::BLACK; break;
165 case fmt::terminal_color::red: res += cf::DARK_RED; break;
166 case fmt::terminal_color::green: res += cf::DARK_GREEN; break;
167 case fmt::terminal_color::yellow: res += cf::GOLD; break;
168 case fmt::terminal_color::blue: res += cf::DARK_BLUE; break;
169 case fmt::terminal_color::magenta: res += cf::DARK_PURPLE; break;
170 case fmt::terminal_color::cyan: res += cf::DARK_AQUA; break;
171 case fmt::terminal_color::white: res += cf::GRAY; break;
172 case fmt::terminal_color::bright_black: res += cf::DARK_GRAY; break;
173 case fmt::terminal_color::bright_red: res += cf::RED; break;
174 case fmt::terminal_color::bright_green: res += cf::GREEN; break;
175 case fmt::terminal_color::bright_yellow: res += cf::YELLOW; break;
176 case fmt::terminal_color::bright_blue: res += cf::BLUE; break;
177 case fmt::terminal_color::bright_magenta: res += cf::LIGHT_PURPLE; break;
178 case fmt::terminal_color::bright_cyan: res += cf::AQUA; break;
179 case fmt::terminal_color::bright_white:
180 default : res += cf::WHITE; break;
181 // clang-format on
182 }
183 }
184 }
185 if (style.has_background()) {
186 hasMcStyle = true;
187 }
188 if (!hasMcStyle) {

Callers 1

replaceAnsiToMcCodeFunction · 0.85

Calls 4

maxFunction · 0.85
valueMethod · 0.80
distanceToMethod · 0.80
ColorClass · 0.50

Tested by

no test coverage detected