wini_cli/init/
mod.rs

1use {
2    err::InitError,
3    inquire::{
4        ui::{RenderConfig, Styled},
5        Select,
6        Text,
7    },
8    std::{fmt::Display, sync::LazyLock},
9};
10
11pub mod ask;
12pub mod err;
13pub mod git;
14pub mod rename;
15
16pub const SEP: &str = "\x1B[90m│\x1B[0m";
17
18pub fn sep() {
19    println!("{SEP}");
20}
21
22/// The official URL of the repo
23const WINI_REPO: &str = "https://codeberg.org/wini/wini-template";
24
25/// The render config used by inquire for the prompts
26static RENDER_CONFIG: LazyLock<RenderConfig> = LazyLock::new(|| {
27    RenderConfig::default_colored()
28        .with_prompt_prefix(Styled::new("◆").with_fg(inquire::ui::Color::LightCyan))
29        .with_answered_prompt_prefix(Styled::new("◇").with_fg(inquire::ui::Color::DarkCyan))
30        .with_highlighted_option_prefix(Styled::new("►").with_fg(inquire::ui::Color::DarkCyan))
31});
32
33const HEADER: &str = "\
34┌───────────────────────────────────┐
35│ \x1b[36mWelcome to your new Wini project!\x1B[0m │
36\x1b[36m◆\x1b[0m ──────────────────────────────────┘";
37
38
39const OFFICIAL_REPOSITORY_OPTIONS: &[&str] = &[
40    "Basic",
41    "Basic - Workspace",
42    "Meta",
43    "Meta - Workspace",
44];
45const OFFICIAL_REPOSITORY_BRANCHES: &[&str] = &["main", "workspaces", "meta", "meta-workspaces"];
46
47pub struct RepoSummary {
48    dir: String,
49    remote_url: Option<String>,
50    branch: String,
51    last_commit_hash: String,
52}
53
54/// Creates a select prompt
55pub fn select<T>(title: &str, options: Vec<T>) -> Result<usize, InitError>
56where
57    T: Display,
58{
59    match Select::new(title, options).with_vim_mode(true).raw_prompt() {
60        Ok(r) => Ok(r.index),
61        Err(_) => Err(InitError::ManualExit),
62    }
63}
64
65/// Creates an input prompt
66pub fn input(prompt: &str) -> Result<String, InitError> {
67    Text::new(prompt)
68        .prompt()
69        .map_err(|_| InitError::ManualExit)
70}