Skip to content

Commit 5b3cd1c

Browse files
committed
Name colors
It's more descriptive, use #define's so we can use compile-time concatenations. Signed-off-by: Eric Curtin <[email protected]>
1 parent 3d804de commit 5b3cd1c

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

common/log.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ void common_log_set_verbosity_thold(int verbosity) {
1414
common_log_verbosity_thold = verbosity;
1515
}
1616

17-
#define LOG_COL_DEFAULT "\033[0m"
18-
#define LOG_COL_BOLD "\033[1m"
19-
#define LOG_COL_RED "\033[31m"
20-
#define LOG_COL_GREEN "\033[32m"
21-
#define LOG_COL_YELLOW "\033[33m"
22-
#define LOG_COL_BLUE "\033[34m"
23-
#define LOG_COL_MAGENTA "\033[35m"
24-
#define LOG_COL_CYAN "\033[36m"
25-
#define LOG_COL_WHITE "\033[37m"
26-
2717
static int64_t t_us() {
2818
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
2919
}

common/log.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
#include "ggml.h" // for ggml_log_level
44

5+
#define LOG_COL_DEFAULT "\033[0m"
6+
#define LOG_COL_BOLD "\033[1m"
7+
#define LOG_COL_RED "\033[31m"
8+
#define LOG_COL_GREEN "\033[32m"
9+
#define LOG_COL_YELLOW "\033[33m"
10+
#define LOG_COL_BLUE "\033[34m"
11+
#define LOG_COL_MAGENTA "\033[35m"
12+
#define LOG_COL_CYAN "\033[36m"
13+
#define LOG_COL_WHITE "\033[37m"
14+
515
#ifndef __GNUC__
616
# define LOG_ATTRIBUTE_FORMAT(...)
717
#elif defined(__MINGW32__)

examples/run/run.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@
2424
#include <string>
2525
#include <vector>
2626

27+
#include "chat-template.hpp"
2728
#include "common.h"
2829
#include "json.hpp"
2930
#include "linenoise.cpp/linenoise.h"
3031
#include "llama-cpp.h"
31-
#include "chat-template.hpp"
32+
#include "log.h"
3233

3334
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(_WIN32)
3435
[[noreturn]] static void sigint_handler(int) {
35-
printf("\n\033[0m");
36+
printf("\n" LOG_COL_DEFAULT);
3637
exit(0); // not ideal, but it's the only way to guarantee exit in all cases
3738
}
3839
#endif
@@ -847,7 +848,7 @@ static int check_context_size(const llama_context_ptr & ctx, const llama_batch &
847848
const int n_ctx = llama_n_ctx(ctx.get());
848849
const int n_ctx_used = llama_get_kv_cache_used_cells(ctx.get());
849850
if (n_ctx_used + batch.n_tokens > n_ctx) {
850-
printf("\033[0m\n");
851+
printf(LOG_COL_DEFAULT "\n");
851852
printe("context size exceeded\n");
852853
return 1;
853854
}
@@ -910,7 +911,7 @@ static int generate(LlamaData & llama_data, const std::string & prompt, std::str
910911
batch = llama_batch_get_one(&new_token_id, 1);
911912
}
912913

913-
printf("\033[0m");
914+
printf(LOG_COL_DEFAULT);
914915
return 0;
915916
}
916917

@@ -919,7 +920,7 @@ static int read_user_input(std::string & user_input) {
919920
#ifdef WIN32
920921
printf(
921922
"\r%*s"
922-
"\r\033[0m%s",
923+
"\r" LOG_COL_DEFAULT "%s",
923924
get_terminal_width(), " ", prompt_prefix);
924925

925926
std::getline(std::cin, user_input);
@@ -956,7 +957,7 @@ static int generate_response(LlamaData & llama_data, const std::string & prompt,
956957
const bool stdout_a_terminal) {
957958
// Set response color
958959
if (stdout_a_terminal) {
959-
printf("\033[33m");
960+
printf(LOG_COL_YELLOW);
960961
}
961962

962963
if (generate(llama_data, prompt, response)) {
@@ -965,7 +966,7 @@ static int generate_response(LlamaData & llama_data, const std::string & prompt,
965966
}
966967

967968
// End response with color reset and newline
968-
printf("\n%s", stdout_a_terminal ? "\033[0m" : "");
969+
printf("\n%s", stdout_a_terminal ? LOG_COL_DEFAULT : "");
969970
return 0;
970971
}
971972

0 commit comments

Comments
 (0)