cat / 012
clone

a spreadsheet for the terminal: lotus 1-2-3 looks, google sheets keys and formulas, one go binary

cat/module-path
012 / internal / notebook / job.go
job.go 2.0K
1package notebook23import "fmt"45// Run is what running a code cell takes that the notebook knows: what6// nu runs, and the variables it reads from other cells. The screen and7// the headless runner each add what only they know: linked files, the8// selection and ranges of sheets.9type Run struct {10 // Command is what nu runs (Source.Command), and Exports the11 // variables it hands back beside the output.12 Command string13 Exports []string14 // Stream is what nu runs to stream the cell (Source.StreamCommand).15 Stream string16 // Tables are the other cells' outputs and variables it reads, by17 // name, as NUON, and Reads the Seqs of the outputs they came from.18 Tables map[string][]byte19 Reads map[string]int20 // Others are the names it reads that no cell gives: linked files,21 // or nothing nu will say so of.22 Others []string23 // Ranges are the ranges of sheets it reads, and Selection whether it24 // reads $selection.25 Ranges []SheetRef26 Selection bool27}2829// Prepare works out what running cell i takes, reading the outputs of30// the cells it reads; the error says why it can't run: what it reads31// hasn't run or failed.32func Prepare(cells []Cell, i int, output func(id int) *Output) (Run, error) {33 src := cells[i].Parse()34 cmd, exports, ranges := src.Command()35 run := Run{Command: cmd, Exports: exports, Stream: src.StreamCommand(), Tables: map[string][]byte{}, Reads: map[string]int{}, Ranges: ranges, Selection: src.ReadsSelection()}36 vars := Vars(cells)37 for _, name := range src.Refs() {38 j, ok := vars[name]39 if !ok || j == i {40 run.Others = append(run.Others, name)41 continue42 }43 o := output(cells[j].ID)44 switch {45 case o.Failed():46 return run, fmt.Errorf("it reads $%s, which failed", name)47 case o == nil || o.Unsaved || !Readable(cells[j], name, o):48 return run, fmt.Errorf("it reads $%s, which hasn't run", name)49 }50 run.Tables[name], run.Reads[name] = o.NUON, o.Seq51 if cells[j].Name() != name {52 run.Tables[name] = o.Vars[name]53 }54 }55 return run, nil56}