add: 添加恢复终端颜色调用

This commit is contained in:
taynpg 2025-03-01 03:48:05 +08:00
parent f08e3e05c8
commit 389837feb3
2 changed files with 34 additions and 0 deletions

View File

@ -106,6 +106,8 @@ short get_cursor_y();
char* fc_readline();
void color_print(const char* text, const COLOR_TYPE color);
void add_newer(const std::vector<char>& wch);
void fc_enable_cur();
void recovery_terminal_color();
static std::vector<std::string> cur_work_content;
static std::vector<char> deadline_vch;
@ -147,6 +149,11 @@ void fc_turn_off()
need_turn = false;
}
void fc_recovery_color()
{
recovery_terminal_color();
}
std::string get_home()
{
#if defined(_WIN32)
@ -179,6 +186,26 @@ std::string get_home()
#endif
}
void recovery_terminal_color()
{
#if defined(OS_WINDOWS)
HANDLE h_console = GetStdHandle(STD_OUTPUT_HANDLE);
if (h_console == NULL) {
fprintf(stderr, "[ERROR] Couldn't handle terminal\n");
exit(1);
}
if (SetConsoleTextAttribute(h_console, DEFAULT_MAIN_COLOR) == 0) {
fprintf(stderr, "[ERROR] Couldn't set terminal color\n");
exit(1);
}
#else
fc_lock_print();
printf("\033[0m");
fc_enable_cur();
fc_unlock_print();
#endif
}
void append_his(const std::string& his)
{
history.push_back(his);
@ -676,6 +703,8 @@ char* fc_readline()
printf("\033[0m");
fc_enable_cur();
fc_unlock_print();
#else
recovery_terminal_color();
#endif
return nullptr;
}

View File

@ -78,6 +78,11 @@ void fc_turn_on();
*/
void fc_turn_off();
/**
* @brief
*/
void fc_recovery_color();
#ifdef __cplusplus
}
#endif