kaspa_cli_lib/modules/
guide.rs

1use crate::imports::*;
2
3#[derive(Default, Handler)]
4#[help("Basic command guide for using this software.")]
5pub struct Guide;
6
7impl Guide {
8    async fn main(self: Arc<Self>, ctx: &Arc<dyn Context>, _argv: Vec<String>, _cmd: &str) -> cli::Result<()> {
9        let guide = include_str!("guide.txt");
10
11        let lines = guide.split('\n');
12
13        let mut paras = Vec::<String>::new();
14        let mut para = String::new();
15        for line in lines {
16            if line.trim().is_empty() {
17                if !para.is_empty() {
18                    let regex = Regex::new(r"\s+").unwrap();
19                    let text = regex.replace_all(para.trim(), " ");
20                    paras.push(text.to_string());
21                    para.clear();
22                }
23            } else {
24                para.push_str(line);
25                para.push(' ');
26            }
27        }
28
29        if !para.is_empty() {
30            let regex = Regex::new(r"\s+").unwrap();
31            let text = regex.replace_all(para.trim(), " ");
32            paras.push(text.to_string());
33            para.clear();
34        }
35
36        let desktop = Regex::new(r"^#(\[desktop\])?\s*").unwrap();
37
38        for para in paras {
39            if desktop.is_match(para.as_str()) {
40                if !application_runtime::is_nw() {
41                    continue;
42                } else {
43                    let text = desktop.replace(para.as_str(), "");
44                    tprintln!(ctx);
45                    tpara!(ctx, "{}", text);
46                }
47            } else {
48                tprintln!(ctx);
49                tpara!(ctx, "{}", para);
50            }
51        }
52        tprintln!(ctx);
53
54        Ok(())
55    }
56}