forked from thenomain/Mu--Support-Systems
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vcolumns.txt
190 lines (143 loc) · 6.08 KB
/
vcolumns.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"Vertical columns" takes up to nine items and turns them into horizontal columns.
================================================================================
== Not Really Vcolumns() =======================================================
vcolumns( <width>:<text 1>, <width>:<text 2> .. , <width>:<text n>[, <divider>[, <left>[, <right>]]] )
0 - 9: width:text, the last three might be divider, left, right
q0 - q9: texts, as correspoinding to input register
c: total number of columns
h: height of the tallest column
e: error storage
z: random temp field
--
&f_vcolumns @@functions object@@=
@@ >> Num Columns
[iter(
lnum( 9 ),
if(
and( isint( before( v( %i0 ), : )), t( rest( v( %i0 ), : ))),
[setq( c, inc( %i0 ))]
@@ .. error-check the text while we're here
[if(
strmatch( v( %i0 ), *`* ),
setq( e, BACKTICK MAY NOT BE IN TEXT )
)]
), , @@
)]
@@ >> Error output
[case( 1,
t( %qe ), #-1 %qe,
@@ >> Wrap Columns to <width>:<line>`<line>`<line>, put in registers
[iter(
lnum( %qc ),
setq(
%i0,
[setr( z, before( v( %i0 ), : ))]:
[wrap( rest( v( %i0 ), : ), %qz, left, , , , ` )]
), , @@
)]
@@ >> Get Height
[iter( lnum( %qc ), setq( h, max( %qh, words( r( %i0 ), ` ))), , @@ )]
@@ >> Display Lines
[iter(
lnum( 1, %qh ),
@@ .. >> Display Columns on that line
@@ .. .. Left
[if( t( v( inc( %qc ))), v( inc( %qc )))]
@@ .. .. Center
[iter(
lnum( %qc ),
if(
t( setr( z, extract( rest( r( %i0 ), : ), inum( 1 ), 1, ` ))),
%qz,
space( first( r( %i0 ), : ))
), , v( %qc )
)]
@@ .. .. Right
[if( t( v( add( %qc, 2 ))), v( add( %qc, 2 )))],
, %r
)]
)]
--------------------------------------------------------------------------------
[ansi( h, vcolumns%(%))]: Parses up to nine inputs as vertical columns. Each item passed must be in the format of <width>:<text>. The next three items that do not are parsed as <divider text>, <left text>, and <right text> with all other inputs ignored. Example: vcolumns( 5:line of text, 10:another line of text, %%b|%%b, <%%b, %%b> )
--------------------------------------------------------------------------------
* This Isn't Columns! *
It's cool, it's fun, but it's a multi-column wrap function. Let's try this again.
================================================================================
== Vcolumns() attempt 2, the working one =======================================
vcolumns( <list1> <width1>, ..., <delim>, <divider>, <left>, <right> )
Due to limitations in Mu* code, the only way to separate <width> from <list> is with a pre-defined delimiter for this only. I'm sticking with :.
Max columns is 9, 8 if delim, 7 if divider, 6 if left, 5 if right.
--
input:
0-9: input, hopefully at least one columns
registers:
0-9: columns
d: delim
i: divider
l: left
r: right
c: number of columns
h: height
--
&f_vcolumns @@functions object@@=
@@ Num Columns
[iter(
lnum( 9 ),
if(
and( isint( before( v( %i0 ), : )), strmatch( v( %i0 ), *:* )),
setq( c, inc( %i0 ))
), , @@
)]
@@ Set Other Registers
@@ ( we set an empty delim to %b because wrap's defaults to %r )
[setq( d, if( t( comp( v( %qc ), )), v( %qc ), %b ))]
[setq( v, v( inc( %qc )))]
[setq( l, v( add( %qc, 2 )))]
[setq( r, v( add( %qc, 3 )))]
@@ Check each column's elements for wrap and enforce it ( <width>:<list> )
[iter(
lnum( %qc ),
@@ .. set 0-9 with the column, internal elements wrapped
setq( %i0,
[setr( w, first( v( %i0 ), : ))]:
[iter(
rest( v( %i0 ), : ),
wrap( %i0, %qw, left, , , , %qd ),
%qd,
%qd
)]
), , @@
)]
@@ Get Height ( <width>:<list> )
[iter( lnum( %qc ), setq( h, max( %qh, words( rest( r( %i0 ), : ), %qd ))), , @@ )]
@@ Display Lines
[iter(
lnum( 1, %qh ),
@@ .. >> Display Columns on that line
@@ .. .. Left
%ql
@@ .. .. Center
[iter(
lnum( %qc ),
if(
t( setr( z, extract( rest( r( %i0 ), : ), inum( 1 ), 1, %qd ))),
%qz,
space( first( r( %i0 ), : ))
), , %qv
)]
@@ .. .. Right
%qr,
, %r
)]
--------------------------------------------------------------------------------
-- Testing ---------------------------------------------------------------------
think [header( vcolumns test )]%r[u( @@functions object@@/f_vcolumns, 14:this is a really kind of annoying test bla bla bla, 10:help I am a small rodent!, `, %b|%b )]%r[footer( )]%r>>> columns ( qc ): %qc%r>>> height ( qh ): %qh%r>>> col 1 ( q0 ): %q0%r>>> col 2 ( q1 ): %q1%r[footer( vcolumns )]
think [header( vcolumns test )]%r[u( @@functions object@@/f_vcolumns, 14:this is a really kind of annoying test bla bla bla, 10:, `, %b|%b )]%r[footer( )]%r>>> columns ( qc ): %qc%r>>> height ( qh ): %qh%r>>> col 1 ( q0 ): %q0%r>>> col 2 ( q1 ): %q1%r[footer( vcolumns )]
think [header( vcolumns test )]%r[vcolumns( 14:this is a really kind of annoying test bla bla bla, 10:%b, `, %b|%b )]%r[footer( vcolumns )]
think [header( vcolumns test )]%r[vcolumns( 14:this is a really kind of annoying test bla bla bla, 10:help I am a small rodent!, `, %b|%b )]%r[footer( vcolumns )]
think [header( vcolumns test )]%r[vcolumns( 14:this is a really kind of annoying test bla bla bla, 10:help%rI%ram%ra%rsmall%rrodent!, `, %b|%b )]%r[footer( vcolumns )]
================================================================================
== COMPILED VERSION ============================================================
Since this is probably what you came here for.
--
&f_vcolumns @@functions object@@=[iter( lnum( 9 ), if( and( isint( before( v( %i0 ), : )), strmatch( v( %i0 ), *:* )), setq( c, inc( %i0 )) ), , @@ )][setq( d, if( t( comp( v( %qc ), )), v( %qc ), %b ))][setq( v, v( inc( %qc )))][setq( l, v( add( %qc, 2 )))][setq( r, v( add( %qc, 3 )))][iter( lnum( %qc ), setq( %i0, [setr( w, first( v( %i0 ), : ))]:[iter( rest( v( %i0 ), : ), wrap( %i0, %qw, left, , , , %qd ), %qd, %qd )] ), , @@ )][iter( lnum( %qc ), setq( h, max( %qh, words( rest( r( %i0 ), : ), %qd ))), , @@ )][iter( lnum( 1, %qh ), %ql[iter( lnum( %qc ), if( t( setr( z, extract( rest( r( %i0 ), : ), inum( 1 ), 1, %qd ))), %qz, space( first( r( %i0 ), : )) ), , %qv )]%qr, , %r )]