Help us shape the future of Go! Take the 2026 Go Developer Survey

vm

package
v0.0.0-...-dd6fb2f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2026 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package vm is the ViewModel of the go-ndarray playground. It holds every piece of state the page shows or edits as a go-widgets/mvvm Observable, ObservableList or Command, and references no widget: the View binds to these, so the whole behaviour is unit-tested here without a canvas.

Index

Constants

View Source
const (
	LangGo = iota
	LangRuby
	LangNumPy
)

Code languages of the code panel, in tab order: Go | Ruby | NumPy.

Variables

This section is empty.

Functions

This section is empty.

Types

type ViewModel

type ViewModel struct {

	// OpNames and PresetNames are the fixed menus.
	OpNames     []string
	PresetNames []string

	// --- the form that builds the next step ---------------------------------
	OpIndex     *mvvm.Observable[int]
	Inputs      *mvvm.ObservableList[string] // steps whose result is an array
	InputIndex  *mvvm.Observable[int]
	Args        *mvvm.Observable[string]
	Hint        *mvvm.Observable[string]
	PresetIndex *mvvm.Observable[int]

	// --- the pipeline --------------------------------------------------------
	Steps    *mvvm.ObservableList[string] // one line per step
	Selected *mvvm.Observable[int]

	// --- the selected step ---------------------------------------------------
	Title  *mvvm.Observable[string]
	Shape  *mvvm.Observable[string]
	Memory *mvvm.Observable[string]
	Timing *mvvm.Observable[string]
	GoLine *mvvm.Observable[string]
	RbLine *mvvm.Observable[string]
	PyLine *mvvm.Observable[string]
	Grid   *mvvm.Observable[*engine.Grid] // nil when there is no step
	Note   *mvvm.Observable[string]

	// --- code panel ----------------------------------------------------------
	CodeLang *mvvm.Observable[int]
	Code     *mvvm.Observable[string]

	// --- Ruby: the program run in this browser by go-embedded-ruby ---------
	RubyOutput   *mvvm.Observable[string]  // what the last run printed, and its error
	RubyStatus   *mvvm.Observable[string]  // where Ruby is: not loaded, downloading, ready, ran
	RubyProgress *mvvm.Observable[float64] // the download, 0 to 1

	// --- messages ------------------------------------------------------------
	Error  *mvvm.Observable[string]
	Status *mvvm.Observable[string]

	// --- commands ------------------------------------------------------------
	Apply      *mvvm.Command
	RemoveLast *mvvm.Command
	Reset      *mvvm.Command
	LoadPreset *mvvm.Command
	CopyCode   *mvvm.Command
	RunRuby    *mvvm.Command

	// Clipboard receives the text CopyCode copies; the host installs it.
	Clipboard func(string)
	// Runtime describes where the code runs, for the status line; the
	// host fills it in. It defaults to the Go runtime's own view.
	Runtime string

	// RubyLoad downloads and starts the Ruby interpreter, reporting progress
	// in bytes (total 0 when unknown), then calls done with "" or an error.
	// It is asynchronous and called at most once. RubyEval runs a program on
	// the started interpreter and returns what it printed and its error ("" on
	// success). The host installs both; without them there is no Ruby.
	RubyLoad func(progress func(got, total int64), done func(err string))
	RubyEval func(src string) (output, err string)
	// contains filtered or unexported fields
}

ViewModel is the whole playground state.

func New

func New() *ViewModel

New builds the ViewModel on the first preset.

func (*ViewModel) Session

func (v *ViewModel) Session() *engine.Session

Session exposes the model, read-only by convention, for the host's tests.

func (*ViewModel) SetRuntime

func (v *ViewModel) SetRuntime(s string)

SetRuntime replaces the runtime description of the status line.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL