Skip to content
Snippets Groups Projects
Commit c220a38e authored by thibault.capt's avatar thibault.capt
Browse files

merge local work on v1

parent 668150b8
No related branches found
No related tags found
1 merge request!1Tui
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/training-session.iml" filepath="$PROJECT_DIR$/.idea/training-session.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="EMPTY_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>
\ No newline at end of file
......@@ -6,3 +6,4 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
termion = "2.0.1"
\ No newline at end of file
mod training;
mod participant;
mod terminal;
use terminal::App;
fn main() {
println!("Hello, world!");
let mut app = App::new();
let _ = app.run();
}
#[derive(Debug)]
pub struct Participant {
pub firstname: String,
pub lastname: String,
pub age: u8
}
impl Participant {
pub fn new(firstname: &str, lastname: &str, age: u8) -> Participant {
Participant {
firstname: String::from(firstname),
lastname: String::from(lastname),
age
}
}
}
\ No newline at end of file
use std::io;
use crate::training::Training;
use termion::event::Key;
use termion::input::TermRead;
use crate::participant::Participant;
pub struct App {
training_list: Vec<Training>
}
impl App {
pub fn new() -> Self {
App { training_list: Vec::new() }
}
fn insert_training(
&mut self,
name: String,
description: String,
date: String,
lieu: String,
duration: i32,
participants: Vec<Participant>) {
self.training_list.push(
Training::new(name, description, date, lieu, duration, participants)
);
}
pub fn run(&mut self) {
loop {
println!("Choisir: ");
println!("'i' -> Insérer");
println!("'a' -> Afficher");
println!("'q' -> Quitter");
println!();
if let Some(Ok(event)) = io::stdin().keys().next() {
match event {
Key::Char('i') => self.insert_training(
"Foot".to_string(),
"Entrainment".to_string(),
"22.09.2023".to_string(),
"Bernex".to_string(),
120,
vec![Participant::new("Thibault", "Capt", 20)]
),
Key::Char('a') => println!("{:?}", self.training_list),
Key::Esc | Key::Char('q') => break,
_ => println!("Choix incorrecte")
}
}
}
}
}
use crate::participant::Participant;
#[derive(Debug)]
pub struct Training {
pub name: String,
pub description: String,
pub date: String,
pub location: String,
pub duration: i32,
pub participants: Vec<Participant>
}
impl Training {
pub fn new(
name: String,
description: String,
date: String,
location: String,
duration: i32,
participants: Vec<Participant>
) -> Training {
Training { name, description, date, location, duration, participants }
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment