From e674fd7e909c273c36952f01829544a2efc11c92 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Wed, 4 May 2022 22:14:57 +0200 Subject: New raw theme & nicer debug representation --- src/eval/func.rs | 10 ++++------ src/eval/value.rs | 22 +++++++++++----------- 2 files changed, 15 insertions(+), 17 deletions(-) (limited to 'src/eval') diff --git a/src/eval/func.rs b/src/eval/func.rs index 7e4040b6..b72e9f18 100644 --- a/src/eval/func.rs +++ b/src/eval/func.rs @@ -1,4 +1,4 @@ -use std::fmt::{self, Debug, Formatter, Write}; +use std::fmt::{self, Debug, Formatter}; use std::hash::{Hash, Hasher}; use std::sync::Arc; @@ -119,12 +119,10 @@ impl Func { impl Debug for Func { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - f.write_str(" f.write_str(name), + None => f.write_str("(..) => {..}"), } - f.write_char('>') } } diff --git a/src/eval/value.rs b/src/eval/value.rs index fc54cbce..b5607cfd 100644 --- a/src/eval/value.rs +++ b/src/eval/value.rs @@ -122,8 +122,9 @@ impl Value { Value::Content(v) => v, // For values which can't be shown "naturally", we return the raw - // representation. - v => Content::show(RawNode { text: v.repr(), block: false }), + // representation with typst code syntax highlighting. + v => Content::show(RawNode { text: v.repr(), block: false }) + .styled(RawNode::LANG, Some("typc".into())), } } } @@ -149,7 +150,7 @@ impl Debug for Value { Self::Fraction(v) => Debug::fmt(v, f), Self::Color(v) => Debug::fmt(v, f), Self::Str(v) => Debug::fmt(v, f), - Self::Content(_) => f.pad(""), + Self::Content(_) => f.pad("[...]"), Self::Array(v) => Debug::fmt(v, f), Self::Dict(v) => Debug::fmt(v, f), Self::Func(v) => Debug::fmt(v, f), @@ -720,7 +721,10 @@ mod tests { "30% + 56.69pt", ); test(Fraction::one() * 7.55, "7.55fr"); - test(Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), "#010101"); + test( + Color::Rgba(RgbaColor::new(1, 1, 1, 0xff)), + "rgb(\"#010101\")", + ); // Collections. test("hello", r#""hello""#); @@ -734,13 +738,9 @@ mod tests { test(dict!["one" => 1], "(one: 1)"); test(dict!["two" => false, "one" => 1], "(one: 1, two: false)"); - // Functions. - test( - Func::from_fn("nil", |_, _| Ok(Value::None)), - "", - ); - - // Dynamics. + // Functions, content and dynamics. + test(Content::Text("a".into()), "[...]"); + test(Func::from_fn("nil", |_, _| Ok(Value::None)), "nil"); test(Dynamic::new(1), "1"); } } -- cgit v1.2.3