* -> &
This commit is contained in:
parent
fcabe9b8b2
commit
ebf09a1919
3 changed files with 11 additions and 11 deletions
|
@ -267,8 +267,8 @@ std::vector<llama_token> llama_tokenize(struct llama_context * ctx, const std::s
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Keep track of current color of output, and emit ANSI code if it changes. */
|
/* 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) {
|
void set_console_color(console_state & con_st, console_color_t color) {
|
||||||
if (con_st->use_color && con_st->color != color) {
|
if (con_st.use_color && con_st.color != color) {
|
||||||
switch(color) {
|
switch(color) {
|
||||||
case CONSOLE_COLOR_DEFAULT:
|
case CONSOLE_COLOR_DEFAULT:
|
||||||
printf(ANSI_COLOR_RESET);
|
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);
|
printf(ANSI_BOLD ANSI_COLOR_GREEN);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
con_st->color = color;
|
con_st.color = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ struct console_state {
|
||||||
console_color_t color = CONSOLE_COLOR_DEFAULT;
|
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)
|
#if defined (_WIN32)
|
||||||
void win32_console_init(bool enable_color);
|
void win32_console_init(bool enable_color);
|
||||||
|
|
|
@ -24,7 +24,7 @@ static bool is_interacting = false;
|
||||||
|
|
||||||
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
|
#if defined (__unix__) || (defined (__APPLE__) && defined (__MACH__)) || defined (_WIN32)
|
||||||
void sigint_handler(int signo) {
|
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.
|
printf("\n"); // this also force flush stdout.
|
||||||
if (signo == SIGINT) {
|
if (signo == SIGINT) {
|
||||||
if (!is_interacting) {
|
if (!is_interacting) {
|
||||||
|
@ -235,7 +235,7 @@ int main(int argc, char ** argv) {
|
||||||
int n_consumed = 0;
|
int n_consumed = 0;
|
||||||
|
|
||||||
// the first thing we will do is to output the prompt, so set color accordingly
|
// 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<llama_token> embd;
|
std::vector<llama_token> embd;
|
||||||
|
|
||||||
|
@ -336,7 +336,7 @@ int main(int argc, char ** argv) {
|
||||||
}
|
}
|
||||||
// reset color to default if we there is no pending user input
|
// reset color to default if we there is no pending user input
|
||||||
if (!input_noecho && (int)embd_inp.size() == n_consumed) {
|
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;
|
// 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) {
|
if (last_output.find(antiprompt.c_str(), last_output.length() - antiprompt.length(), antiprompt.length()) != std::string::npos) {
|
||||||
is_interacting = true;
|
is_interacting = true;
|
||||||
is_antiprompt = true;
|
is_antiprompt = true;
|
||||||
set_console_color(&con_st, CONSOLE_COLOR_USER_INPUT);
|
set_console_color(con_st, CONSOLE_COLOR_USER_INPUT);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -365,7 +365,7 @@ int main(int argc, char ** argv) {
|
||||||
|
|
||||||
if (n_past > 0 && is_interacting) {
|
if (n_past > 0 && is_interacting) {
|
||||||
// potentially set color to indicate we are taking user input
|
// 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) {
|
if (params.instruct) {
|
||||||
printf("\n> ");
|
printf("\n> ");
|
||||||
|
@ -393,7 +393,7 @@ int main(int argc, char ** argv) {
|
||||||
} while (another_line);
|
} while (another_line);
|
||||||
|
|
||||||
// done taking input, reset color
|
// 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
|
// Add tokens to embd only if the input buffer is non-empty
|
||||||
// Entering a empty line lets the user pass control back
|
// 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_print_timings(ctx);
|
||||||
llama_free(ctx);
|
llama_free(ctx);
|
||||||
|
|
||||||
set_console_color(&con_st, CONSOLE_COLOR_DEFAULT);
|
set_console_color(con_st, CONSOLE_COLOR_DEFAULT);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue