diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-08-25 10:22:55 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2020-08-25 10:22:55 -0400 |
| commit | 32c7ecd7326f05673d0f3ff751ae4e4bc43f36cb (patch) | |
| tree | 4894c62319602a56ee6260b62b118e28cdfc5e5d /md.bqn | |
| parent | 0d287cb8d4c3253618136cbd5631bc6f534c4c55 (diff) | |
Include fmt.bqn from md.bqn instead of duplicating the code
Diffstat (limited to 'md.bqn')
| -rw-r--r-- | md.bqn | 62 |
1 files changed, 2 insertions, 60 deletions
@@ -545,66 +545,8 @@ GetMultiHighlights ← { ################################ # Format an array to a character matrix # Won't work on functions until we can catch errors -Fmt ← { - # Vertical padding for arrays of rank greater than 2 - PadV ← { - # Leading shape - ls ← ¯1↓≢𝕩 - # Empty lines after each row: 1 if it's at the end of a 2-cell, plus - # 1 if it's at the end of a 2-cell and a 3-cell, and so on - p ← ⥊ +⎉¯1‿∞´ ×⌜˜`⌾⌽ (-1⌈ls)↑¨1 - # But none at the very end - p ↩ 0⌾(¯1⊸⊑) p - Pad ← {i←/1+𝕨 ⋄ (¯1¨⌾((¬∊i)⊸/)i) ⊏ 𝕩∾(¯1⊑≢𝕩)⥊" "} - p (⊑0∊ls)◶⟨Pad,+´⊸↑⟩ ((×´ls)∾¯1⊑≢𝕩) ⥊ 𝕩 - }⍟(2 < =) - # Horizontal padding: just some spaces on either side - PadH ← { - (𝕨/" ") (∾⎉1∾⎉1⊣) 𝕩 - } - Pad ← PadH⟜PadV - Enframe ← {(1≠𝕨)∨(1≠≠𝕩)∨⊑2∊+`-˝"⟨⟩"=⌜⊏𝕩}◶{ - ≍"⟨"∾(¯1↓1↓⊏𝕩)∾"⟩" - }‿{ - l ← ¯1 ⊑ ≢𝕩 - ∾ ⟨ # "┼╒╛╪" - 1‿l↑∾⟨"┌",(5⊸<)◶⟨⥊"·─"⊏˜1⌊⊢,⍕⟩𝕨⟩ - ((4⌊0⌈𝕨-1)⊑"·╵╎┆┊")⌾⊑ 𝕩 - (1∾-l)↑"┘" - ⟩ - } - FmtEmpty ← (0‿0≢≢)◶("┌┐"≍"└┘")‿(((2≠=)∨0=≠)◶{ - '┐'⌾(0‿¯1⊸⊑) 2 Enframe 1 PadH " "¨𝕩 - }‿{ - ≍"⟨⟩"∾˜(1<≠)◶⟨"",'⥊'⌾(¯1⊸⊑)·∾·∾⟜"‿"¨⍕¨⟩≢𝕩 - }) - PaddingJoin ← {1𝕊𝕩; - s ← ≢¨ 𝕩 - w ← ⌈˝⍟(=-1˜)1⊑¨s - h ← ⌈˝⎉1 ⊑¨s - ∾⎉2 ≍⍟(0⌈2-=) (h ∾⌜ 𝕨×w¬(-𝕨×≠w)↑1) ↑¨ 𝕩 - } - FmtMixed ← { - (=𝕩) Enframe 2 Pad 𝕨 PaddingJoin F¨𝕩 - } - F ← (2⌊≡)◶(≍≤⟜∞◶⟨"'"⊸(∾∾⊣),⍕⟩)‿{ - num ← 𝕩≤∞ ⋄ r ← =𝕩 - ((≠(0⊸<+≤)+´)⥊num)◶{ - # All characters - k ← -≠ c ← ¯1↓≢𝕩 - q ← '"' - 𝕩 ↩ (1+q=⊢)⊸/⍟(k=0) 𝕩 - (r Enframe 1 PadH PadV)⍟(1≠r) ≍ (c↑q) ∾⎉k 𝕩 ∾⎉k ⌽⌾⥊c↑q - }‿{ - # Not homogeneous, or empty - (∨´0=≢)◶FmtMixed‿FmtEmpty 𝕩 - }‿{ - # All numbers - ¯1 FmtMixed 𝕩 - } 𝕩 - }‿FmtMixed - F 𝕩 -} +fmtm ← ⟨•path∾"src/fmt.bqn"⟩ •EX •path∾"dzref" +Fmt ← ⍕ _fmtm ################################ |
