Skip to content

Commit 9939bca

Browse files
committed
feat: setup for ratatui
1 parent a7e287a commit 9939bca

9 files changed

Lines changed: 1453 additions & 43 deletions

File tree

Cargo.lock

Lines changed: 1254 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,9 @@ path = "src/main.rs"
1515

1616
[dependencies]
1717
argh = "0.1.13"
18+
inquire = "0.9.1"
19+
serde = { version = "1.0.228", features = ["derive"] }
20+
toml = "0.9"
21+
ratatui = "0.29"
22+
crossterm = "0.28"
23+
color-eyre = { version = "0.6.5", features = ["issue-url", "url"] }

justfile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11

22

3+
# Only needed for full dev cycle with publish
4+
deps:
5+
cargo install cargo-release
6+
37
install:
48
cargo install --path .
5-
9+
610
run *args:
711
cargo run {{args}}
812

@@ -20,4 +24,7 @@ lint:
2024

2125
fmt:
2226
cargo fmt
23-
cargo fix --allow-dirty --allow-stageds
27+
cargo fix --allow-dirty --allow-stageds
28+
29+
publish:
30+
cargo release

public_files/meetups.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[[meetups]]
2+
id = 0
3+
title = "Opensource Contributions Meetup #0"
4+
date = "?"
5+
description = "In this meetup we will build teams to contribute to or create opensource software, you will get support in doing so"
6+
markdown_url = "http://example.com/meetup.md"
7+
8+
[meetups.address]
9+
street = "Barfüsserplatz 6"
10+
city = "Basel"
11+
postal_code = "4051"
12+
country = "Switzerland"
13+
description = "Level 4 - Optravis Headquarter"
14+
15+
[[meetups.sponsors]]
16+
name = "Optravic LLC"
17+
website = "http://optravis.com"
18+
content = ""

public_files/meetups/opensource_0.md

Whitespace-only changes.

src/docs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn docs_ui() {
2+
println!("not implemented")
3+
}

src/main.rs

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,109 @@
1+
mod docs;
12
mod meetups;
23

34
use argh::FromArgs;
5+
use inquire::{InquireError, Select};
46

57
#[derive(FromArgs, PartialEq, Debug)]
68
/// The Rust-Basel cli.
79
struct Basel {
810
#[argh(subcommand)]
9-
nested: Commands,
11+
commands: Option<Command>,
1012
}
1113

1214
#[derive(FromArgs, PartialEq, Debug)]
1315
#[argh(subcommand)]
14-
enum Commands {
15-
One(JobCommand),
16-
Two(MeetupCommand),
16+
enum Command {
17+
Job(JobCommand),
18+
Mtp(MeetupCommand),
19+
Doc(DocCommand),
20+
Admin(AdminCommand),
1721
}
1822

23+
impl From<String> for Command {
24+
fn from(s: String) -> Self {
25+
match s.as_str() {
26+
"job" => Command::Job(JobCommand {}),
27+
"meetup" => Command::Mtp(MeetupCommand {}),
28+
"doc" => Command::Doc(DocCommand {}),
29+
_ => panic!("Unknown command"),
30+
}
31+
}
32+
}
33+
34+
fn command_as_vec() -> Vec<&'static str> {
35+
vec!["job", "meetup", "doc"]
36+
}
37+
38+
#[derive(FromArgs, PartialEq, Debug)]
39+
/// Find the featured jobs.
40+
#[argh(subcommand, name = "admin")]
41+
struct AdminCommand {}
42+
1943
#[derive(FromArgs, PartialEq, Debug)]
20-
/// First subcommand.
44+
/// Find the featured jobs.
45+
#[argh(subcommand, name = "job")]
46+
struct InitCommand {}
47+
48+
#[derive(FromArgs, PartialEq, Debug)]
49+
/// Find the featured jobs.
2150
#[argh(subcommand, name = "job")]
2251
struct JobCommand {}
2352

2453
#[derive(FromArgs, PartialEq, Debug)]
25-
/// Second subcommand.
54+
/// Go to the documentation for this application.
55+
#[argh(subcommand, name = "doc")]
56+
struct DocCommand {}
57+
58+
#[derive(FromArgs, PartialEq, Debug)]
59+
/// Explore meetups
2660
#[argh(subcommand, name = "meetup")]
2761
struct MeetupCommand {}
2862

