From 53a3936901e06320be0c118a0841cafc93591cca Mon Sep 17 00:00:00 2001 From: sudoPom <72107751+sudoPom@users.noreply.github.com> Date: Sun, 10 Apr 2022 00:46:01 +0100 Subject: [PATCH 1/6] Fix: Literal colours changed Literals will be the same colour as the user's terminal's directories. --- modus-lib/Cargo.toml | 1 + modus-lib/src/sld.rs | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/modus-lib/Cargo.toml b/modus-lib/Cargo.toml index 9ec82c3..bc68113 100644 --- a/modus-lib/Cargo.toml +++ b/modus-lib/Cargo.toml @@ -20,6 +20,7 @@ nom_locate = "4.0.0" # for the span nom-supreme = "0.6.0" # for the TagError and ErrorTree codespan-reporting = "0.11.1" colored = "2" +lscolors = "0.9.0" lazy_static = "1.4.0" fp-core = "0.1.9" dot = "0.1.4" # graphviz library diff --git a/modus-lib/src/sld.rs b/modus-lib/src/sld.rs index dff436f..391d2be 100644 --- a/modus-lib/src/sld.rs +++ b/modus-lib/src/sld.rs @@ -36,6 +36,7 @@ use crate::{ }; use codespan_reporting::diagnostic::{Diagnostic, Label, Severity}; use colored::Colorize; +use lscolors::{LsColors, Style}; use logic::{Clause, IRTerm, Literal}; use ptree::{item::StringItem, print_tree, TreeBuilder, TreeItem}; @@ -447,7 +448,11 @@ impl Proof { let mut prev_scope_start_index = 0; let mut prev_scope_end_index = 0; let mut dont_close: HashSet = HashSet::new(); - + let colors = LsColors::from_env().unwrap_or_default(); + let dir_style = colors.style_for_indicator(lscolors::Indicator::Directory); + let normal_style = colors.style_for_indicator(lscolors::Indicator::Normal); + let dir_ansi = dir_style.map(Style::to_ansi_term_style).unwrap_or_default(); + let normal_ansi = normal_style.map(Style::to_ansi_term_style).unwrap_or_default(); for (i, child) in p.children.iter().enumerate() { match &child.clause { ClauseId::Rule(rid) => { @@ -458,9 +463,9 @@ impl Proof { if pred_kind.get(&clauses[*rid].head.predicate) == Some(&analysis::Kind::Image) { - s.cyan() + dir_ansi.paint(s) } else { - s.normal() + normal_ansi.paint(s) }, )); } @@ -476,7 +481,7 @@ impl Proof { crate::analysis::Kind::Image => { builder.add_empty_child(format!( "{}", - b.substitute(&child.valuation).to_string().cyan() + dir_ansi.paint(b.substitute(&child.valuation).to_string()) )); } crate::analysis::Kind::Layer => { From 75bc0d0d2a5b9bc7a157ea50b244a7621cd9cfeb Mon Sep 17 00:00:00 2001 From: sudoPom <72107751+sudoPom@users.noreply.github.com> Date: Tue, 12 Apr 2022 16:41:36 +0100 Subject: [PATCH 2/6] Fix: Moved colour determination into a seperate fn --- modus-lib/src/sld.rs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/modus-lib/src/sld.rs b/modus-lib/src/sld.rs index 391d2be..07c2886 100644 --- a/modus-lib/src/sld.rs +++ b/modus-lib/src/sld.rs @@ -448,11 +448,8 @@ impl Proof { let mut prev_scope_start_index = 0; let mut prev_scope_end_index = 0; let mut dont_close: HashSet = HashSet::new(); - let colors = LsColors::from_env().unwrap_or_default(); - let dir_style = colors.style_for_indicator(lscolors::Indicator::Directory); - let normal_style = colors.style_for_indicator(lscolors::Indicator::Normal); - let dir_ansi = dir_style.map(Style::to_ansi_term_style).unwrap_or_default(); - let normal_ansi = normal_style.map(Style::to_ansi_term_style).unwrap_or_default(); + let dir_style = Proof::get_color("Directory"); + let normal_style = Proof::get_color("Normal"); for (i, child) in p.children.iter().enumerate() { match &child.clause { ClauseId::Rule(rid) => { @@ -463,9 +460,9 @@ impl Proof { if pred_kind.get(&clauses[*rid].head.predicate) == Some(&analysis::Kind::Image) { - dir_ansi.paint(s) + dir_style.paint(s) } else { - normal_ansi.paint(s) + normal_style.paint(s) }, )); } @@ -481,7 +478,7 @@ impl Proof { crate::analysis::Kind::Image => { builder.add_empty_child(format!( "{}", - dir_ansi.paint(b.substitute(&child.valuation).to_string()) + dir_style.paint(b.substitute(&child.valuation).to_string()) )); } crate::analysis::Kind::Layer => { @@ -535,6 +532,17 @@ impl Proof { builder.build() } + fn get_color(color_of: &str) -> ansi_term::Style{ + let colors = LsColors::from_env().unwrap_or_default(); + let mut style: std::option::Option<&lscolors::Style>; + match color_of{ + "Directory" => style = colors.style_for_indicator(lscolors::Indicator::Directory), + "Normal" => style = colors.style_for_indicator(lscolors::Indicator::Normal), + _ => panic!("The only used LSColours are 'Directory' and 'Normal'") + }; + style.map(Style::to_ansi_term_style).unwrap_or_default() + } + pub fn pretty_print( &self, clauses: &Vec, From 5199e3acd8409a1ba3a1b02b53787ce9e5bf5f03 Mon Sep 17 00:00:00 2001 From: sudoPom <72107751+sudoPom@users.noreply.github.com> Date: Tue, 12 Apr 2022 16:42:01 +0100 Subject: [PATCH 3/6] Fix: Use ansi term for colouring --- modus-lib/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/modus-lib/Cargo.toml b/modus-lib/Cargo.toml index bc68113..e7c4319 100644 --- a/modus-lib/Cargo.toml +++ b/modus-lib/Cargo.toml @@ -21,6 +21,7 @@ nom-supreme = "0.6.0" # for the TagError and ErrorTree codespan-reporting = "0.11.1" colored = "2" lscolors = "0.9.0" +ansi_term = "*" lazy_static = "1.4.0" fp-core = "0.1.9" dot = "0.1.4" # graphviz library From 8790fb4335ec7c05dc67b06f9685699ef7c2c173 Mon Sep 17 00:00:00 2001 From: sudoPom <72107751+sudoPom@users.noreply.github.com> Date: Tue, 12 Apr 2022 17:24:42 +0100 Subject: [PATCH 4/6] Fix: Various fixes * Ansi term version * Itertools re added (whoops) --- modus-lib/Cargo.toml | 2 +- modus-lib/src/sld.rs | 40 ++++------------------------------------ 2 files changed, 5 insertions(+), 37 deletions(-) diff --git a/modus-lib/Cargo.toml b/modus-lib/Cargo.toml index e7c4319..fb2d3e4 100644 --- a/modus-lib/Cargo.toml +++ b/modus-lib/Cargo.toml @@ -21,7 +21,7 @@ nom-supreme = "0.6.0" # for the TagError and ErrorTree codespan-reporting = "0.11.1" colored = "2" lscolors = "0.9.0" -ansi_term = "*" +ansi_term = "0.12" lazy_static = "1.4.0" fp-core = "0.1.9" dot = "0.1.4" # graphviz library diff --git a/modus-lib/src/sld.rs b/modus-lib/src/sld.rs index 7d5017e..d585aab 100644 --- a/modus-lib/src/sld.rs +++ b/modus-lib/src/sld.rs @@ -37,6 +37,7 @@ use crate::{ use codespan_reporting::diagnostic::{Diagnostic, Label, Severity}; use colored::Colorize; use lscolors::{LsColors, Style}; +use itertools::Itertools; use logic::{Clause, IRTerm, Literal}; use ptree::{item::StringItem, print_tree, TreeBuilder, TreeItem}; @@ -253,8 +254,7 @@ impl Tree { + &xs.join(&("\n".to_owned() + &" ".repeat(depth * 3) + &"- ")) } else { "".to_string() - } - .bright_red() + }.bright_red() )); } else { let mut resolvent_pairs = t.resolvents().into_iter().collect::>(); @@ -613,8 +613,8 @@ impl fmt::Display for ResolutionError { ResolutionError::MaximumDepthExceeded(_, max_depth) => { write!(f, "exceeded maximum depth of {}", max_depth) } - ResolutionError::BuiltinFailure(l, builtin_name) => { - write!(f, "builtin {builtin_name} failed to apply or unify: {l}") + ResolutionError::BuiltinFailure(_, builtin_name) => { + write!(f, "builtin {} failed to apply or unify", builtin_name) } ResolutionError::InsufficientRules(literal) => write!( f, @@ -721,36 +721,6 @@ impl ResolutionError { .with_labels(labels) .with_notes(notes) } - - /// Returns a normalized version of a resolution error --- should be better for hash equality. - /// Without this, may get a lot of resolution errors, for example, that are identical except for a different - /// auxiliary variable index. - fn normalize(self) -> ResolutionError { - match self { - ResolutionError::UnknownPredicate(l) => { - ResolutionError::UnknownPredicate(l.normalized_terms()) - } - ResolutionError::InsufficientGroundness(ls) => ResolutionError::InsufficientGroundness( - ls.into_iter().map(|x| x.normalized_terms()).collect(), - ), - ResolutionError::MaximumDepthExceeded(ls, s) => ResolutionError::MaximumDepthExceeded( - ls.into_iter().map(|x| x.normalized_terms()).collect(), - s, - ), - ResolutionError::BuiltinFailure(l, s) => { - ResolutionError::BuiltinFailure(l.normalized_terms(), s) - } - ResolutionError::InsufficientRules(l) => { - ResolutionError::InsufficientRules(l.normalized_terms()) - } - ResolutionError::InconsistentGroundnessSignature(sigs) => { - ResolutionError::InconsistentGroundnessSignature(sigs.to_vec()) - } - ResolutionError::NegationProof(l) => { - ResolutionError::NegationProof(l.normalized_terms()) - } - } - } } /// Result of building the SLD tree. @@ -770,8 +740,6 @@ impl From for Result>> { Err(sld_result .errors .into_iter() - .map(ResolutionError::normalize) - .unique() .map(ResolutionError::get_diagnostic) .collect::>()) } From 52378ec42a94ced870c884fb9a834d34b380313d Mon Sep 17 00:00:00 2001 From: sudoPom <72107751+sudoPom@users.noreply.github.com> Date: Thu, 14 Apr 2022 13:57:45 +0100 Subject: [PATCH 5/6] Fic: Any LS Colour can now be used --- modus-lib/src/sld.rs | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/modus-lib/src/sld.rs b/modus-lib/src/sld.rs index d585aab..0ef19c6 100644 --- a/modus-lib/src/sld.rs +++ b/modus-lib/src/sld.rs @@ -449,8 +449,8 @@ impl Proof { let mut prev_scope_start_index = 0; let mut prev_scope_end_index = 0; let mut dont_close: HashSet = HashSet::new(); - let dir_style = Proof::get_color("Directory"); - let normal_style = Proof::get_color("Normal"); + let literal_style = Proof::get_color("di"); + let normal_style = Proof::get_color("no"); for (i, child) in p.children.iter().enumerate() { match &child.clause { ClauseId::Rule(rid) => { @@ -461,7 +461,7 @@ impl Proof { if pred_kind.get(&clauses[*rid].head.predicate) == Some(&analysis::Kind::Image) { - dir_style.paint(s) + literal_style.paint(s) } else { normal_style.paint(s) }, @@ -479,7 +479,7 @@ impl Proof { crate::analysis::Kind::Image => { builder.add_empty_child(format!( "{}", - dir_style.paint(b.substitute(&child.valuation).to_string()) + literal_style.paint(b.substitute(&child.valuation).to_string()) )); } crate::analysis::Kind::Layer => { @@ -537,9 +537,30 @@ impl Proof { let colors = LsColors::from_env().unwrap_or_default(); let mut style: std::option::Option<&lscolors::Style>; match color_of{ - "Directory" => style = colors.style_for_indicator(lscolors::Indicator::Directory), - "Normal" => style = colors.style_for_indicator(lscolors::Indicator::Normal), - _ => panic!("The only used LSColours are 'Directory' and 'Normal'") + "Directory" | "di" => style = colors.style_for_indicator(lscolors::Indicator::Directory), + "Normal" | "no" => style = colors.style_for_indicator(lscolors::Indicator::Normal), + "RegularFile" | "fi" => style = colors.style_for_indicator(lscolors::Indicator::RegularFile), + "SymbolicLink" | "ln" => style = colors.style_for_indicator(lscolors::Indicator::SymbolicLink), + "FIFO" | "pi" => style = colors.style_for_indicator(lscolors::Indicator::FIFO), + "Door" | "do" => style = colors.style_for_indicator(lscolors::Indicator::Door), + "BlockDevice" | "bd" => style = colors.style_for_indicator(lscolors::Indicator::BlockDevice), + "CharacterDevice" | "cd" => style = colors.style_for_indicator(lscolors::Indicator::CharacterDevice), + "OrphanedSymbolicLink" | "or" => style = colors.style_for_indicator(lscolors::Indicator::OrphanedSymbolicLink), + "Setuid" | "su" => style = colors.style_for_indicator(lscolors::Indicator::Setuid), + "Setgid" | "sg" => style = colors.style_for_indicator(lscolors::Indicator::Setgid), + "Sticky" | "st" => style = colors.style_for_indicator(lscolors::Indicator::Sticky), + "OtherWritable" | "ow" => style = colors.style_for_indicator(lscolors::Indicator::OtherWritable), + "StickyAndOtherWritable" | "tw" => style = colors.style_for_indicator(lscolors::Indicator::StickyAndOtherWritable), + "Socket" | "ex" => style = colors.style_for_indicator(lscolors::Indicator::Socket), + "MissingFile" | "mi" => style = colors.style_for_indicator(lscolors::Indicator::MissingFile), + "Capabilities" | "ca" => style = colors.style_for_indicator(lscolors::Indicator::Capabilities), + "MultipleHardLinks" | "mh" => style = colors.style_for_indicator(lscolors::Indicator::MultipleHardLinks), + "LeftCode" | "lc" => style = colors.style_for_indicator(lscolors::Indicator::LeftCode), + "RightCode" | "rc" => style = colors.style_for_indicator(lscolors::Indicator::RightCode), + "EndCode" | "ec" => style = colors.style_for_indicator(lscolors::Indicator::EndCode), + "Reset" | "rs" => style = colors.style_for_indicator(lscolors::Indicator::Reset), + "ClearLine" | "cl" => style = colors.style_for_indicator(lscolors::Indicator::ClearLine), + _ => style = colors.style_for_indicator(lscolors::Indicator::Normal) }; style.map(Style::to_ansi_term_style).unwrap_or_default() } From c6fd08241187a27005cba62c8ef625169a8c98c0 Mon Sep 17 00:00:00 2001 From: sudoPom <72107751+sudoPom@users.noreply.github.com> Date: Thu, 14 Apr 2022 14:06:14 +0100 Subject: [PATCH 6/6] Fix: Changed name of colour mappings. --- modus-lib/src/sld.rs | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/modus-lib/src/sld.rs b/modus-lib/src/sld.rs index 0ef19c6..32de488 100644 --- a/modus-lib/src/sld.rs +++ b/modus-lib/src/sld.rs @@ -449,8 +449,8 @@ impl Proof { let mut prev_scope_start_index = 0; let mut prev_scope_end_index = 0; let mut dont_close: HashSet = HashSet::new(); - let literal_style = Proof::get_color("di"); - let normal_style = Proof::get_color("no"); + let literal_style = Proof::get_color("ImagePred"); + let normal_style = Proof::get_color("Normal"); for (i, child) in p.children.iter().enumerate() { match &child.clause { ClauseId::Rule(rid) => { @@ -537,29 +537,8 @@ impl Proof { let colors = LsColors::from_env().unwrap_or_default(); let mut style: std::option::Option<&lscolors::Style>; match color_of{ - "Directory" | "di" => style = colors.style_for_indicator(lscolors::Indicator::Directory), - "Normal" | "no" => style = colors.style_for_indicator(lscolors::Indicator::Normal), - "RegularFile" | "fi" => style = colors.style_for_indicator(lscolors::Indicator::RegularFile), - "SymbolicLink" | "ln" => style = colors.style_for_indicator(lscolors::Indicator::SymbolicLink), - "FIFO" | "pi" => style = colors.style_for_indicator(lscolors::Indicator::FIFO), - "Door" | "do" => style = colors.style_for_indicator(lscolors::Indicator::Door), - "BlockDevice" | "bd" => style = colors.style_for_indicator(lscolors::Indicator::BlockDevice), - "CharacterDevice" | "cd" => style = colors.style_for_indicator(lscolors::Indicator::CharacterDevice), - "OrphanedSymbolicLink" | "or" => style = colors.style_for_indicator(lscolors::Indicator::OrphanedSymbolicLink), - "Setuid" | "su" => style = colors.style_for_indicator(lscolors::Indicator::Setuid), - "Setgid" | "sg" => style = colors.style_for_indicator(lscolors::Indicator::Setgid), - "Sticky" | "st" => style = colors.style_for_indicator(lscolors::Indicator::Sticky), - "OtherWritable" | "ow" => style = colors.style_for_indicator(lscolors::Indicator::OtherWritable), - "StickyAndOtherWritable" | "tw" => style = colors.style_for_indicator(lscolors::Indicator::StickyAndOtherWritable), - "Socket" | "ex" => style = colors.style_for_indicator(lscolors::Indicator::Socket), - "MissingFile" | "mi" => style = colors.style_for_indicator(lscolors::Indicator::MissingFile), - "Capabilities" | "ca" => style = colors.style_for_indicator(lscolors::Indicator::Capabilities), - "MultipleHardLinks" | "mh" => style = colors.style_for_indicator(lscolors::Indicator::MultipleHardLinks), - "LeftCode" | "lc" => style = colors.style_for_indicator(lscolors::Indicator::LeftCode), - "RightCode" | "rc" => style = colors.style_for_indicator(lscolors::Indicator::RightCode), - "EndCode" | "ec" => style = colors.style_for_indicator(lscolors::Indicator::EndCode), - "Reset" | "rs" => style = colors.style_for_indicator(lscolors::Indicator::Reset), - "ClearLine" | "cl" => style = colors.style_for_indicator(lscolors::Indicator::ClearLine), + "ImagePred" => style = colors.style_for_indicator(lscolors::Indicator::Directory), + "Normal" => style = colors.style_for_indicator(lscolors::Indicator::Normal), _ => style = colors.style_for_indicator(lscolors::Indicator::Normal) }; style.map(Style::to_ansi_term_style).unwrap_or_default()