diff --git a/filecomplete.cpp b/filecomplete.cpp index 517a435..0f07590 100644 --- a/filecomplete.cpp +++ b/filecomplete.cpp @@ -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& wch); +void fc_enable_cur(); +void recovery_terminal_color(); static std::vector cur_work_content; static std::vector 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; } diff --git a/filecomplete.h b/filecomplete.h index dfc9b6d..56d94dc 100644 --- a/filecomplete.h +++ b/filecomplete.h @@ -78,6 +78,11 @@ void fc_turn_on(); */ void fc_turn_off(); +/** + * @brief 恢复默认终端颜色 + */ +void fc_recovery_color(); + #ifdef __cplusplus } #endif