agda_mode/
debug.rs

1static mut DEBUG_COMMAND: Option<Box<dyn Fn(String)>> = None;
2static mut DEBUG_RESPONSE: Option<Box<dyn Fn(String)>> = None;
3
4pub unsafe fn debug_command_via(f: impl Fn(String) + 'static) {
5    DEBUG_COMMAND = Some(Box::new(f));
6}
7
8pub unsafe fn debug_response_via(f: impl Fn(String) + 'static) {
9    DEBUG_RESPONSE = Some(Box::new(f));
10}
11
12pub unsafe fn dont_debug_command() {
13    DEBUG_COMMAND = None;
14}
15
16pub unsafe fn dont_debug_response() {
17    DEBUG_RESPONSE = None;
18}
19
20pub(crate) unsafe fn debug_command(s: String) -> bool {
21    DEBUG_COMMAND.as_ref().map(|f| f(s)).is_some()
22}
23
24pub(crate) unsafe fn debug_response(s: String) -> bool {
25    DEBUG_RESPONSE.as_ref().map(|f| f(s)).is_some()
26}
27
28pub unsafe fn toggle_debug_command() {
29    match DEBUG_COMMAND {
30        None => {
31            println!("Command debug mode is ON");
32            debug_command_via(|s| print!("{}", s))
33        }
34        Some(_) => {
35            println!("Command debug mode is OFF");
36            DEBUG_COMMAND = None
37        }
38    }
39}
40
41pub unsafe fn toggle_debug_response() {
42    match DEBUG_RESPONSE {
43        None => {
44            println!("Response debug mode is ON");
45            debug_response_via(|s| print!("{}", s))
46        }
47        Some(_) => {
48            println!("Response debug mode is OFF");
49            DEBUG_RESPONSE = None
50        }
51    }
52}