aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-02 20:37:08 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-10-02 21:01:23 -0400
commitf6a7c636f8187a8e324901e6671d04c759d5e4c7 (patch)
treedacba2c5c453b241c72bf341627791b4f0461bf0 /src
parent62fd9972759daeb5fd313b634fb3a27425acbdbe (diff)
Simplify vertical padding when formatting
Diffstat (limited to 'src')
-rw-r--r--src/fmt.bqn12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/fmt.bqn b/src/fmt.bqn
index def46f58..61bd8639 100644
--- a/src/fmt.bqn
+++ b/src/fmt.bqn
@@ -1,7 +1,7 @@
# Format an array to a string including newlines
{
- F0←𝔽 # Function to format an atom
- FmtAtom ← (≍ <⟜@β—ΆβŸ¨@βŠΈβ‰ β—ΆβŸ¨"@","'"⊸(∾∾⊣)⟩,F0⟩)
+ F0←𝔽 # Format a number or operation to a string
+ FmtAtom ← ≍ <⟜@β—ΆβŸ¨@βŠΈβ‰ β—ΆβŸ¨"@","'"⊸(∾∾⊣)⟩,F0⟩
# Vertical padding for arrays of rank greater than 2
PadV ← {
@@ -12,8 +12,10 @@
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βŠ‘β‰’π•©) β₯Š 𝕩
+ # If 𝕩 has cells, pad by selection; if it's empty, there are only
+ # pads but selection would try to get cells (1⌈ above), so overtake.
+ Pad ← {(»⊸<βŠΈΓ—/0∾1+𝕨) ⊏ ' 'Β¨βˆ˜βŠβŠΈβˆΎπ•©}
+ p (0<β‰ βˆ˜βŠ’)β—ΆβŸ¨+Β΄βŠΈβ†‘,Pad⟩ ((Γ—Β΄ls)∾¯1↑≒𝕩) β₯Š 𝕩
}⍟(2 < =)
# Horizontal padding: just some spaces on either side
@@ -30,7 +32,7 @@
l ← Β―1 βŠ‘ ≒𝕩
∾ ⟨
≍lβ†‘βˆΎβŸ¨"β”Œ",(5⊸<)β—ΆβŸ¨β₯Š"·─"⊏˜1⌊⊒,F0βŸ©π•¨βŸ©
- ((4⌊0βŒˆπ•¨-1)βŠ‘"Β·β•΅β•Žβ”†β”Š")βŒΎβŠ‘ 𝕩
+ ((0⌈4βŒŠπ•¨-1)βŠ‘"Β·β•΅β•Žβ”†β”Š")βŒΎβŠ‘ 𝕩
≍l-βŠΈβ†‘"β”˜"
⟩
}