Skip to content

Commit 404fac0

Browse files
authored
Fix color getting reset before prompt output done (#65)
(cherry picked from commit 7eb2987)
1 parent 1a0a743 commit 404fac0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

main.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ int main(int argc, char ** argv) {
869869
is_interacting = true;
870870
}
871871

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

892893
if (embd_inp.size() <= input_consumed) {
893-
// out of input, sample next token
894+
// out of user input, sample next token
894895
const float top_k = params.top_k;
895896
const float top_p = params.top_p;
896897
const float temp = params.temp;
@@ -920,7 +921,7 @@ int main(int argc, char ** argv) {
920921
// decrement remaining sampling budget
921922
--remaining_tokens;
922923
} else {
923-
// if here, it means we are still processing the input prompt
924+
// some user input remains from prompt or interaction, forward it to processing
924925
while (embd_inp.size() > input_consumed) {
925926
embd.push_back(embd_inp[input_consumed]);
926927
last_n_tokens.erase(last_n_tokens.begin());
@@ -930,17 +931,17 @@ int main(int argc, char ** argv) {
930931
break;
931932
}
932933
}
933-
934-
if (params.use_color && embd_inp.size() <= input_consumed) {
935-
printf(ANSI_COLOR_RESET);
936-
}
937934
}
938935

939936
// display text
940937
if (!input_noecho) {
941938
for (auto id : embd) {
942939
printf("%s", vocab.id_to_token[id].c_str());
943940
}
941+
// reset color to default if we there is no pending user input
942+
if (params.use_color && embd_inp.size() <= input_consumed) {
943+
printf(ANSI_COLOR_RESET);
944+
}
944945
fflush(stdout);
945946
}
946947

0 commit comments

Comments
 (0)