2963
fn main() {
30-
let up: Basel = argh::from_env();
64+
let basel: Basel = argh::from_env();
65+
match basel.commands {
66+
Some(c) => match_command(c),
67+
None => {
68+
inquire();
69+
return;
70+
}
71+
}
72+
}
73+
74+
fn match_command(c: Command) {
75+
match c {
76+
Command::Job(_jobs) => {
77+
println!("Help needed to implement a nice job ui and systemy");
78+
}
79+
Command::Mtp(_mtp) => meetups::meetup_ui(),
80+
81+
Command::Doc(_doc) => docs::docs_ui(),
82+
Command::Admin(_admin_command) => inquire_admin(),
83+
}
84+
}
85+
86+
fn inquire() {
87+
let ans: Result<&str, InquireError> = Select::new("commands", command_as_vec()).prompt();
88+
89+
let Ok(ans) = ans else {
90+
println!("No selection made");
91+
return;
92+
};
93+
94+
match_command(ans.to_owned().into());
95+
}
96+
97+
fn inquire_admin() {
98+
let ans: Result<&str, InquireError> = Select::new("admin commands", vec!["init"]).prompt();
99+
100+
let Ok(ans) = ans else {
101+
println!("No selection made");
102+
return;
103+
};
104+
105+
match ans {
106+
"init" => meetups::init::init(),
107+
_ => println!("Unknown admin command"),
108+
}
31109
}

src/meetups/init.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use std::{fs, io::Write};
2+
3+
pub fn init() {
4+
let meetups = super::Meetups::default();
5+
6+
let mut file = fs::OpenOptions::new()
7+
.write(true)
8+
.create_new(true)
9+
.open("public_files/meetups.toml")
10+
.expect("Failed to create meetups.json file");
11+
12+
let toml_string =
13+
toml::to_string_pretty(&meetups).expect("Failed to serialize meetups to TOML");
14+
file.write_all(toml_string.as_bytes())
15+
.expect("Failed to write to file");
16+
}

src/meetups/mod.rs

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,75 @@
1+
use std::default;
2+
3+
use serde::{Deserialize, Serialize};
4+
5+
pub mod init;
6+
7+
#[derive(Debug, Deserialize, Serialize)]
8+
pub struct Meetups {
9+
pub meetups: Vec<Meetup>,
10+
}
11+
12+
impl Default for Meetups {
13+
fn default() -> Self {
14+
Meetups {
15+
meetups: vec![Meetup::default_with_id(0), Meetup::default_with_id(1)],
16+
}
17+
}
18+
}
19+
20+
#[derive(Debug, Deserialize, Serialize)]
121
pub struct Meetup {
222
pub id: u32,
323
pub title: String,
424
pub date: String,
5-
pub location: String,
25+
pub address: Address,
626
pub description: String,
27+
pub markdown_url: String,
728
pub sponsors: Vec<Sponsor>,
829
}
930

31+
#[derive(Debug, Deserialize, Serialize)]
32+
pub struct Address {
33+
pub street: String,
34+
pub city: String,
35+
pub postal_code: String,
36+
pub country: String,
37+
pub description: Option<String>,
38+
}
39+
40+
#[derive(Debug, Deserialize, Serialize)]
1041
pub struct Sponsor {
1142
pub name: String,
1243
pub website: Option<String>,
1344
pub content: Option<String>,
1445
}
46+
47+
impl Meetup {
48+
fn default_with_id(id: u32) -> Self {
49+
let title = format!("Meetup {}", id);
50+
Meetup {
51+
id,
52+
title,
53+
date: "2024-01-01".to_string(),
54+
address: Address {
55+
street: "123 Default St".to_string(),
56+
city: "Default City".to_string(),
57+
postal_code: "00000".to_string(),
58+
country: "Default Country".to_string(),
59+
description: Some("Go around the building and dance.".to_string()),
60+
},
61+
description: "This is a default meetup description.".to_string(),
62+
markdown_url: "http://example.com/meetup.md".to_string(),
63+
sponsors: vec![Sponsor {
64+
name: "Default Sponsor".to_string(),
65+
website: Some("http://sponsor.com".to_string()),
66+
content: Some("This is a default sponsor.".to_string()),
67+
}],
68+
}
69+
}
70+
}
71+
72+
73+
pub fn meetup_ui(){
74+
75+
}

0 commit comments

Comments
 (0)