Skip to content

Commit

Permalink
Fix color getting reset before prompt output done (cocktailpeanut#65)
Browse files Browse the repository at this point in the history
(cherry picked from commit 7eb2987619feee04c40eff69b604017d09919cb6)
  • Loading branch information
blackhole89 committed Mar 12, 2023
1 parent 1a0a743 commit 404fac0
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,7 @@ int main(int argc, char ** argv) {
is_interacting = true;
}

// set the color for the prompt which will be output initially
if (params.use_color) {
printf(ANSI_COLOR_YELLOW);
}
Expand All @@ -890,7 +891,7 @@ int main(int argc, char ** argv) {
embd.clear();

if (embd_inp.size() <= input_consumed) {
// out of input, sample next token
// out of user input, sample next token
const float top_k = params.top_k;
const float top_p = params.top_p;
const float temp = params.temp;
Expand Down Expand Up @@ -920,7 +921,7 @@ int main(int argc, char ** argv) {
// decrement remaining sampling budget
--remaining_tokens;
} else {
// if here, it means we are still processing the input prompt
// some user input remains from prompt or interaction, forward it to processing
while (embd_inp.size() > input_consumed) {
embd.push_back(embd_inp[input_consumed]);
last_n_tokens.erase(last_n_tokens.begin());
Expand All @@ -930,17 +931,17 @@ int main(int argc, char ** argv) {
break;
}
}

if (params.use_color && embd_inp.size() <= input_consumed) {
printf(ANSI_COLOR_RESET);
}
}

// display text
if (!input_noecho) {
for (auto id : embd) {
printf("%s", vocab.id_to_token[id].c_str());
}
// reset color to default if we there is no pending user input
if (params.use_color && embd_inp.size() <= input_consumed) {
printf(ANSI_COLOR_RESET);
}
fflush(stdout);
}

Expand Down

0 comments on commit 404fac0

Please sign in to comment.