DEV Community

Cover image for A holiday gift: "inspect" dialog for Mini Micro
JoeStrout
JoeStrout

Posted on

A holiday gift: "inspect" dialog for Mini Micro

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!

Inspector demo animation

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:

  1. Download inspectDialog.ms and save it in your user disk, under a folder called "lib" (i.e., save it as /usr/lib/inspectDialog).

  2. 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
Enter fullscreen mode Exit fullscreen mode

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.

  1. 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.

Animation of inspect dialog on Advent of Code data

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)