timecat/utils/
info_utils.rs1use super::*;
2
3pub fn format_info<T: fmt::Display>(desc: &str, info: T, add_info_string: bool) -> String {
4 let mut desc = desc.trim().trim_end_matches(':').to_string();
5 if GLOBAL_TIMECAT_STATE.is_in_uci_mode() {
6 desc = desc.to_lowercase();
7 }
8 desc = desc.colorize(INFO_MESSAGE_STYLE);
9 if GLOBAL_TIMECAT_STATE.is_in_console_mode() {
10 format!("{desc}: {info}")
11 } else {
12 let mut formatted_info = format!("{desc} {info}",);
13 if add_info_string {
14 formatted_info = "info string ".colorize(INFO_MESSAGE_STYLE) + &formatted_info
15 }
16 formatted_info
17 }
18}
19
20#[inline]
21pub fn force_println_info<T: fmt::Display>(desc: &str, info: T) {
22 println_wasm!("{}", format_info(desc, info, true));
23}
24
25#[inline]
26pub fn println_info<T: fmt::Display>(desc: &str, info: T) {
27 if GLOBAL_TIMECAT_STATE.is_in_debug_mode() {
28 force_println_info(desc, info);
29 }
30}
31
32#[inline]
33pub fn get_engine_version() -> String {
34 format!("{ENGINE_NAME} v{ENGINE_VERSION}")
35}
36
37pub fn print_engine_version() {
38 println_wasm!("{}", get_engine_version().colorize(SUCCESS_MESSAGE_STYLE));
39}
40
41pub fn print_cache_table_info(
42 name: &str,
43 table_len: impl fmt::Display,
44 table_size: impl fmt::Display,
45) {
46 let mut to_print = format!(
47 "{name} initialization complete with {table_len} entries taking {table_size} space."
48 );
49 if GLOBAL_TIMECAT_STATE.is_in_uci_mode() {
50 to_print = "info string ".to_string() + to_print.trim();
51 }
52 println_wasm!("{}", to_print.colorize(INFO_MESSAGE_STYLE));
53}