1mod ansi_slice;
2mod line_wrapper;
3
4pub use ansi_slice::slice_ansi_text;
5#[allow(unused_imports)]
6pub use line_wrapper::LineWrapper;
7
8use std::sync::atomic::{AtomicBool, Ordering};
9use unicode_width::UnicodeWidthChar;
10
11static DEBUG_MODE: AtomicBool = AtomicBool::new(false);
13
14#[allow(dead_code)]
16pub fn set_debug_mode(enabled: bool) {
17 DEBUG_MODE.store(enabled, Ordering::Relaxed);
18}
19
20pub fn is_debug_mode() -> bool {
22 DEBUG_MODE.load(Ordering::Relaxed)
23}
24
25#[macro_export]
31macro_rules! debug_log {
32 ($($arg:tt)*) => {
33 if cfg!(debug_assertions) || $crate::utils::is_debug_mode() {
34 eprintln!("[DEBUG] {}", format_args!($($arg)*));
35 }
36 };
37}
38
39pub fn visual_width(s: &str) -> usize {
42 s.chars()
43 .map(|ch| UnicodeWidthChar::width(ch).unwrap_or(1))
44 .sum()
45}
46
47#[allow(dead_code)]
49pub fn char_width(ch: char) -> usize {
50 UnicodeWidthChar::width(ch).unwrap_or(1)
51}