From fb79b520d4969e98ce5b9e844faceb789ae41e21 Mon Sep 17 00:00:00 2001 From: WanderingPenwing Date: Fri, 13 Dec 2024 18:26:58 +0100 Subject: [PATCH] display bloc --- src/pendragon/debug.rs | 36 ++++++++++++++++++++++++++++-------- src/pendragon/structure.rs | 4 ++-- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/pendragon/debug.rs b/src/pendragon/debug.rs index 0af12cd..cf2a94f 100644 --- a/src/pendragon/debug.rs +++ b/src/pendragon/debug.rs @@ -119,10 +119,10 @@ impl fmt::Display for ErreurPendragon { impl fmt::Display for Commande { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//' match self { - Self::Definis(nom, type_element) => write!(f, "Definis {} comme {}.", nom, type_element.nom()), - Self::Demande(nom) => write!(f, "Demande {}.", nom), - Self::Modifie(nom, expression) => write!(f, "Modifie {} avec {:?}.", nom, expression), - Self::Affiche(expression) => write!(f, "Affiche {:?}.", expression), + Self::Definis(nom, type_element) => write!(f, "{}:{}", nom, type_element.nom()), + Self::Demande(nom) => write!(f, "{}?", nom), + Self::Modifie(nom, expression) => write!(f, "{}={:?}", nom, expression), + Self::Affiche(expression) => write!(f, "#{:?}", expression), } } } @@ -190,9 +190,14 @@ impl fmt::Display for Operateur { impl fmt::Display for Programme { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//' - let mut texte: String = format!("variables : {:?}", self.variables); - for (index, phrase) in self.contenu.iter().enumerate() { - texte += &format!("\n#{:2}-{}", index+1, phrase); + let mut texte: String = format!("variables : {:?}\n", self.variables); + let mut nombre_retour: usize = 0; + for phrase in &self.contenu { + if texte.len()/30 > nombre_retour { + texte += "\n"; + nombre_retour = texte.len()/30; + } + texte += &format!("{}, ", phrase); } write!(f, "{}", texte) } @@ -202,7 +207,22 @@ impl fmt::Display for Phrase { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//' match self { Self::Commande(commande) => write!(f, "{}", commande), - Self::Bloc(_bloc) => write!(f, "bloc inconnu"), + Self::Bloc(bloc) => write!(f, "{}", bloc), } } +} + +impl fmt::Display for Bloc { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {//' + let mut texte: String = format!("\n[{:?}] : [", self.condition); + let mut nombre_retour: usize = 0; + for phrase in &self.contenu { + if texte.len()/30 > nombre_retour { + texte += "\n"; + nombre_retour = texte.len()/30; + } + texte += &format!("{}, ", phrase); + } + write!(f, "{}]", texte) + } } \ No newline at end of file diff --git a/src/pendragon/structure.rs b/src/pendragon/structure.rs index 7172498..640bfd0 100644 --- a/src/pendragon/structure.rs +++ b/src/pendragon/structure.rs @@ -69,8 +69,8 @@ impl Programme { } pub struct Bloc { - condition: Vec, - contenu: Vec, + pub condition: Vec, + pub contenu: Vec, } impl Bloc {