March Docs

ScrollInput

lib/scroll/scroll_input.march — Controls whose value a cell reads.

import ScrollInput

let model = ScrollInput.select("Model", ["Weekly naive", "Chronos-2 Small"], "Chronos-2 Small")
let last_lead = ScrollInput.slider("Last lead (hours)", 1, 24, 24)

Each call shows a control in the cell's output and returns the control's current value (the default until someone changes it). Changing the control re-runs this cell and the cells that use what it defines, and nothing else, so data loaded earlier is not loaded again.

The notebook keeps the values in a JSON file, {"<label>": <value>, ...}, named by SCROLL_INPUTS in the REPL's environment; outside Scroll every call returns its default. A control's label is its key, so two controls in one notebook need different labels.

Each call prints one __SCROLL_BLOB__ block of type application/vnd.scroll.input+json: {"label":"Model","kind":"select","options":["a","b"],"value":"b"} (slider adds min/max/step, number adds step).

Functions

fncheckboxcheckbox(label : String, default : Bool) : Bool#

A checkbox. Returns whether it is ticked.

fnmake_sentinelmake_sentinel(spec : JsonValue) : String#

The sentinel block that displays a control (for tests and composition).

fnmimemime() : String do "application/vnd.scroll.input+json" end#

The MIME type the notebook renders as a control.

fnnumbernumber(label : String, default : Float) : Float#

A number field. Returns the entered number.

fnselectselect(label : String, options : List(String), default : String) : String#

A drop-down of options. Returns the chosen option, or default when nothing valid is stored.

fnsliderslider(label : String, min : Int, max : Int, default : Int) : Int#

A slider over the integers min..max (inclusive). Returns the chosen value.

fnstoredstored(label : String) : Option(JsonValue)#

The stored value for label, if the notebook has one.

fntexttext(label : String, default : String) : String#

A one-line text field. Returns the entered text.