quinjet 0.0.50

A fast, live, keyboard-first Git source-control interface for the terminal
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
#[cfg_attr(not(test), expect(clippy::wildcard_imports, reason = "shared"))]
use super::*;

#[expect(
    clippy::too_many_lines,
    reason = "the picker renders headings and worktree rows in one pass"
)]
#[expect(
    clippy::too_many_arguments,
    reason = "the picker receives one value for each modal field plus its palette"
)]
pub(crate) fn draw_projects(
    frame: &mut Frame<'_>,
    collapse_hits: &mut Vec<(Rect, std::path::PathBuf)>,
    groups: &[ProjectGroup],
    selected: usize,
    query: &crate::app::TextBuffer,
    collapsed: &HashSet<std::path::PathBuf>,
    loading: bool,
    opening: Option<&Path>,
    mode: ProjectOpenMode,
    ssh: Option<&SshContext>,
    list: &mut ModalList<'_>,
    theme: &Theme,
) -> Vec<(Rect, usize)> {
    let height = frame.area().height.saturating_sub(6).min(28);
    let area = centered_rect(
        frame.area().width.saturating_sub(10).min(88),
        height,
        frame.area(),
    );
    frame.render_widget(Clear, area);
    let title = match mode {
        ProjectOpenMode::Initial => " Open a project ",
        ProjectOpenMode::CurrentTab => " Switch project ",
        ProjectOpenMode::NewTab => " Open in new tab ",
    };
    let block = modal_block(title, theme);
    let inner = block.inner(area);
    frame.render_widget(block, area);
    let query_area = Rect::new(inner.x, inner.y, inner.width, 1);
    frame.render_widget(
        Paragraph::new(Line::from(vec![
            Span::styled(" / ", Style::default().fg(theme.accent)),
            Span::styled(query.value.as_str(), Style::default().fg(theme.text)),
        ]))
        .style(Style::default().bg(theme.panel_alt)),
        query_area,
    );
    set_text_cursor(
        frame,
        Rect::new(
            query_area.x + 3,
            query_area.y,
            query_area.width.saturating_sub(3),
            1,
        ),
        query,
        false,
    );
    let machine_hits = ssh.map_or_else(Vec::new, |context| {
        modal_ssh::draw_project_machines(
            frame,
            Rect::new(inner.x, inner.y.saturating_add(2), inner.width, 1),
            context,
            theme,
        )
    });
    let machine_rows = if ssh.is_some() { 2 } else { 0 };
    let list_area = Rect::new(
        inner.x,
        inner.y.saturating_add(2 + machine_rows),
        inner.width,
        inner.height.saturating_sub(5 + machine_rows),
    );
    if let Some(path) = opening {
        modal_ssh::draw_project_opening(frame, path, list_area, theme);
    } else if loading {
        frame.render_widget(
            Paragraph::new("  ◐ Loading projects…")
                .style(Style::default().fg(theme.accent).bg(theme.panel)),
            Rect::new(list_area.x, list_area.y, list_area.width, 1),
        );
        for offset in 1..list_area.height.min(7) {
            let width = list_area
                .width
                .saturating_sub(8_u16.saturating_add((offset % 3).saturating_mul(7)));
            frame.render_widget(
                Paragraph::new(format!(
                    "{}",
                    "".repeat(width.saturating_sub(6) as usize)
                ))
                .style(Style::default().fg(theme.border).bg(theme.panel)),
                Rect::new(
                    list_area.x,
                    list_area.y.saturating_add(offset),
                    list_area.width,
                    1,
                ),
            );
        }
    } else {
        let rows = App::filtered_project_rows(groups, &query.value, collapsed);
        let offset = list.offset(selected, list_area.height as usize, rows.len());
        let visible_lines = rows
            .iter()
            .enumerate()
            .skip(offset)
            .take(list_area.height as usize)
            .filter_map(|(index, row)| match row {
                ProjectRow::Group(group_index) => {
                    let group = groups.get(*group_index)?;
                    let expanded =
                        !collapsed.contains(&group.common_dir) || !query.value.is_empty();
                    Some((
                        project_header_line(
                            group,
                            expanded,
                            index == selected,
                            list_area.width as usize,
                            theme,
                        ),
                        Some(group.common_dir.clone()),
                        index,
                    ))
                }
                ProjectRow::Worktree {
                    group_index,
                    tree_index,
                } => {
                    let tree = groups.get(*group_index)?.worktrees.get(*tree_index)?;
                    Some((
                        project_worktree_line(
                            tree,
                            index == selected,
                            list_area.width as usize,
                            theme,
                        ),
                        None,
                        index,
                    ))
                }
            })
            .collect::<Vec<_>>();
        if visible_lines.is_empty() {
            let empty = if groups.is_empty() && mode == ProjectOpenMode::Initial {
                "No recent projects. Press Ctrl+O to enter a repository path."
            } else {
                "No projects match this filter"
            };
            frame.render_widget(
                Paragraph::new(empty).style(Style::default().fg(theme.muted)),
                list_area,
            );
        } else {
            collapse_hits.extend(visible_lines.iter().enumerate().filter_map(
                |(line_index, (_, common_dir, _))| {
                    common_dir.as_ref().map(|common_dir| {
                        (
                            Rect::new(
                                list_area.x.saturating_add(1),
                                list_area.y.saturating_add(cells(line_index)),
                                3,
                                1,
                            ),
                            common_dir.clone(),
                        )
                    })
                },
            ));
            for (line_index, (_, _, index)) in visible_lines.iter().enumerate() {
                list.hit(
                    Rect::new(
                        list_area.x,
                        list_area.y.saturating_add(cells(line_index)),
                        list_area.width,
                        1,
                    ),
                    *index,
                );
            }
            frame.render_widget(
                Paragraph::new(
                    visible_lines
                        .into_iter()
                        .map(|(line, ..)| line)
                        .collect::<Vec<_>>(),
                ),
                list_area,
            );
        }
    }
    let selected_group = matches!(
        App::filtered_project_rows(groups, &query.value, collapsed).get(selected),
        Some(ProjectRow::Group(_))
    );
    let hint = if opening.is_some() {
        "Opening project…".to_owned()
    } else {
        let machines = ssh.map_or("", |_| "   Tab machine");
        if selected_group {
            let escape = if mode == ProjectOpenMode::Initial {
                "quit"
            } else {
                "close"
            };
            format!("Enter/Space fold   ←/→{machines}   Ctrl+E all   Esc {escape}")
        } else {
            match mode {
                ProjectOpenMode::Initial => {
                    format!("Enter open{machines}   Ctrl+E all   Ctrl+O path   Esc quit")
                }
                ProjectOpenMode::CurrentTab => {
                    format!("Enter switch{machines}   Ctrl+E all   Del forget   Esc close")
                }
                ProjectOpenMode::NewTab => {
                    format!("Enter new tab{machines}   Ctrl+E all   Del forget   Esc close")
                }
            }
        }
    };
    draw_modal_hint(frame, area, &hint, theme);
    machine_hits
}

