I was delighted by a pleasant surprise this week, when MiniScript user Marc Gurevitx posted a utility he wrote for Mini Micro called InspectDialog.
What this does is provide an "inspector" for MiniScript values, allowing you to explore complex data structures with ease!
The code is nice and clean, and based on the textUtil.Dialog class in /sys/lib/textUtil. Much like findFile, Marc's new InspectDialog can be used from code, or you can use it interactively on the command line.
Installation
To open this delightful holiday present in your own Mini Micro, just follow these steps:
Download inspectDialog.ms and save it in your user disk, under a folder called "lib" (i.e., save it as /usr/lib/inspectDialog).
edit /usr/startup.ms and add this code:
import "inspectDialog"
inspect = function(value)
dlog = inspectDialog.InspectDialog.make(@value)
btn = dlog.show
return @btn.payload
end function
_savedGlobals.inspectDialog = inspectDialog
_savedGlobals.inspect = @inspect
This imports the inspectDialog module, and then adds an inspect
command for easy use. It also stuffs both of these into the _savedGlobals
map, so that they don't disappear every time you do a reset
.
-
reboot
Mini Micro.
That's it! Now you'll have an inspect
command you can use anywhere.
Usage
Just type inspect
followed by the name of some variable you're curious about. The inspect dialog will snap open. Using the mouse or keyboard, navigate your data structure, pressing Return
(or clicking the Inspect button) to drill down to sub-values, or b
(or clicking Back) to go back up. To exit the dialog, you can always press Esc
, which will return the value of the variable you were inspecting; or if you have drilled down, you can also press c
(Current) to return the value you're currently inspecting instead.
The image above shows me inspecting some data from today's Advent of Code challenge. I always used to use pprint
for this sort of thing, and then wade through page after page of output looking for the data I needed. No more! From now on, it's inspect for me!
Thank you, Marc!
Top comments (0)