Repository navigation
Expand file tree
/
Copy pathui.rs
More file actions
1826 lines (1738 loc) · 88.9 KB
/
Copy pathui.rs
File metadata and controls
1826 lines (1738 loc) · 88.9 KB
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
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! Rendering of the dashboard with Ratatui.
//!
//! The design is monochrome at its core: one ink color on the terminal's own background. Hierarchy
//! and state come from bold, dim and inverse text, thick borders and symbols. Colors are an optional
//! layer on top (`hue`): every colored span keeps the weight and symbol it has without color, so
//! turning colors off (`C`, `color = false` in config.lua or `NO_COLOR`) leaves the monochrome look unchanged.
mod flows;
mod tasks;
mod view;
use std::sync::{
OnceLock,
atomic::{AtomicBool, Ordering},
};
use ratatui::{
Frame,
layout::{Constraint, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, BorderType, Clear, List, ListItem, Padding, Paragraph, Tabs},
};
use crate::{
app::{App, Choice, Filter, Focus, InputKind, Mode, ProjectStep, TaskState},
banner,
diff::{Row, SRow, Sign},
git::{Branch, DiffKind, FileEntry, TreeKind},
github::{self, Ci, Hits, Kind, Scope},
langs::Breakdown,
license::LICENSES,
logger::{self, Level},
palette,
repo::{Health, Owner, Repo},
scaffold::{PackageKind, langs},
syntax::Tok,
term::Term,
};
const SPINNER: [&str; 10] = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
/// The base color of the whole interface. `Reset` is the terminal's own foreground;
/// set any other color here to recolor all of Oxide at once.
const INK: Color = Color::Reset;
/// Accent hues of the color layer. They are the terminal's ANSI colors, so they follow its theme.
const ACCENT: Color = Color::Cyan; // focus, branch names, the logo
const GOOD: Color = Color::Green; // owned, ahead, staged, added, success
const WARN: Color = Color::Yellow; // modified, dirty, warnings, pins
const BAD: Color = Color::Red; // behind, conflicts, deleted, errors
const INFO: Color = Color::Blue; // untracked files, search
const PINK: Color = Color::Magenta; // running operations, stashes
/// Whether `hue` draws colors; set from `App::color` at the start of every frame.
static COLOR: AtomicBool = AtomicBool::new(true);
/// `style` in the accent color `c`, or unchanged when colors are off.
fn hue(style: Style, c: Color) -> Style {
if COLOR.load(Ordering::Relaxed) { style.fg(c) } else { style }
}
const PLAIN: Style = Style::new().fg(INK);
const BOLD: Style = PLAIN.add_modifier(Modifier::BOLD);
const DIM: Style = PLAIN.add_modifier(Modifier::DIM);
const ITALIC: Style = PLAIN.add_modifier(Modifier::ITALIC);
/// Selection and active tab: swaps ink and background.
const INVERSE: Style = PLAIN.add_modifier(Modifier::REVERSED).add_modifier(Modifier::BOLD);
/// Selection in a pane that does not have focus: inverse, but faded.
const INVERSE_DIM: Style = PLAIN.add_modifier(Modifier::REVERSED).add_modifier(Modifier::DIM);
/// Key caps in the footer.
const KEYCAP: Style = PLAIN.add_modifier(Modifier::REVERSED);
/// Empty columns between side-by-side panels and empty rows between stacked panels.
/// A terminal cell is about twice as tall as it is wide, so the 2 adjacent border columns with
/// a 1-column gap are as far apart as 2 stacked border rows with no gap.
const GAP_X: u16 = 1;
const GAP_Y: u16 = 0;
/// Empty rows between the banner and the header, so the logo has room to breathe.
const BANNER_GAP: u16 = 1;
/// Inner side padding of every panel (same cell-ratio reasoning: the sides get a column of
/// padding to match the one-row borders on top and bottom).
const SIDE_PAD: u16 = 1;
/// Rows the dashboard needs besides the banner; on shorter terminals the banner is hidden.
const MIN_DASHBOARD_ROWS: u16 = 24;
pub fn draw(f: &mut Frame, app: &mut App) {
COLOR.store(app.color, Ordering::Relaxed);
// Paint the ink color over the whole screen so text without an explicit style uses it too.
f.render_widget(Block::new().style(PLAIN), f.area());
let [mut area, footer] = Layout::vertical([Constraint::Min(0), Constraint::Length(footer_height(app))]).areas(f.area());
let banner = banner::get();
let banner_h = banner.lines.len() as u16;
if banner_h > 0 && f.area().height >= banner_h + BANNER_GAP + MIN_DASHBOARD_ROWS && f.area().width >= banner.width {
let [banner_area, rest] = Layout::vertical([Constraint::Length(banner_h), Constraint::Min(0)]).spacing(BANNER_GAP).areas(area);
// Center the art as one block so its lines stay aligned with each other.
let [_, art, _] = Layout::horizontal([Constraint::Fill(1), Constraint::Length(banner.width), Constraint::Fill(1)]).areas(banner_area);
f.render_widget(Paragraph::new(banner.lines.clone()).style(hue(BOLD, ACCENT)), art);
area = rest;
}
let [header, body, log] =
Layout::vertical([Constraint::Length(3), Constraint::Min(8), Constraint::Length(if app.logs { 8 } else { 0 })]).spacing(GAP_Y).areas(area);
let [left, right] =
Layout::horizontal([Constraint::Percentage(54), Constraint::Fill(1)]).spacing(GAP_X).areas(body);
draw_header(f, app, header);
draw_repos(f, app, left);
draw_details(f, app, right);
if app.logs {
draw_log(f, app, log);
}
draw_footer(f, app, footer);
// A pending confirmation is drawn on top of the view it was asked from.
let view = match (app.mode, &app.confirm, &app.visibility) {
(Mode::Confirm, Some(c), _) => c.back,
(Mode::Visibility, _, Some(v)) => v.back,
(mode, ..) => mode,
};
match view {
Mode::Diff => draw_diff(f, app),
Mode::Picker => view::draw_picker(f, app),
Mode::Code => view::draw_code(f, app),
Mode::Tasks => tasks::draw_tasks(f, app),
Mode::Task => tasks::draw_task(f, app),
Mode::History => draw_history(f, app),
Mode::Branches => draw_branches(f, app),
Mode::Reflog => draw_reflog(f, app),
Mode::Trees => draw_trees(f, app),
Mode::Remotes => draw_remotes(f, app),
Mode::GitHub => draw_github(f, app),
Mode::Text => draw_text(f, app),
Mode::Finder => draw_finder(f, app),
Mode::Project => draw_project(f, app),
Mode::Tags => draw_tags(f, app),
Mode::Workflows => flows::draw_workflows(f, app),
Mode::WorkflowRun => {
flows::draw_workflows(f, app);
flows::draw_run_form(f, app);
}
Mode::WorkflowNew => {
flows::draw_workflows(f, app);
flows::draw_wizard(f, app);
}
_ => {}
}
// A shell fills the whole screen; an editor is drawn like the other panels, above the key bar.
let editor = app.program_shown();
let [body, _] = Layout::vertical([Constraint::Min(0), Constraint::Length(footer_height(app))]).areas(f.area());
if app.mode == Mode::Terminal
&& let Some(t) = app.term.and_then(|i| app.terms.get_mut(i))
{
draw_terminal(f, t, if editor { body } else { f.area() });
}
if app.mode == Mode::Palette {
draw_palette(f, app);
}
if app.mode == Mode::Help {
draw_help(f);
}
}
/// The new-project menu: a centered popup whose content depends on the page.
fn draw_project(f: &mut Frame, app: &mut App) {
let Some(v) = app.project.as_mut() else { return };
let name = v.repo.file_name().map_or_else(String::new, |n| n.to_string_lossy().into_owned());
let page = match v.step {
ProjectStep::Lang => "language",
ProjectStep::Package => langs()[v.lang].package.map_or("package", |p| p.kind.noun()),
ProjectStep::Variant => "variant",
ProjectStep::License => "license",
ProjectStep::Confirm => "confirm",
};
let area = f.area();
let w = 80.min(area.width);
// Rows of the page's list plus the lines around it (borders, filter or holder line).
let (rows, extra) = match v.step {
ProjectStep::Lang => (v.choices().len(), 4),
ProjectStep::Package => (3, 4),
ProjectStep::Variant => (langs()[v.lang].variants.len(), 3),
ProjectStep::License => (LICENSES.len() + 1, 4),
// The plan, a line for programs that are missing and the lines around them.
ProjectStep::Confirm => (v.plan.as_ref().map_or(0, |p| p.actions.len() + usize::from(!p.missing.is_empty())), 7),
};
let h = (rows as u16 + extra).clamp(6, area.height.saturating_sub(2).max(6)).min(area.height);
let [_, mid, _] = Layout::vertical([Constraint::Fill(1), Constraint::Length(h), Constraint::Fill(1)]).areas(area);
let [_, popup, _] = Layout::horizontal([Constraint::Fill(1), Constraint::Length(w), Constraint::Fill(1)]).areas(mid);
f.render_widget(Clear, popup);
let block = pane(format!(" New project · {name} · {page} "), true);
let inner = block.inner(popup);
f.render_widget(block, popup);
match v.step {
ProjectStep::Lang => {
let [filter, list] = Layout::vertical([Constraint::Length(2), Constraint::Min(1)]).areas(inner);
let found = v.choices();
let count = format!("{}/{}", found.iter().filter(|c| matches!(c, Choice::Lang(_))).count(), langs().len());
let line = Line::from(vec![
Span::styled("Filter ▸ ", hue(BOLD, ACCENT)),
Span::styled(v.query.clone(), BOLD),
Span::styled("█", PLAIN),
Span::styled(format!(" {count}"), DIM),
]);
f.render_widget(Paragraph::new(line), filter);
if found.iter().all(|c| *c == Choice::Other) && !v.query.is_empty() {
f.render_widget(Paragraph::new("No language matches.").style(DIM.add_modifier(Modifier::ITALIC)), list);
}
let note_w = (list.width as usize).saturating_sub(17);
let items: Vec<ListItem> = found
.iter()
.map(|c| match c {
Choice::Lang(i) => {
let l = &langs()[*i];
ListItem::new(Line::from(vec![Span::styled(fit(l.name, 16), BOLD), Span::raw(" "), Span::styled(fit(l.variants[0].note, note_w), DIM)]))
}
Choice::Other => ListItem::new(Line::from(vec![
Span::styled(fit("Other / manual…", 16), hue(BOLD, ACCENT)),
Span::raw(" "),
Span::styled(fit("open a terminal here and set it up yourself", note_w), DIM),
])),
})
.collect();
f.render_stateful_widget(List::new(items).highlight_style(INVERSE), list, &mut v.lang_state);
}
ProjectStep::Package => {
let kind = langs()[v.lang].package.map_or(PackageKind::Packages, |p| p.kind);
let mut lines = vec![
Line::from(Span::styled(kind.help(), DIM)),
Line::raw(""),
Line::from(vec![Span::styled(format!("{} ▸ ", kind.noun().chars().next().map_or_else(String::new, |c| c.to_uppercase().chain(kind.noun().chars().skip(1)).collect())), hue(BOLD, ACCENT)), Span::styled(v.package.clone(), BOLD), Span::styled("█", PLAIN)]),
];
if let Some(e) = &v.package_error {
lines.push(Line::from(Span::styled(fit(e, inner.width as usize), hue(BOLD, BAD))));
}
f.render_widget(Paragraph::new(lines), inner);
}
ProjectStep::Variant => {
let lang = &langs()[v.lang];
let note_w = (inner.width as usize).saturating_sub(24);
let items: Vec<ListItem> = lang
.variants
.iter()
.enumerate()
.map(|(i, var)| {
let default = if i == 0 { " (default)" } else { "" };
ListItem::new(Line::from(vec![
Span::styled(fit(&format!("{}{default}", var.name), 23), BOLD),
Span::raw(" "),
Span::styled(fit(var.note, note_w), DIM),
]))
})
.collect();
f.render_stateful_widget(List::new(items).highlight_style(INVERSE), inner, &mut v.variant_state);
}
ProjectStep::License => {
let [list, holder] = Layout::vertical([Constraint::Min(1), Constraint::Length(2)]).areas(inner);
let name_w = (list.width as usize).saturating_sub(15);
let mut items: Vec<ListItem> = LICENSES
.iter()
.map(|l| ListItem::new(Line::from(vec![Span::styled(fit(l.id, 14), BOLD), Span::raw(" "), Span::styled(fit(l.name, name_w), DIM)])))
.collect();
items.push(ListItem::new(Line::from(vec![Span::styled(fit("None", 14), BOLD), Span::raw(" "), Span::styled(fit("no LICENSE file", name_w), DIM)])));
f.render_stateful_widget(List::new(items).highlight_style(INVERSE), list, &mut v.license_state);
let mut spans = vec![Span::styled("Holder ▸ ", hue(BOLD, ACCENT)), Span::styled(v.holder.clone(), if v.editing { BOLD } else { PLAIN })];
spans.push(if v.editing { Span::styled("█", PLAIN) } else { Span::styled(" (Tab edits)", DIM) });
spans.push(Span::styled(format!(" Year ▸ {}", v.year), DIM));
f.render_widget(Paragraph::new(vec![Line::raw(""), Line::from(spans)]), holder);
}
ProjectStep::Confirm => {
let Some(plan) = &v.plan else { return };
let lang = &langs()[v.lang];
let variant = lang.variants[v.variant_state.selected().unwrap_or(0)].name;
let license = v.license().map_or("no license", |l| l.id);
let packages = if v.packages.is_empty() { String::new() } else { format!(" · {}", v.packages.join(", ")) };
let mut lines = vec![
Line::from(Span::styled(fit(&format!("{} · {variant}{packages} · {license}", lang.name), inner.width as usize), BOLD)),
Line::from(Span::styled(fit(&format!("in {}", v.repo.display()), inner.width as usize), DIM)),
Line::raw(""),
];
// Leave room for the rows below the plan: a blank line and the commit option.
let room = (inner.height as usize).saturating_sub(lines.len() + 2 + usize::from(!plan.missing.is_empty()));
for a in plan.actions.iter().take(room) {
let label = a.label();
let style = if label.starts_with('$') { hue(PLAIN, ACCENT) } else { PLAIN };
lines.push(Line::from(Span::styled(fit(&label, inner.width as usize), style)));
}
if plan.actions.len() > room {
lines.push(Line::from(Span::styled(format!("… and {} more", plan.actions.len() - room), DIM)));
}
if !plan.missing.is_empty() {
lines.push(Line::from(Span::styled(format!("! not installed, skipped: {}", plan.missing.join(", ")), hue(BOLD, WARN))));
}
lines.push(Line::raw(""));
let (mark, style) = if v.commit { ("[x]", hue(BOLD, GOOD)) } else { ("[ ]", PLAIN) };
lines.push(Line::from(vec![Span::styled(mark, style), Span::styled(" Add initial commit and projects' initial files", PLAIN)]));
f.render_widget(Paragraph::new(lines), inner);
}
}
}
/// The embedded terminal, filling the whole screen: the shell's screen is copied cell by cell into the
/// frame, in the colors the shell asked for. The pseudo-terminal is resized to the room inside the border.
fn draw_terminal(f: &mut Frame, term: &mut Term, area: Rect) {
f.render_widget(Clear, area);
let mut name = term.repo.file_name().map_or_else(|| term.repo.display().to_string(), |n| n.to_string_lossy().into_owned());
// A shell in a folder of the repository says which one.
if let Ok(rel) = term.dir.strip_prefix(&term.repo)
&& !rel.as_os_str().is_empty()
{
name = format!("{name}/{}", rel.display());
}
let block = match &term.session {
// The key bar below the program already says how to leave it.
Some(s) => pane(format!(" {} ", s.title), true).padding(Padding::ZERO),
None => pane(format!(" Terminal · {name} "), true)
.padding(Padding::ZERO)
.title_bottom(Line::from(Span::styled(" Ctrl+T hide · Shift+PgUp/PgDn scroll · exit closes ", DIM))),
};
let inner = block.inner(area);
f.render_widget(block, area);
term.resize(inner.height, inner.width);
let buf = f.buffer_mut();
let cursor = term.with_screen(|screen| {
for row in 0..inner.height {
for col in 0..inner.width {
let Some(cell) = screen.cell(row, col) else { continue };
if cell.is_wide_continuation() {
continue; // drawn together with the wide character before it
}
let mut style = Style::new().fg(term_color(cell.fgcolor())).bg(term_color(cell.bgcolor()));
for (on, m) in [
(cell.bold(), Modifier::BOLD),
(cell.dim(), Modifier::DIM),
(cell.italic(), Modifier::ITALIC),
(cell.underline(), Modifier::UNDERLINED),
(cell.inverse(), Modifier::REVERSED),
] {
if on {
style = style.add_modifier(m);
}
}
let text = if cell.has_contents() { cell.contents() } else { " " };
buf[(inner.x + col, inner.y + row)].set_symbol(text).set_style(style);
}
}
// The cursor is only shown at the bottom of the history, where the shell is actually typing.
(screen.scrollback() == 0 && !screen.hide_cursor()).then(|| screen.cursor_position())
});
if let Some((row, col)) = cursor {
f.set_cursor_position((inner.x + col, inner.y + row));
}
}
/// A color of the shell's screen as a Ratatui color.
fn term_color(c: vt100::Color) -> Color {
match c {
vt100::Color::Default => Color::Reset,
vt100::Color::Idx(i) => Color::Indexed(i),
vt100::Color::Rgb(r, g, b) => Color::Rgb(r, g, b),
}
}
/// Panel frame: a thick bold border while the pane has focus, a thin dim one otherwise.
/// The title sits in a `─┤ title ├─` notch.
fn pane(title: String, focused: bool) -> Block<'static> {
let (border, style) = if focused { (BorderType::Thick, hue(BOLD, ACCENT)) } else { (BorderType::Plain, DIM) };
let title = Line::from(vec![
Span::styled("─┤ ", style),
Span::styled(title.trim().to_string(), style),
Span::styled(" ├", style),
]);
Block::bordered()
.border_type(border)
.padding(Padding::horizontal(SIDE_PAD))
.border_style(style)
.title(title)
}
/// Truncates (with `…`) or pads `s` to exactly `w` characters.
fn fit(s: &str, w: usize) -> String {
let n = s.chars().count();
if n > w {
let mut t: String = s.chars().take(w.saturating_sub(1)).collect();
t.push('…');
t
} else {
format!("{s:<w$}")
}
}
/// Progress bar of `width` cells, e.g. `▰▰▰▱▱▱▱▱▱▱`.
fn bar(done: usize, total: usize, width: usize) -> String {
let filled = (done * width).checked_div(total).unwrap_or(0).min(width);
format!("{}{}", "▰".repeat(filled), "▱".repeat(width - filled))
}
/// `30s`, `10m` or `2h` for a number of seconds.
fn interval(secs: u64) -> String {
match secs {
s if s % 3600 == 0 => format!("{}h", s / 3600),
s if s % 60 == 0 => format!("{}m", s / 60),
s => format!("{s}s"),
}
}
fn draw_header(f: &mut Frame, app: &App, area: Rect) {
let dirty = app.listed().filter(|r| r.health() != Health::Clean).count();
let ahead = app.listed().filter(|r| r.ahead > 0).count();
let behind = app.listed().filter(|r| r.behind > 0).count();
let spin = SPINNER[app.tick % SPINNER.len()];
// Right side, left to right: search, running operations, scan progress, totals.
let mut right = Vec::new();
if !app.search.is_empty() {
right.push(Span::styled(format!(" /{} ", app.search), hue(BOLD, INFO)));
}
if !app.busy.is_empty() {
right.push(Span::styled(format!(" {spin} {} running ", app.busy.len()), hue(BOLD, PINK)));
}
match app.scan {
Some((_, 0)) => right.push(Span::styled(format!(" {spin} discovering "), hue(BOLD, ACCENT))),
Some((done, total)) => right.push(Span::styled(format!(" {spin} scanning {} {done}/{total} ", bar(done, total, 10)), hue(BOLD, ACCENT))),
None => {}
}
// Totals: each non-zero count takes its hue, zero counts stay dim.
if app.cfg.autofetch > 0 {
right.push(Span::styled(format!(" ⟳ {} ", interval(app.cfg.autofetch)), DIM));
}
right.push(Span::styled(format!(" {} repos", app.listed().count()), DIM));
for (n, label, color) in [(dirty, "dirty", WARN), (ahead, "ahead", GOOD), (behind, "behind", BAD)] {
right.push(Span::styled(" · ", DIM));
right.push(Span::styled(format!("{n} {label}"), if n == 0 { DIM } else { hue(PLAIN, color) }));
}
right.push(Span::styled(" ", DIM));
let block = Block::bordered()
.padding(Padding::horizontal(SIDE_PAD))
.border_style(DIM)
.title(Line::from(vec![
Span::styled("─┤ ", DIM),
Span::styled("◆ OXIDE", hue(BOLD, ACCENT)),
Span::styled(format!(" v{}", env!("CARGO_PKG_VERSION")), DIM),
Span::styled(" ├", DIM),
]))
.title_top(Line::from(right).right_aligned());
let inner = block.inner(area);
f.render_widget(block, area);
let titles: Vec<String> = Filter::ALL
.iter()
.map(|&flt| {
let name = match flt {
Filter::All => "All",
Filter::Owned => "Owned",
Filter::Cloned => "Cloned",
Filter::Attention => "Attention",
};
format!(" {name} {} ", app.count(flt))
})
.collect();
let tabs = Tabs::new(titles).style(PLAIN).select(app.filter.index()).highlight_style(INVERSE).divider(Span::styled("┊", DIM));
f.render_widget(tabs, inner);
}
fn repo_row(r: &Repo, busy: Option<&str>, ci: Option<Ci>, tick: usize, name_w: usize) -> ListItem<'static> {
// Cloned repositories are dimmed so owned ones stand out.
let (badge, badge_style) = match r.owner {
Owner::Owned => ("own ", hue(PLAIN, GOOD)),
Owner::Cloned => ("clone", DIM),
};
// The two columns left of the name are breathing room inside the selection bar; they also hold
// the pin and ignore marks.
let mark = if r.pinned {
"★ "
} else if r.ignored {
"⊘ "
} else {
" "
};
let mut spans = vec![
Span::styled(mark, if r.ignored { DIM } else { hue(BOLD, WARN) }),
Span::styled(fit(&r.name, name_w), BOLD),
Span::raw(" "),
Span::styled(badge, badge_style),
Span::raw(" "),
Span::styled(fit(&r.branch, 14), hue(PLAIN, ACCENT)),
Span::raw(" "),
ci_span(ci, tick),
];
if r.ahead > 0 {
spans.push(Span::styled(format!("↑{} ", r.ahead), hue(PLAIN, GOOD)));
}
if r.behind > 0 {
spans.push(Span::styled(format!("↓{} ", r.behind), hue(PLAIN, BAD)));
}
if let Some(label) = busy {
spans.push(Span::styled(format!("{} {label}… ", SPINNER[tick % SPINNER.len()]), hue(BOLD, PINK)));
}
if r.error.is_some() {
spans.push(Span::styled("error", hue(BOLD, BAD)));
}
let counters = [
(r.conflicts(), "!", BAD),
(r.staged(), "+", GOOD),
(r.unstaged(), "~", WARN),
(r.untracked(), "?", INFO),
(r.stashes as usize, "$", PINK),
];
for (n, sym, color) in counters {
if n > 0 {
spans.push(Span::styled(format!("{sym}{n} "), hue(PLAIN, color)));
}
}
ListItem::new(Line::from(spans))
}
/// The two-column CI slot of a repository row: ✓ passing, ✗ failing, a spinner while running, ○ inconclusive.
fn ci_span(ci: Option<Ci>, tick: usize) -> Span<'static> {
match ci {
Some(Ci::Passing) => Span::styled("✓ ", hue(PLAIN, GOOD)),
Some(Ci::Failing) => Span::styled("✗ ", hue(BOLD, BAD)),
Some(Ci::Running) => Span::styled(format!("{} ", SPINNER[tick % SPINNER.len()]), hue(PLAIN, PINK)),
Some(Ci::Other) => Span::styled("○ ", DIM),
None => Span::raw(" "),
}
}
/// CI state of `r` when it was loaded for the branch that is checked out now.
fn ci_of(app: &App, r: &Repo) -> Option<Ci> {
app.ci.get(&r.path).filter(|(branch, _)| *branch == r.branch).map(|(_, state)| *state)
}
fn draw_repos(f: &mut Frame, app: &mut App, area: Rect) {
let hidden = if app.show_hidden { " · +ignored" } else { "" };
let title = format!(" Repositories · {} ({}) · by {}{hidden} ", app.filter.name(), app.visible.len(), app.sort.name());
let block = pane(title, app.focus == Focus::Repos);
if app.visible.is_empty() {
let msg = if app.scan.is_some() { "Scanning for repositories…" } else { "No repositories match. Press R to rescan." };
f.render_widget(Paragraph::new(msg).style(DIM.add_modifier(Modifier::ITALIC)).block(block), area);
return;
}
// Give the name column the spare width, between 12 and 28 characters.
let name_w = (area.width as usize).saturating_sub(54).clamp(12, 28);
let items: Vec<ListItem> = app
.visible
.iter()
.map(|&i| {
let r = &app.repos[i];
repo_row(r, app.busy.get(&r.path).copied(), ci_of(app, r), app.tick, name_w)
})
.collect();
let selection = if app.focus == Focus::Repos { INVERSE } else { INVERSE_DIM };
let list = List::new(items).block(block).highlight_style(selection);
f.render_stateful_widget(list, area, &mut app.repo_state);
}
/// Hue of a git status letter.
fn status_color(c: char) -> Color {
match c {
'A' => GOOD,
'M' | 'T' => WARN,
'D' | 'U' => BAD,
'R' | 'C' => ACCENT,
_ => INFO,
}
}
/// `XY path`: the index letter is bold when staged, untracked files are dimmed.
fn file_row(e: &FileEntry) -> ListItem<'static> {
if e.untracked() {
return ListItem::new(Line::from(Span::styled(format!("?? {}", e.path), hue(DIM, INFO))));
}
let x_style = if e.staged() || e.conflict() { BOLD } else { PLAIN };
let color = if e.conflict() { BAD } else { status_color(e.x) };
ListItem::new(Line::from(vec![
Span::styled(e.x.to_string(), hue(x_style, color)),
Span::styled(e.y.to_string(), hue(PLAIN, status_color(e.y))),
Span::styled(format!(" {}", e.path), PLAIN),
]))
}
/// A counter that is dimmed while it is zero, so only non-zero values stand out.
fn count_span(n: usize, prefix: &str, suffix: &str, color: Color) -> Span<'static> {
Span::styled(format!("{prefix}{n}{suffix}"), if n == 0 { DIM } else { hue(BOLD, color) })
}
/// `<hash> <subject> (<relative date>)` with the hash dimmed.
fn commit_line(commit: &str, label: Span<'static>) -> Line<'static> {
match commit.split_once(' ') {
Some((hash, rest)) => Line::from(vec![label, Span::styled(format!("{hash} "), hue(DIM, WARN)), Span::styled(rest.to_string(), PLAIN)]),
None => Line::from(vec![label, Span::styled(commit.to_string(), DIM)]),
}
}
/// A language's own colour: true colour where the terminal has it (`COLORTERM`), else the nearest of the
/// 256-colour palette's 6×6×6 cube.
fn lang_color(rgb: u32) -> Color {
static TRUECOLOR: OnceLock<bool> = OnceLock::new();
let truecolor = *TRUECOLOR.get_or_init(|| std::env::var("COLORTERM").is_ok_and(|v| v.contains("truecolor") || v.contains("24bit")));
let (r, g, b) = ((rgb >> 16) as u8, (rgb >> 8) as u8, rgb as u8);
if truecolor {
return Color::Rgb(r, g, b);
}
let q = |v: u8| (u16::from(v) * 5 + 127) / 255;
Color::Indexed((16 + 36 * q(r) + 6 * q(g) + q(b)) as u8)
}
/// Fill glyphs that tell languages apart by rank when colors are off.
const SHADES: [&str; 6] = ["█", "▓", "▒", "░", "▚", "▞"];
/// The glyph and style a language's bar and swatch are drawn with: its colour, or a shade by rank without colors.
fn lang_mark(rank: usize, rgb: u32) -> (&'static str, Style) {
if COLOR.load(Ordering::Relaxed) { ("█", PLAIN.fg(lang_color(rgb))) } else { (SHADES[rank % SHADES.len()], PLAIN) }
}
/// `82%`, or `<1%` for the tiny shares.
fn percent(p: f64) -> String {
if p < 1.0 { "<1%".to_string() } else { format!("{p:.0}%") }
}
/// `12.3 kB` style size.
fn human(bytes: u64) -> String {
match bytes {
b if b < 1024 => format!("{b} B"),
b if b < 1024 * 1024 => format!("{:.1} kB", b as f64 / 1024.0),
b => format!("{:.1} MB", b as f64 / 1048576.0),
}
}
/// One line for the details pane: a stacked bar of `cells` cells, one segment per language in its colour
/// (or shade). The names and shares are in the Languages pane.
fn langs_line(entry: Option<&(String, Result<Breakdown, String>)>, cells: usize) -> Vec<Span<'static>> {
let note = |msg: &str| vec![Span::styled(msg.to_string(), DIM.add_modifier(Modifier::ITALIC))];
let bd = match entry {
None => return note("counting…"),
Some((_, Err(_))) => return note("no commits yet"),
Some((_, Ok(bd))) => bd,
};
if bd.langs.is_empty() {
return note("none recognised");
}
// Each language gets the cells between its cumulative boundaries, so the bar always adds up to `cells`.
let mut spans = Vec::new();
let (mut cum, mut drawn) = (0u64, 0usize);
for (rank, st) in bd.langs.iter().enumerate() {
cum += st.bytes;
let end = (cum as f64 * cells as f64 / bd.total as f64).round() as usize;
if end > drawn {
let (glyph, style) = lang_mark(rank, st.color);
spans.push(Span::styled(glyph.repeat(end - drawn), style));
drawn = end;
}
}
spans
}
/// The Languages pane when it has focus: one row per language with its swatch, a bar, share, size and file count.
fn draw_langs(f: &mut Frame, app: &mut App, area: Rect, path: &std::path::Path) {
let entry = app.langs.get(path);
let count = match entry {
Some((_, Ok(bd))) => format!(" ({})", bd.langs.len()),
_ => String::new(),
};
let block = pane(format!(" Languages{count} "), true);
let note = |msg: &str, f: &mut Frame, block: Block<'static>| {
f.render_widget(Paragraph::new(msg.to_string()).style(DIM.add_modifier(Modifier::ITALIC)).block(block), area);
};
let bd = match entry {
None => return note("Counting…", f, block),
Some((_, Err(e))) => return note(&format!("No languages: {}", e.lines().next().unwrap_or("")), f, block),
Some((_, Ok(bd))) => bd,
};
if bd.langs.is_empty() {
return note("No programming or markup languages recognised.", f, block);
}
// Fixed columns: swatch, name, share, size, files; the bar takes what is left (up to 24 cells).
let fixed = 2 + 16 + 1 + 5 + 10 + 9;
let bar_w = (area.width as usize).saturating_sub(4 + fixed).min(24);
let rows: Vec<ListItem> = bd
.langs
.iter()
.enumerate()
.map(|(rank, st)| {
let p = bd.percent(st);
let (glyph, style) = lang_mark(rank, st.color);
let mut spans = vec![Span::styled(format!("{glyph} "), style), Span::styled(fit(st.name, 16), BOLD), Span::raw(" ")];
if bar_w >= 4 {
let filled = ((p * bar_w as f64 / 100.0).round() as usize).clamp(1, bar_w);
spans.push(Span::styled(glyph.repeat(filled), style));
spans.push(Span::styled("░".repeat(bar_w - filled), DIM));
}
spans.push(Span::styled(format!("{:>5}", percent(p)), PLAIN));
spans.push(Span::styled(format!("{:>10}", human(st.bytes)), DIM));
spans.push(Span::styled(format!("{:>6} f", st.files), DIM));
ListItem::new(Line::from(spans))
})
.collect();
let list = List::new(rows).block(block).highlight_style(INVERSE);
f.render_stateful_widget(list, area, &mut app.lang_state);
}
fn draw_details(f: &mut Frame, app: &mut App, area: Rect) {
let focused = app.focus == Focus::Files;
let Some(r) = app.selected().cloned() else {
f.render_widget(Paragraph::new("Select a repository.").style(DIM.add_modifier(Modifier::ITALIC)).block(pane(" Details ".into(), false)), area);
return;
};
// With the Languages pane focused it grows to fill the panel and the Changes list shrinks to a few rows.
let langs_focus = app.focus == Focus::Langs;
let (info_area, langs_area, files_area) = if langs_focus {
let [i, l, f] = Layout::vertical([Constraint::Length(10), Constraint::Min(4), Constraint::Length(4)]).spacing(GAP_Y).areas(area);
(i, Some(l), f)
} else {
let [i, f] = Layout::vertical([Constraint::Length(10), Constraint::Min(3)]).spacing(GAP_Y).areas(area);
(i, None, f)
};
let label = |s: &'static str| Span::styled(format!("{s:<9}"), DIM);
let ci = ci_of(app, &r);
let mut lines = vec![
Line::from(vec![label("path"), Span::styled(r.path.display().to_string(), ITALIC)]),
Line::from(vec![
label("branch"),
Span::styled(r.branch.clone(), hue(BOLD, ACCENT)),
Span::styled(
match &r.upstream {
Some(u) => format!(" → {u}"),
None => " (no upstream)".to_string(),
},
PLAIN,
),
]),
Line::from(vec![label("remote"), Span::styled(r.remote.clone().unwrap_or_else(|| "none (local only)".into()), ITALIC)]),
Line::from(vec![
label("owner"),
if r.owner == Owner::Owned { Span::styled("owned", hue(PLAIN, GOOD)) } else { Span::styled("cloned", PLAIN) },
]),
Line::from(vec![
label("sync"),
count_span(r.ahead as usize, "↑", " ahead", GOOD),
Span::raw(" "),
count_span(r.behind as usize, "↓", " behind", BAD),
Span::raw(if ci.is_some() { " ci " } else { "" }),
ci.map_or_else(|| Span::raw(""), |c| Span::styled(format!("{} ", c.label()), DIM)),
ci_span(ci, app.tick),
]),
Line::from(vec![
label("changes"),
count_span(r.staged(), "", " staged", GOOD),
Span::styled(" · ", DIM),
count_span(r.unstaged(), "", " modified", WARN),
Span::styled(" · ", DIM),
count_span(r.untracked(), "", " untracked", INFO),
Span::styled(" · ", DIM),
count_span(r.stashes as usize, "", " stashed", PINK),
]),
commit_line(&r.last_commit, label("commit")),
];
if let Some(e) = &r.error {
lines.push(Line::from(Span::styled(format!("error: {}", e.lines().next().unwrap_or("")), hue(BOLD, BAD))));
} else {
// The bar takes the rest of the line after the label (borders and padding take 4 columns).
let cells = (info_area.width as usize).saturating_sub(4 + 9).clamp(8, 60);
let mut spans = vec![label("langs")];
spans.extend(langs_line(app.langs.get(&r.path), cells));
lines.push(Line::from(spans));
}
f.render_widget(Paragraph::new(lines).block(pane(format!(" {} ", r.name), false)), info_area);
if let Some(langs_area) = langs_area {
draw_langs(f, app, langs_area, &r.path);
}
let block = pane(format!(" Changes ({}) ", r.files.len()), focused);
if r.files.is_empty() {
f.render_widget(Paragraph::new("Working tree clean ✓").style(DIM.add_modifier(Modifier::ITALIC)).block(block), files_area);
return;
}
let items: Vec<ListItem> = r.files.iter().map(file_row).collect();
let list = List::new(items).block(block).highlight_style(if focused { INVERSE } else { INVERSE_DIM });
f.render_stateful_widget(list, files_area, &mut app.file_state);
}
fn draw_log(f: &mut Frame, app: &App, area: Rect) {
let rows = area.height.saturating_sub(2) as usize;
let start = app.log.len().saturating_sub(rows);
let lines: Vec<Line> = app.log[start..]
.iter()
.enumerate()
.map(|(i, l)| {
// Level is shown by a symbol and weight: dim info, plain ok, bold warnings and errors.
let (sym, style) = match l.level {
Level::Info => (" ", DIM),
Level::Ok => ("✓ ", hue(PLAIN, GOOD)),
Level::Warn => ("! ", hue(BOLD, WARN)),
Level::Error => ("✗ ", hue(BOLD, BAD)),
};
// Entries fade out as they age: only the newest three keep their full weight.
let age = app.log.len() - start - 1 - i;
let style = if age >= 3 { style.add_modifier(Modifier::DIM) } else { style };
Line::from(vec![
Span::styled(format!("{} ", l.time), DIM),
Span::styled(sym, style),
Span::styled(l.text.clone(), style),
])
})
.collect();
f.render_widget(Paragraph::new(lines).block(pane(format!(" Log ({}) ", logger::zone_name()), false)), area);
}
/// The bottom row shows the key bar unless `h` hid it. Prompts (text input, confirmations) always need it,
/// and so does a message that is shown for a moment while the log panel is hidden.
fn footer_height(app: &App) -> u16 {
u16::from(app.hints || app.toast().is_some() || matches!(app.mode, Mode::Input(_) | Mode::Confirm | Mode::Visibility) || app.code.as_ref().is_some_and(|c| c.prompt.is_some()) || app.program_shown())
}
fn draw_footer(f: &mut Frame, app: &App, area: Rect) {
// With the log panel hidden, a new log message takes the key bar's place for a few seconds.
if let (Some(l), Mode::Normal) = (app.toast(), app.mode) {
let (sym, style) = match l.level {
Level::Info => (" ", DIM),
Level::Ok => ("✓ ", hue(PLAIN, GOOD)),
Level::Warn => ("! ", hue(BOLD, WARN)),
Level::Error => ("✗ ", hue(BOLD, BAD)),
};
let line = Line::from(vec![Span::styled(format!(" {} ", l.time), DIM), Span::styled(sym, style), Span::styled(l.text.trim().to_string(), style)]);
f.render_widget(Paragraph::new(line), area);
return;
}
if let Mode::Input(kind) = app.mode {
let prompt = match kind {
InputKind::Commit => format!("commit message → {} (Tab: type)", app.selected().map_or("", |r| r.name.as_str())),
InputKind::Tag => "new tag on HEAD: a name, then optionally a message (makes it an annotated tag)".to_string(),
InputKind::RemoteAdd => "add remote: <name> <url> (a lone URL becomes origin when there is none)".to_string(),
InputKind::RemoteUrl => format!("new URL of remote {}", app.remote_name()),
InputKind::RemoteRename => format!("new name of remote {}", app.remote_name()),
InputKind::Worktree => "new worktree for branch (created next to the repository, branch made if missing)".to_string(),
InputKind::Amend => format!("amend last commit of {} (empty = keep message, Tab: type)", app.selected().map_or("", |r| r.name.as_str())),
InputKind::Merge => format!("merge into {} (empty = upstream)", app.selected().map_or("", |r| r.branch.as_str())),
InputKind::Search => "search".to_string(),
InputKind::Branch => format!("new branch from {}", app.selected().map_or("", |r| r.branch.as_str())),
InputKind::Init => "git init in folder (created if missing)".to_string(),
InputKind::GhSearch => "search GitHub: words, user:name, repo:name or file:name (empty = your repositories)".to_string(),
InputKind::CloneTo => "clone into".to_string(),
InputKind::DeleteRepo => app.selected().map_or_else(String::new, |r| {
// `~` instead of the home directory keeps the part that matters on screen.
let home = crate::config::home();
let path = r.path.strip_prefix(&home).map_or_else(|_| r.path.display().to_string(), |p| format!("~/{}", p.display()));
format!("DELETE {path} from disk ({}). Type \"{}\"", r.risk_summary(), r.name)
}),
};
let mut spans = vec![Span::styled(format!(" {prompt} "), hue(BOLD, ACCENT))];
// The identity warning sits right next to the prompt so it is seen before the message is sent.
if let (InputKind::Commit | InputKind::Amend, Some(warn)) = (kind, &app.commit_warn) {
spans.push(Span::styled(format!("⚠ {warn} "), hue(BOLD, WARN)));
}
spans.extend([Span::styled("▸ ", hue(BOLD, ACCENT)), Span::styled(app.input.clone(), PLAIN), Span::styled("█", PLAIN)]);
f.render_widget(Paragraph::new(Line::from(spans)), area);
return;
}
if app.program_shown() {
let hints = [("Ctrl+T", "back to Oxide, it keeps running"), ("quit it", "to return to where you were")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if let (Mode::Code, Some(v)) = (app.mode, &app.code) {
if let Some((kind, text)) = &v.prompt {
f.render_widget(Paragraph::new(view::code_prompt(*kind, text)), area);
} else {
let hints = [("↑↓", "line"), ("Space", "page"), ("/ n N", "find"), (":", "go to line"), ("e", "edit"), ("r", "reload"), ("g G", "top/end"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
}
return;
}
if app.mode == Mode::Tasks {
let hints = [("↑↓", "move"), ("Enter", "run"), ("o", "last output"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if let (Mode::Task, Some(v)) = (app.mode, &app.task) {
let mut hints = vec![("↑↓", "scroll"), ("Space", "page"), ("g G", "top/end")];
if v.places() > 0 {
hints.extend([("n N", "next place"), ("Enter", "open"), ("e", "edit")]);
}
if v.state == TaskState::Running {
hints.push(("c", "stop"));
hints.push(("Esc", "hide"));
} else {
hints.push(("r", "run again"));
hints.push(("Esc", "close"));
}
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Picker {
let hints = [("type", "to filter"), ("↑↓", "move"), ("Enter", "view the file"), ("Ctrl+E", "edit"), ("Esc", "clear/close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Diff {
let both = app.diff.as_ref().is_some_and(|v| v.both);
if let Some(v) = app.diff.as_ref().filter(|v| v.pick.is_some()) {
let mut hints = vec![("↑↓", "line"), ("Space", "pick"), ("a", "all"), ("s", if v.kind == DiffKind::Staged { "unstage picked" } else { "stage picked" })];
if v.kind == DiffKind::Unstaged {
hints.push(("x", "discard picked"));
}
hints.push(("Esc", "back"));
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
let split = app.diff.as_ref().is_some_and(|v| v.split);
let mut hints = vec![("↑↓", "scroll"), ("Space", "page"), ("[ ]", "hunk"), ("← →", "pan"), ("m", if split { "one column" } else { "side by side" })];
if let Some(v) = app.diff.as_ref().filter(|v| v.stageable()) {
hints.push(("s", if v.kind == DiffKind::Staged { "unstage hunk" } else { "stage hunk" }));
hints.push(("v", "pick lines"));
if v.kind == DiffKind::Unstaged {
hints.push(("x", "discard hunk"));
}
}
if both {
hints.push(("Tab", "staged/unstaged"));
}
hints.push(("e", "edit"));
hints.push(("Esc", "close"));
let mut spans = Vec::new();
for (key, what) in hints {
spans.push(Span::styled(format!(" {key} "), hue(KEYCAP, ACCENT)));
spans.push(Span::styled(format!(" {what} "), DIM));
}
f.render_widget(Paragraph::new(Line::from(spans)), area);
return;
}
if let (Mode::Project, Some(v)) = (app.mode, &app.project) {
let hints: &[(&str, &str)] = match (v.step, v.editing) {
(ProjectStep::Lang, _) => &[("↑↓", "move"), ("type", "filter"), ("Enter", "select"), ("Esc", "clear/close")],
(ProjectStep::Package, _) => &[("type", "the name"), ("Enter", "continue"), ("Esc", "back")],
(ProjectStep::Variant, _) => &[("↑↓", "move"), ("Enter", "select"), ("Esc", "back")],
(ProjectStep::License, false) => &[("↑↓", "move"), ("Tab", "edit holder"), ("Enter", "continue"), ("Esc", "back")],
(ProjectStep::License, true) => &[("type", "copyright holder"), ("Enter", "done")],
(ProjectStep::Confirm, _) => &[("Enter", "set up"), ("c", "toggle first commit"), ("Esc", "back")],
};
f.render_widget(Paragraph::new(Line::from(hint_spans(hints))), area);
return;
}
if app.mode == Mode::History {
let hints = [("↑↓", "move"), ("Enter", "show the commit"), ("g G", "newest/oldest"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Reflog {
let hints = [("↑↓", "move"), ("u", "undo this entry"), ("Enter", "move branch here"), ("d", "show the commit"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Workflows {
let hints = [("↑↓", "move"), ("Enter", "run by hand"), ("n", "new workflow"), ("o", "browser"), ("e", "edit"), ("f", "refresh"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if let (Mode::WorkflowNew, Some(w)) = (app.mode, &app.wizard) {
use crate::app::WStep;
let hints: &[(&str, &str)] = match w.step {
WStep::Kind => &[("↑↓", "move"), ("Enter", "choose"), ("Esc", "cancel")],
WStep::Toolchain => &[("↑↓", "move"), ("Enter", "choose"), ("Esc", "back")],
WStep::Triggers | WStep::Options => &[("↑↓", "move"), ("Space", "check"), ("Enter", "next"), ("Esc", "back")],
WStep::Details => &[("↑↓", "field"), ("type", "edit"), ("Enter", "preview"), ("Esc", "back")],
WStep::Preview => &[("↑↓", "scroll"), ("Enter", "write the file"), ("c", "write, commit, push and run"), ("Esc", "back")],
};
f.render_widget(Paragraph::new(Line::from(hint_spans(hints))), area);
return;
}
if app.mode == Mode::WorkflowRun {
let hints = [("↑↓", "field"), ("type", "edit"), ("Space ←→", "check / choose"), ("Enter", "run"), ("Esc", "back")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Tags {
let hints = [("↑↓", "move"), ("Enter", "show the commit"), ("n", "new"), ("p", "push"), ("d", "delete"), ("D", "delete + remote"), ("r", "release"), ("R", "draft release"), ("o", "open release"), ("f", "refresh"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Remotes {
let hints = [("↑↓", "move"), ("a", "add"), ("e", "change URL"), ("n", "rename"), ("d", "remove"), ("Enter", "fetch"), ("Esc", "close")];
f.render_widget(Paragraph::new(Line::from(hint_spans(&hints))), area);
return;
}
if app.mode == Mode::Trees {
let hints = [("↑↓", "move"), ("Enter", "go to worktree"), ("n", "new worktree"), ("d", "remove"), ("D", "force remove"), ("p", "prune"), ("u", "update submodule"), ("U", "update all"), ("Esc", "close")];