1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use crate::imports::*;

#[derive(Default, Handler)]
#[help("Basic command guide for using this software.")]
pub struct Guide;

impl Guide {
    async fn main(self: Arc<Self>, ctx: &Arc<dyn Context>, _argv: Vec<String>, _cmd: &str) -> cli::Result<()> {
        let guide = include_str!("guide.txt");

        let lines = guide.split('\n');

        let mut paras = Vec::<String>::new();
        let mut para = String::new();
        for line in lines {
            if line.trim().is_empty() {
                if !para.is_empty() {
                    let regex = Regex::new(r"\s+").unwrap();
                    let text = regex.replace_all(para.trim(), " ");
                    paras.push(text.to_string());
                    para.clear();
                }
            } else {
                para.push_str(line);
                para.push(' ');
            }
        }

        if !para.is_empty() {
            let regex = Regex::new(r"\s+").unwrap();
            let text = regex.replace_all(para.trim(), " ");
            paras.push(text.to_string());
            para.clear();
        }

        let desktop = Regex::new(r"^#(\[desktop\])?\s*").unwrap();

        for para in paras {
            if desktop.is_match(para.as_str()) {
                if !application_runtime::is_nw() {
                    continue;
                } else {
                    let text = desktop.replace(para.as_str(), "");
                    tprintln!(ctx);
                    tpara!(ctx, "{}", text);
                }
            } else {
                tprintln!(ctx);
                tpara!(ctx, "{}", para);
            }
        }
        tprintln!(ctx);

        Ok(())
    }
}