Documentation
¶
Overview ¶
Package notebook is a notebook's document: its cells (code cells holding a nushell pipeline, note cells holding Markdown), the names cells give their outputs, what each cell reads, the order cells run in, and what a cell's last run left (its output). It knows nothing of sheets, terminals or nu itself: the engine (internal/sheet) keeps a notebook tab's cells in its undo history and its file, and the UI runs them and draws them.
Index ¶
- Constants
- Variables
- func Dependents(cells []Cell, i int) []int
- func Inputs(cells []Cell, i int, output func(id int) *Output) []int
- func Kept(cells []Cell, output func(id int) *Output, caps Caps) map[int]bool
- func Names(cells []Cell) map[string]int
- func Order(cells []Cell, want []int) (order, cycle []int)
- func RangeSpans(pipeline string) [][2]int
- func Reads(cells []Cell, names map[string]int, i int) []int
- func ReadsSelection(pipeline string) bool
- func Refs(pipeline string) []string
- func Settle(cells []Cell, outputs map[int]*Output)
- func SplitName(src string) (name, pipeline string)
- func Stale(cells []Cell, output func(id int) *Output) map[int]bool
- func Taken(cells []Cell, i int) string
- func ValidName(name string) error
- func WithName(src, name string) string
- type Caps
- type Cell
- type Kind
- type Output
- type SheetRef
Constants ¶
const Selection = "selection"
Selection is the variable that holds the selection.
Variables ¶
var DefaultCaps = Caps{Cell: 1 << 20, Total: 8 << 20}
DefaultCaps keep 1 MB of a cell's output and 8 MB of a notebook's.
var Reserved = []string{"in", "env", "nu", "it", "selection", "sheet"}
Reserved are nushell's own variables and the notebook's: $selection is the selection on a sheet, $sheet.A1:C9 a range of one.
Functions ¶
func Dependents ¶
Dependents returns the cells that read cell i, directly or through others, in the notebook's order.
func Inputs ¶
Inputs returns the cells cell i reads, directly or through others, that have no output, in the notebook's order: what has to run before it can.
func Kept ¶
Kept returns the cells, by ID, whose outputs a file keeps within caps: in the notebook's order, each that fits in what's left.
func Order ¶
Order returns the code cells of want, each after the cells it reads among them, in want's order otherwise, and the cells left out for reading themselves, directly or through others.
func RangeSpans ¶
RangeSpans are where a pipeline reads ranges of sheets, by byte offsets: each $sheet.A1:C9 whole, as Bind renames them.
func ReadsSelection ¶
ReadsSelection reports whether a pipeline reads $selection.
func Refs ¶
Refs returns the names a pipeline reads as $name, in the order it first names them, leaving out nushell's variables and the notebook's own ($selection, $sheet).
func Settle ¶
Settle makes outputs read from a file what their cells' runs would have left: made from the source as it is, having read the outputs as they are, so none is stale until something changes.
func SplitName ¶
SplitName splits `name = pipeline` into the name and the pipeline; a source that doesn't start so has no name. `==` isn't a name's `=`.
func Stale ¶
Stale returns the cells, by ID, whose output may not be what running them now would give: their source changed since, or an output they read changed or is stale itself.
func Taken ¶
Taken says why cell i can't use its name: an earlier cell gives it (names ignore case there, as formulas' nu.name do), or "".
Types ¶
type Caps ¶
type Caps struct{ Cell, Total int }
Caps are how much of the outputs a file keeps, in bytes of NUON: at most Cell of one cell's, Total of all of them.
type Cell ¶
type Cell struct {
// ID identifies the cell for as long as the workbook is open: its
// output is kept by it. It isn't saved.
ID int
Kind Kind
Source string
}
Cell is one cell of a notebook. Cells are values: a change makes a new one, so the undo history can keep the list it replaced.
type Output ¶
type Output struct {
// NUON is what the pipeline printed, as NUON; nil when it failed or
// its output wasn't saved.
NUON []byte
// Err is nu's message when the run failed, and Detail the rest of
// what it said (its help line).
Err, Detail string
// Note says what was left out.
Note string
// Count is the run's number in this session, [3]; 0 for an output
// read from the file.
Count int
// Seq identifies the output among the workbook's, for telling
// whether what a cell read has changed since.
Seq int
// Took is how long the run took.
Took time.Duration
// Source is the cell's source when it ran.
Source string
// Reads are the Seqs of the outputs the run read, by name.
Reads map[string]int
// Selection is the range the run read as $selection, "Sheet1!A1:C9".
Selection string
// Unsaved is set on an output the file didn't keep, being larger
// than the caps allowed: there's nothing to show until it runs.
Unsaved bool
}
Output is what a code cell's last run left: what it printed, as NUON, or why it failed. Outputs are values too, replaced whole.