A simple CPU rendered GUI IDE experience.
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
use std::iter::{chain, repeat};

use dsb::Cell;
use dsb::cell::Style;
use lsp_types::WorkDoneProgress;

use crate::lsp::{Client, Rq};
use crate::rnd::simplify_path;
use crate::sym::Symbols;
use crate::text::TextArea;
#[derive(Default, Debug)]
pub struct Bar {
    pub last_action: String,
}

impl Bar {
    pub fn write_to(
        &self,
        color: [u8; 3],
        bg: [u8; 3],
        (into, (w, _)): (&mut [Cell], (usize, usize)),
        oy: usize,
        fname: &str,
        state: &super::State,
        _t: &TextArea,
        lsp: Option<&Client>,
    ) {
        let fname = simplify_path(fname);
        let row = &mut into[oy * w..oy * w + w];
        row.fill(Cell {
            style: Style::new(color, bg) | Style::ITALIC,
            letter: None,
        });
        fn s(s: &str) -> impl Iterator<Item = (char, u8)> {
            s.chars().zip(repeat(0))
        }
        use super::State;
        match state {
            State::Default if super::ctrl() => {
                let x = "C + { S, Q, V, Z, Y }".chars();
                x.zip(&mut *row).for_each(|(x, y)| {
                    y.letter = Some(x);
                });
                row.iter_mut()
                    .rev()
                    .zip(self.last_action.chars().rev())
                    .for_each(|(x, y)| x.letter = Some(y));
            }
            State::Default => {
                row[1.."gracilaria".len() + 1]
                    .iter_mut()
                    .zip("gracilaria".chars())
                    .for_each(|(x, y)| x.letter = Some(y));
                row[w / 2 - fname.len() / 2
                    ..w / 2 - fname.len() / 2 + fname.len()]
                    .iter_mut()
                    .zip(fname.chars())
                    .for_each(|(x, y)| x.letter = Some(y));
                // lsp.map(|x| dbg!(x.progress));
                if let Some(x) = lsp
                    && let Some(m) = x
                        .progress
                        .iter(&x.progress.guard())
                        .find_map(|x| match x.1 {
                            Some((WorkDoneProgress::Report(x), b)) =>
                                format!(
                                    "{}: {}",
                                    b.title,
                                    x.message.clone().unwrap_or_default()
                                )
                                .into(),
                            _ => None,
                        })
                {
                    // dbg!(&m);
                    row.iter_mut()
                        .rev()
                        .zip(m.chars().rev())
                        .for_each(|(x, y)| x.letter = Some(y));
                } else {
                    row.iter_mut()
                        .rev()
                        .zip(self.last_action.chars().rev())
                        .for_each(|(x, y)| x.letter = Some(y));
                }
            }
            State::Procure(x, r) => {
                r.prompt()
                    .chars()
                    .zip(repeat(Style::BOLD | Style::ITALIC))
                    .chain(s(&x.rope.to_string()))
                    .zip(row)
                    .for_each(|((x, z), y)| {
                        *y = Cell {
                            letter: Some(x),
                            style: Style { flags: z, ..y.style },
                        }
                    });
            }
            State::Command(x) => {
                ":".chars()
                    .zip(repeat(Style::BOLD | Style::ITALIC))
                    .chain(s(&x.tedit.rope.to_string()))
                    .zip(row)
                    .for_each(|((x, z), y)| {
                        *y = Cell {
                            letter: Some(x),
                            style: Style { flags: z, ..y.style },
                        }
                    });
            }
            State::Symbols(Rq {
                result: Some(Symbols { tedit, .. }),
                request,
            }) => {
                chain(
                    [match request {
                        Some(_) => '…',
                        None => '_',
                    }],
                    "filter: ".chars(),
                )
                .zip(repeat(Style::BOLD | Style::ITALIC))
                .chain(s(&tedit.rope.to_string()))
                .zip(row)
                .for_each(|((x, z), y)| {
                    *y = Cell {
                        letter: Some(x),
                        style: Style { flags: z, ..y.style },
                    }
                });
            }
            State::RequestBoolean(x) => {
                x.prompt()
                    .chars()
                    .zip(repeat(Style::BOLD | Style::ITALIC))
                    .zip(row)
                    .for_each(|((x, z), y)| {
                        *y = Cell {
                            letter: Some(x),
                            style: Style { flags: z, ..y.style },
                        }
                    });
            }
            // State::Selection => {
            // let [(x1, y1), (x2, y2)] = t.position(x.clone()).unwrap();
            // format!("selection from ({x1}, {y1}) to ({x2}, {y2})")
            //     .chars()
            //     .rev()
            //     .zip(row.iter_mut().rev())
            //     .for_each(|(x, y)| y.letter = Some(x));
            // }
            State::Selection => {
                // let [(x1, y1), (x2, y2)] = t.position(x.clone()).unwrap();
                format!("selection mode")
                    .chars()
                    .rev()
                    .zip(row.iter_mut().rev())
                    .for_each(|(x, y)| y.letter = Some(x));
            }
            State::Search(x, y, z) => {
                format!("{} ({} of {z})", x.as_str(), y + 1)
                    .chars()
                    .zip(row)
                    .for_each(|(c, x)| {
                        x.letter = Some(c);
                    });
            }
            State::Save => unreachable!(),
            _ => {}
        }
    }
}