From 11302a6463701de46fb668cc88b69d6eef28f120 Mon Sep 17 00:00:00 2001 From: Kai Schmidt Date: Tue, 19 Dec 2023 12:57:59 -0800 Subject: [PATCH] change how some empty arrays are shown --- src/array.rs | 7 +++++++ src/grid_fmt.rs | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/array.rs b/src/array.rs index de1d33dc5..2c8a3b961 100644 --- a/src/array.rs +++ b/src/array.rs @@ -431,6 +431,8 @@ impl FromIterator for Array { pub trait ArrayValue: Clone + Debug + Display + GridFmt + ArrayCmp + Send + Sync + 'static { /// The type name const NAME: &'static str; + /// A glyph indicating the type + const SYMBOL: char; /// Get the fill value from the environment fn get_fill(env: &Uiua) -> Result; /// Hash the value @@ -449,6 +451,7 @@ pub trait ArrayValue: Clone + Debug + Display + GridFmt + ArrayCmp + Send + Sync impl ArrayValue for f64 { const NAME: &'static str = "number"; + const SYMBOL: char = 'ℝ'; fn get_fill(env: &Uiua) -> Result { env.num_fill() } @@ -469,6 +472,7 @@ impl ArrayValue for f64 { impl ArrayValue for u8 { const NAME: &'static str = "number"; + const SYMBOL: char = 'ℝ'; fn get_fill(env: &Uiua) -> Result { env.byte_fill() } @@ -482,6 +486,7 @@ impl ArrayValue for u8 { impl ArrayValue for char { const NAME: &'static str = "character"; + const SYMBOL: char = '@'; fn get_fill(env: &Uiua) -> Result { env.char_fill() } @@ -501,6 +506,7 @@ impl ArrayValue for char { impl ArrayValue for Boxed { const NAME: &'static str = "box"; + const SYMBOL: char = '□'; fn get_fill(env: &Uiua) -> Result { env.box_fill() } @@ -514,6 +520,7 @@ impl ArrayValue for Boxed { impl ArrayValue for Complex { const NAME: &'static str = "complex"; + const SYMBOL: char = 'ℂ'; fn get_fill(env: &Uiua) -> Result { env.complex_fill() } diff --git a/src/grid_fmt.rs b/src/grid_fmt.rs index 70eb798ea..c6bbc08f0 100644 --- a/src/grid_fmt.rs +++ b/src/grid_fmt.rs @@ -142,6 +142,7 @@ impl GridFmt for Array { } let stringy = type_name::() == type_name::(); let boxy = type_name::() == type_name::(); + let complexy = type_name::() == type_name::(); if *self.shape == [0] { return if stringy { if boxed { @@ -153,6 +154,8 @@ impl GridFmt for Array { let (left, right) = if boxed { ('⟦', '⟧') } else { ('[', ']') }; if boxy { vec![vec![left, '□', right]] + } else if complexy { + vec![vec![left, 'ℂ', right]] } else { vec![vec![left, right]] } @@ -252,12 +255,12 @@ fn fmt_array( let mut shape_row = Vec::new(); for (i, dim) in shape.iter().enumerate() { if i > 0 { - shape_row.extend(" × ".chars()); + shape_row.extend("×".chars()); } shape_row.extend(dim.to_string().chars()); } shape_row.push(' '); - shape_row.extend(T::NAME.chars()); + shape_row.push(T::SYMBOL); metagrid.push(vec![vec![shape_row]]); return; }