Skip to main content

git_same/setup/screens/
provider.rs

1//! Step 1: Provider selection screen with descriptions.
2
3use crate::setup::state::SetupState;
4use crate::types::ProviderKind;
5use ratatui::layout::Rect;
6use ratatui::style::{Color, Modifier, Style};
7use ratatui::text::{Line, Span};
8use ratatui::widgets::Paragraph;
9use ratatui::Frame;
10
11/// Get a short description for each provider.
12fn provider_description(kind: ProviderKind) -> &'static str {
13    match kind {
14        ProviderKind::GitHub => "github.com \u{2014} Public and private repositories",
15        ProviderKind::GitHubEnterprise => "GitHub Enterprise Cloud & Server (coming soon)",
16        ProviderKind::GitLab => "gitlab.com (coming soon)",
17        ProviderKind::GitLabSelfManaged => "GitLab Dedicated & Self-Managed (coming soon)",
18        ProviderKind::Codeberg => "codeberg.org (coming soon)",
19        ProviderKind::Bitbucket => "bitbucket.org (coming soon)",
20    }
21}
22
23pub fn render(state: &SetupState, frame: &mut Frame, area: Rect) {
24    let mut lines: Vec<Line> = Vec::new();
25
26    // Title
27    lines.push(Line::from(Span::styled(
28        "  Select your Git provider",
29        Style::default()
30            .fg(Color::Cyan)
31            .add_modifier(Modifier::BOLD),
32    )));
33    lines.push(Line::raw(""));
34
35    // Provider list with descriptions
36    for (i, choice) in state.provider_choices.iter().enumerate() {
37        let is_selected = i == state.provider_index;
38        let marker = if is_selected { "  \u{25b8}  " } else { "     " };
39
40        let (label_style, desc_style) = if !choice.available {
41            (
42                Style::default().fg(Color::DarkGray),
43                Style::default().fg(Color::DarkGray),
44            )
45        } else if is_selected {
46            (
47                Style::default()
48                    .fg(Color::Cyan)
49                    .add_modifier(Modifier::BOLD),
50                Style::default().fg(Color::White),
51            )
52        } else {
53            (
54                Style::default().fg(Color::White),
55                Style::default().fg(Color::DarkGray),
56            )
57        };
58
59        lines.push(Line::from(vec![
60            Span::styled(marker, label_style),
61            Span::styled(&choice.label, label_style),
62        ]));
63
64        // Description line
65        lines.push(Line::from(Span::styled(
66            format!("        {}", provider_description(choice.kind)),
67            desc_style,
68        )));
69
70        lines.push(Line::raw(""));
71    }
72
73    let widget = Paragraph::new(lines);
74    frame.render_widget(widget, area);
75}
76
77#[cfg(test)]
78#[path = "provider_tests.rs"]
79mod tests;