Skip to content

Commit

Permalink
change how some empty arrays are shown
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Dec 19, 2023
1 parent 93aea50 commit 11302a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ impl FromIterator<String> for Array<Boxed> {
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<Self, &'static str>;
/// Hash the value
Expand All @@ -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<Self, &'static str> {
env.num_fill()
}
Expand All @@ -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<Self, &'static str> {
env.byte_fill()
}
Expand All @@ -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<Self, &'static str> {
env.char_fill()
}
Expand All @@ -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<Self, &'static str> {
env.box_fill()
}
Expand All @@ -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<Self, &'static str> {
env.complex_fill()
}
Expand Down
7 changes: 5 additions & 2 deletions src/grid_fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl<T: GridFmt + ArrayValue> GridFmt for Array<T> {
}
let stringy = type_name::<T>() == type_name::<char>();
let boxy = type_name::<T>() == type_name::<Boxed>();
let complexy = type_name::<T>() == type_name::<Complex>();
if *self.shape == [0] {
return if stringy {
if boxed {
Expand All @@ -153,6 +154,8 @@ impl<T: GridFmt + ArrayValue> GridFmt for Array<T> {
let (left, right) = if boxed { ('⟦', '⟧') } else { ('[', ']') };
if boxy {
vec![vec![left, '□', right]]
} else if complexy {
vec![vec![left, 'ℂ', right]]
} else {
vec![vec![left, right]]
}
Expand Down Expand Up @@ -252,12 +255,12 @@ fn fmt_array<T: GridFmt + ArrayValue>(
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;
}
Expand Down

0 comments on commit 11302a6

Please sign in to comment.