#[expect(
    clippy::too_many_arguments,
    reason = "the picker receives its modal state, list geometry, and palette"
)]
pub(super) fn draw_pull_request_repositories(
    frame: &mut Frame<'_>,
    items: &[GitHubRepository],
    selected: usize,
    query: &crate::app::TextBuffer,
    loading: bool,
    list: &mut ModalList<'_>,
    theme: &Theme,
) {
    let height = (cells(items.len()) + 7)
        .min(frame.area().height.saturating_sub(8))
        .max(10);
    let area = centered_rect(
        frame.area().width.saturating_sub(12).min(82),
        height,
        frame.area(),
    );
    frame.render_widget(Clear, area);
    let block = modal_block(" Pull Request Repository ", theme);
    let inner = block.inner(area);
    frame.render_widget(block, area);
    let query_area = Rect::new(inner.x, inner.y, inner.width, 1);
    frame.render_widget(
        Paragraph::new(Line::from(vec![
            Span::styled(" / ", Style::default().fg(theme.accent)),
            Span::styled(query.value.as_str(), Style::default().fg(theme.text)),
        ]))
        .style(Style::default().bg(theme.panel_alt)),
        query_area,
    );
    set_text_cursor(
        frame,
        Rect::new(
            query_area.x + 3,
            query_area.y,
            query_area.width.saturating_sub(3),
            1,
        ),
        query,
        false,
    );
    let list_area = Rect::new(
        inner.x,
        inner.y + 2,
        inner.width,
        inner.height.saturating_sub(4),
    );
    let visible = App::filtered_github_repositories(items, &query.value);
    let offset = list.offset(selected, list_area.height as usize, visible.len());
    let lines = visible
        .iter()
        .skip(offset)
        .take(list_area.height as usize)
        .enumerate()
        .filter_map(|(visible_offset, index)| {
            let repository = items.get(*index)?;
            let active = offset + visible_offset == selected;
            let background = if active { theme.selected } else { theme.panel };
            let remotes = if repository.remotes.is_empty() {
                "inferred".to_owned()
            } else {
                repository.remotes.join(", ")
            };
            Some(Line::from(vec![
                Span::styled(
                    if active { "" } else { "   " },
                    Style::default().fg(theme.accent).bg(background),
                ),
                Span::styled(
                    truncate_middle(
                        &repository.display_name(),
                        list_area.width.saturating_sub(24) as usize,
                    ),
                    Style::default()
                        .fg(theme.text)
                        .bg(background)
                        .add_modifier(if active {
                            Modifier::BOLD
                        } else {
                            Modifier::empty()
                        }),
                ),
                Span::styled(
                    format!("  remote {remotes}"),
                    Style::default().fg(theme.muted).bg(background),
                ),
            ]))
        })
        .collect::<Vec<_>>();
    for index in 0..lines.len() {
        list.hit(
            Rect::new(
                list_area.x,
                list_area.y.saturating_add(cells(index)),
                list_area.width,
                1,
            ),
            offset.saturating_add(index),
        );
    }
    if loading {
        frame.render_widget(
            Paragraph::new("Discovering GitHub repositories from configured remotes…")
                .style(Style::default().fg(theme.muted)),
            list_area,
        );
    } else {
        frame.render_widget(Paragraph::new(lines), list_area);
    }
    draw_modal_hint(
        frame,
        area,
        if loading {
            "Discovering repositories…   Esc close"
        } else {
            "Enter select repository and reopen only the entered PR   Esc close"
        },
        theme,
    );
}

