diff --git a/examples/common.cpp b/examples/common.cpp index a4e64143c..1dd1423a6 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -267,8 +267,8 @@ std::vector llama_tokenize(struct llama_context * ctx, const std::s } /* Keep track of current color of output, and emit ANSI code if it changes. */ -void set_console_color(console_state* con_st, console_color_t color) { - if (con_st->use_color && con_st->color != color) { +void set_console_color(console_state & con_st, console_color_t color) { + if (con_st.use_color && con_st.color != color) { switch(color) { case CONSOLE_COLOR_DEFAULT: printf(ANSI_COLOR_RESET); @@ -280,7 +280,7 @@ void set_console_color(console_state* con_st, console_color_t color) { printf(ANSI_BOLD ANSI_COLOR_GREEN); break; } - con_st->color = color; + con_st.color = color; } } diff --git a/examples/common.h b/examples/common.h index 9a4826dfe..1505aa927 100644 --- a/examples/common.h +++ b/examples/common.h @@ -88,7 +88,7 @@ struct console_state { console_color_t color = CONSOLE_COLOR_DEFAULT; }; -void set_console_color(console_state* con_st, console_color_t color); +void set_console_color(console_state & con_st, console_color_t color); #if defined (_WIN32) void win32_console_init(bool enable_color); diff --git a/examples/main/main.cpp b/examples/main/main.cpp index dcefc2af1..d5ab2cf75 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -24,7 +24,7 @@ static bool is_interacting = false; #if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32) void sigint_handler(int signo) { - set_console_color(&con_st, CONSOLE_COLOR_DEFAULT); + set_console_color(con_st, CONSOLE_COLOR_DEFAULT); printf("\n"); // this also force flush stdout. if (signo == SIGINT) { if (!is_interacting) { @@ -235,7 +235,7 @@ 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 - set_console_color(&con_st, CONSOLE_COLOR_PROMPT); + set_console_color(con_st, CONSOLE_COLOR_PROMPT); std::vector embd; @@ -336,7 +336,7 @@ int main(int argc, char ** argv) { } // reset color to default if we there is no pending user input if (!input_noecho && (int)embd_inp.size() == n_consumed) { - set_console_color(&con_st, CONSOLE_COLOR_DEFAULT); + set_console_color(con_st, CONSOLE_COLOR_DEFAULT); } // in interactive mode, and not currently processing queued inputs; @@ -356,7 +356,7 @@ int main(int argc, char ** argv) { if (last_output.find(antiprompt.c_str(), last_output.length() - antiprompt.length(), antiprompt.length()) != std::string::npos) { is_interacting = true; is_antiprompt = true; - set_console_color(&con_st, CONSOLE_COLOR_USER_INPUT); + set_console_color(con_st, CONSOLE_COLOR_USER_INPUT); fflush(stdout); break; } @@ -365,7 +365,7 @@ int main(int argc, char ** argv) { if (n_past > 0 && is_interacting) { // potentially set color to indicate we are taking user input - set_console_color(&con_st, CONSOLE_COLOR_USER_INPUT); + set_console_color(con_st, CONSOLE_COLOR_USER_INPUT); if (params.instruct) { printf("\n> "); @@ -393,7 +393,7 @@ int main(int argc, char ** argv) { } while (another_line); // done taking input, reset color - set_console_color(&con_st, CONSOLE_COLOR_DEFAULT); + set_console_color(con_st, CONSOLE_COLOR_DEFAULT); // Add tokens to embd only if the input buffer is non-empty // Entering a empty line lets the user pass control back @@ -448,7 +448,7 @@ int main(int argc, char ** argv) { llama_print_timings(ctx); llama_free(ctx); - set_console_color(&con_st, CONSOLE_COLOR_DEFAULT); + set_console_color(con_st, CONSOLE_COLOR_DEFAULT); return 0; }