Skip to content

Commit 2947e8b

Browse files
committed
FEAT: print a human friendly list of available codecs on help codecs
1 parent 9ce9d9a commit 2947e8b

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

src/mezz/mezz-help.reb

+56
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ import module [
4747
? function!
4848
? datatype!
4949
^[[m
50+
^[[4;1;36mTo see all available codecs^[[m:
51+
^[[1;32m
52+
? codecs
53+
^[[m
5054
^[[4;1;36mOther debug functions^[[m:
5155
5256
^[[1;32m??^[[m - display a variable and its value
@@ -197,6 +201,16 @@ import module [
197201
word? :word [
198202
either value? :word [
199203
value: get :word ;lookup for word's value if any
204+
if :word = 'codecs [
205+
list-codecs :word
206+
if same? :value system/codecs [throw true]
207+
output lf
208+
if any-function? :value [
209+
; don't display help in case that user redefined `codecs` with a function
210+
output ajoin ["^[[1;32m" uppercase mold word "^[[m is " form-type :value ".^[[m"]
211+
throw true
212+
]
213+
]
200214
][ word: mold :word ] ;or use it as a string input
201215
]
202216
string? :word [
@@ -364,6 +378,48 @@ import module [
364378
either into [buffer][print head buffer]
365379
]
366380

381+
list-codecs: function [][
382+
names: sort keys-of codecs: system/codecs
383+
foreach type common-types: [
384+
time
385+
text
386+
cryptography
387+
compression
388+
sound
389+
image
390+
other
391+
][
392+
tmp: clear []
393+
foreach name names [
394+
codec: codecs/:name
395+
if any [
396+
type = codec/type
397+
all [type = 'other not find common-types codec/type]
398+
][
399+
append tmp codec
400+
]
401+
]
402+
if empty? tmp [continue]
403+
404+
output ajoin [{^[[4;1;36m} uppercase form type { CODECS^[[m:}]
405+
foreach codec tmp [
406+
output ajoin ["^/ ^[[4;1;33m" uppercase form codec/name "^[[m^/ ^[[1;32m" codec/title]
407+
if all [tmp: select codec 'suffixes not empty? tmp] [
408+
output ajoin ["^[[m^/ Suffixes: ^[[31m" codec/suffixes]
409+
]
410+
tmp: exclude keys-of codec [name type title entry suffixes]
411+
unless empty? tmp [
412+
output ajoin ["^[[m^/ Includes: ^[[35m" tmp]
413+
]
414+
output lf
415+
]
416+
output "^[[m^/^/"
417+
]
418+
output ajoin [
419+
"^[[1mTIP:^[[m use for example ^[[1;32mhelp system/codecs/" codec/name "^[[m to see more info.^/"
420+
]
421+
]
422+
367423
about: func [
368424
"Information about REBOL"
369425
][

0 commit comments

Comments
 (0)