#[expect(clippy::integer_division, reason = "layout maths works in whole cells")]
pub(super) fn draw_palette(
    frame: &mut Frame<'_>,
    app: &App,
    query: &crate::app::TextBuffer,
    selected: usize,
    list: &mut ModalList<'_>,
    theme: &Theme,
) {
    let commands = app.palette_commands(&query.value);
    let height = (cells(commands.len()) + 6)
        .min(frame.area().height.saturating_sub(6))
        .max(8);
    let area = Rect::new(
        frame.area().x
            + (frame
                .area()
                .width
                .saturating_sub(76.min(frame.area().width.saturating_sub(8))))
                / 2,
        frame.area().y + 3,
        76.min(frame.area().width.saturating_sub(8)),
        height,
    );
    frame.render_widget(Clear, area);
    let block = modal_block(" Command Palette ", theme);
    let inner = block.inner(area);
    frame.render_widget(block, area);
    let query_area = Rect::new(inner.x, inner.y, inner.width, 1);
    frame.render_widget(
        Paragraph::new(Line::from(vec![
            Span::styled(" > ", Style::default().fg(theme.accent)),
            Span::styled(query.value.as_str(), Style::default().fg(theme.text)),
        ]))
        .style(Style::default().bg(theme.panel_alt)),
        query_area,
    );
    set_text_cursor(
        frame,
        Rect::new(
            query_area.x + 3,
            query_area.y,
            query_area.width.saturating_sub(3),
            1,
        ),
        query,
        false,
    );
    let list_area = Rect::new(
        inner.x,
        inner.y + 2,
        inner.width,
        inner.height.saturating_sub(2),
    );
    let offset = list.offset(selected, list_area.height as usize, commands.len());
    let lines = commands
        .iter()
        .skip(offset)
        .take(list_area.height as usize)
        .enumerate()
        .map(|(index, command)| palette_line(*command, offset + index == selected, theme))
        .collect::<Vec<_>>();
    for index in 0..lines.len() {
        list.hit(
            Rect::new(
                list_area.x,
                list_area.y.saturating_add(cells(index)),
                list_area.width,
                1,
            ),
            offset.saturating_add(index),
        );
    }
    frame.render_widget(Paragraph::new(lines), list_area);
}

pub(super) fn palette_line(
    command: PaletteCommand,
    selected: bool,
    theme: &Theme,
) -> Line<'static> {
    let background = if selected {
        theme.selected
    } else {
        theme.panel
    };
    Line::from(vec![
        Span::styled(
            if selected { "" } else { "   " },
            Style::default().fg(theme.accent).bg(background),
        ),
        Span::styled(
            command.label(),
            Style::default()
                .fg(theme.text)
                .bg(background)
                .add_modifier(if selected {
                    Modifier::BOLD
                } else {
                    Modifier::empty()
                }),
        ),
    ])
}