Skip to content

Commit

Permalink
Fix colors enabling on WIN32
Browse files Browse the repository at this point in the history
  • Loading branch information
ggerganov committed Mar 25, 2023
1 parent 79b2b26 commit c2b25b6
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions examples/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ static bool con_use_color = false;

void enable_console_colors() {
#if defined (_WIN32)
if (params.use_color) {
// Enable ANSI colors on Windows 10+
unsigned long dwMode = 0;
void* hConOut = GetStdHandle((unsigned long)-11); // STD_OUTPUT_HANDLE (-11)
if (hConOut && hConOut != (void*)-1 && GetConsoleMode(hConOut, &dwMode) && !(dwMode & 0x4)) {
SetConsoleMode(hConOut, dwMode | 0x4); // ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
}
// Enable ANSI colors on Windows 10+
unsigned long dwMode = 0;
void* hConOut = GetStdHandle((unsigned long)-11); // STD_OUTPUT_HANDLE (-11)
if (hConOut && hConOut != (void*)-1 && GetConsoleMode(hConOut, &dwMode) && !(dwMode & 0x4)) {
SetConsoleMode(hConOut, dwMode | 0x4); // ENABLE_VIRTUAL_TERMINAL_PROCESSING (0x4)
}
#endif
}
Expand Down Expand Up @@ -287,7 +285,9 @@ int main(int argc, char ** argv) {
int n_consumed = 0;

// the first thing we will do is to output the prompt, so set color accordingly
enable_console_colors();
if (params.use_color) {
enable_console_colors();
}
set_console_state(CONSOLE_STATE_PROMPT);

std::vector<llama_token> embd;
Expand Down

1 comment on commit c2b25b6

@anzz1
Copy link
Contributor

@anzz1 anzz1 commented on c2b25b6 Mar 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is fixed also on #420

Please sign in to comment.