summaryrefslogtreecommitdiff
path: root/examples/common.h
diff options
context:
space:
mode:
authoranzz1 <anzz1@live.com>2023-03-28 17:09:55 +0300
committerGitHub <noreply@github.com>2023-03-28 17:09:55 +0300
commit7b8dbcb78b2f65c4676e41da215800d65846edd0 (patch)
treeab17f652bb706aac95699ee323c6aaa36a1f4706 /examples/common.h
parent4b8efff0e3945090379aa2f897ff125c8f9cdbae (diff)
main.cpp fixes, refactoring (#571)
- main: entering empty line passes back control without new input in interactive/instruct modes - instruct mode: keep prompt fix - instruct mode: duplicate instruct prompt fix - refactor: move common console code from main->common
Diffstat (limited to 'examples/common.h')
-rw-r--r--examples/common.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/common.h b/examples/common.h
index 8caefd85..1505aa92 100644
--- a/examples/common.h
+++ b/examples/common.h
@@ -63,3 +63,33 @@ std::string gpt_random_prompt(std::mt19937 & rng);
//
std::vector<llama_token> llama_tokenize(struct llama_context * ctx, const std::string & text, bool add_bos);
+
+//
+// Console utils
+//
+
+#define ANSI_COLOR_RED "\x1b[31m"
+#define ANSI_COLOR_GREEN "\x1b[32m"
+#define ANSI_COLOR_YELLOW "\x1b[33m"
+#define ANSI_COLOR_BLUE "\x1b[34m"
+#define ANSI_COLOR_MAGENTA "\x1b[35m"
+#define ANSI_COLOR_CYAN "\x1b[36m"
+#define ANSI_COLOR_RESET "\x1b[0m"
+#define ANSI_BOLD "\x1b[1m"
+
+enum console_color_t {
+ CONSOLE_COLOR_DEFAULT=0,
+ CONSOLE_COLOR_PROMPT,
+ CONSOLE_COLOR_USER_INPUT
+};
+
+struct console_state {
+ bool use_color = false;
+ console_color_t color = CONSOLE_COLOR_DEFAULT;
+};
+
+void set_console_color(console_state & con_st, console_color_t color);
+
+#if defined (_WIN32)
+void win32_console_init(bool enable_color);
+#endif