fix: fix todos waiting termcolor.

This commit is contained in:
2025-08-19 13:58:05 +08:00
parent 8a72e6a655
commit a76f10722d
2 changed files with 15 additions and 11 deletions

View File

@ -1,21 +1,23 @@
#include "panic.hpp" #include "panic.hpp"
#include "../carton/termcolor.hpp"
#include "../string/reinterpret.hpp"
#include <cstdlib> #include <cstdlib>
#include <iomanip> #include <iomanip>
#include <iostream> #include <iostream>
#include <stacktrace> #include <stacktrace>
#define TERMCOLOR ::yycc::carton::termcolor
#define REINTERPRET ::yycc::string::reinterpret
namespace yycc::rust::panic { namespace yycc::rust::panic {
void panic(const char* file, int line, const std::string_view& msg) { void panic(const char* file, int line, const std::string_view& msg) {
// Output message in stderr. // Output message in stderr.
auto& dst = std::cerr; auto& dst = std::cerr;
// TODO: Fix colorful output when finishing `termcolor` lib.
// Print error message if we support it. // Print error message if we support it.
// // Setup color // Setup color
// dst << FOREGROUND<Color::Red>; dst << REINTERPRET::as_ordinary_view(TERMCOLOR::foreground(TERMCOLOR::Color::Red));
// File name and line number message // File name and line number message
dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl; dst << "program paniked at " << std::quoted(file) << ":Ln" << line << std::endl;
// User custom message // User custom message
@ -23,8 +25,8 @@ namespace yycc::rust::panic {
// Stacktrace message if we support it. // Stacktrace message if we support it.
dst << "stacktrace: " << std::endl; dst << "stacktrace: " << std::endl;
dst << std::stacktrace::current() << std::endl; dst << std::stacktrace::current() << std::endl;
// // Restore color // Restore color
// dst << RESET; dst << REINTERPRET::as_ordinary_view(TERMCOLOR::reset());;
// Make sure all messages are flushed into screen. // Make sure all messages are flushed into screen.
dst.flush(); dst.flush();

View File

@ -1,8 +1,10 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <yycc.hpp> #include <yycc.hpp>
#include <yycc/carton/wcwidth.hpp> #include <yycc/carton/wcwidth.hpp>
#include <yycc/carton/termcolor.hpp>
#define WCWDITH ::yycc::carton::wcwidth #define WCWDITH ::yycc::carton::wcwidth
#define TERMCOLOR ::yycc::carton::termcolor
namespace yycctest::carton::wcwidth { namespace yycctest::carton::wcwidth {
@ -43,10 +45,10 @@ namespace yycctest::carton::wcwidth {
} }
TEST(CartonWcwdith, Termcolor) { TEST(CartonWcwdith, Termcolor) {
// TODO: Fix this after finish "termcolor". using Color = TERMCOLOR::Color;
// assert_eq!(wcswidth(&colored("abc", Color::Red, Default::default(), Default::default())), 3); TEST_SUCCESS(TERMCOLOR::colored(u8"abc", Color::Red), 3);
// assert_eq!(wcswidth(&colored("中文", Color::Red, Default::default(), Default::default())), 4); TEST_SUCCESS(TERMCOLOR::colored(u8"中文", Color::Red), 4);
// assert_eq!(wcswidth(&colored("ありがとう", Color::Red, Default::default(), Default::default())), 10); TEST_SUCCESS(TERMCOLOR::colored(u8"ありがとう", Color::Red), 10);
} }
} // namespace yycctest::carton::wcwidth } // namespace yycctest::carton::wcwidth