Documentation
¶
Overview ¶
Package notebook is the part of mdsh-gui that doesn't need a window: it opens a document, runs its blocks in a run.Session and lays the document out as cells for the frontend to draw.
Index ¶
- Constants
- Variables
- func Describe(event string, f map[string]any) (text string, lost bool)
- func DocURL(path string) string
- func OutsideImage(file, link string) (string, bool)
- func Reason(why string) string
- type AuditEvent
- type Cell
- type ChoiceCell
- type Completion
- type Deleted
- type DependsProblem
- type EarlierRun
- type EditReply
- type Event
- type EventLog
- type Fix
- type Fold
- type FrontMatter
- type HTTPCell
- type HTTPCheck
- type IncludeCell
- type IncludeFile
- type LineEdit
- type LineEvent
- type Lines
- type Move
- type Names
- type Notebook
- func (n *Notebook) BlockAt(line int) int
- func (n *Notebook) BlocksAt() ([]SourceBlock, Version)
- func (n *Notebook) Cells() []Cell
- func (n *Notebook) Changed() bool
- func (n *Notebook) ClearEarlierRuns(i int) error
- func (n *Notebook) ClearOutput(i int) error
- func (n *Notebook) ClearOutputs() error
- func (n *Notebook) Close()
- func (n *Notebook) Complete(input string) bool
- func (n *Notebook) Completions(before string) (Completion, error)
- func (n *Notebook) Curl(i int) (string, error)
- func (n *Notebook) DeleteBlock(i int) (Deleted, error)
- func (n *Notebook) DeleteEarlierRun(i, k int) error
- func (n *Notebook) DependsAt() ([]DependsProblem, Version)
- func (n *Notebook) DescribeFix(warning string) (Fix, error)
- func (n *Notebook) Dirty() bool
- func (n *Notebook) Edit(v Version, edits []LineEdit) (EditReply, error)
- func (n *Notebook) Enter(input string) error
- func (n *Notebook) EnterUnrecorded(input string) error
- func (n *Notebook) EnvBanner() string
- func (n *Notebook) File() string
- func (n *Notebook) FixWarning(warning string) error
- func (n *Notebook) FrontMatter() (FrontMatter, error)
- func (n *Notebook) FrontMatterError() string
- func (n *Notebook) FrontMatterFix() Fix
- func (n *Notebook) HasOutput() bool
- func (n *Notebook) History() bool
- func (n *Notebook) IncludeFile(i int) (IncludeFile, error)
- func (n *Notebook) Kill() bool
- func (n *Notebook) KillProcess(pid int) bool
- func (n *Notebook) LinesSince(v Version) Lines
- func (n *Notebook) MakeReport(r Report) ([]byte, error)
- func (n *Notebook) MoveBlock(i, dir int, byBlock bool) (Move, error)
- func (n *Notebook) MoveTo(from, at int) (Move, error)
- func (n *Notebook) Names() Names
- func (n *Notebook) Outside() []string
- func (n *Notebook) PlanMove(i, dir int, byBlock bool) (Move, error)
- func (n *Notebook) Processes() []env.ShellProcs
- func (n *Notebook) Prompt() (Prompt, error)
- func (n *Notebook) PromptAt(cols, rows int) (Prompt, error)
- func (n *Notebook) Ran() (ran, total int)
- func (n *Notebook) Redo() (string, error)
- func (n *Notebook) Reload() (waiting bool, err error)
- func (n *Notebook) ReplaceCast(i int, as string, frame int) error
- func (n *Notebook) ReportCommand(r Report, home string) string
- func (n *Notebook) Restart() error
- func (n *Notebook) RunBlock(i int) error
- func (n *Notebook) RunFrom(i int) error
- func (n *Notebook) RunOptions() RunOptions
- func (n *Notebook) RunRange(from, to int) error
- func (n *Notebook) Save() error
- func (n *Notebook) SaveAs(file string) error
- func (n *Notebook) SetCastFrame(i int, body string, frame int) error
- func (n *Notebook) SetChoice(i int, checked []bool) error
- func (n *Notebook) SetDepends(i int, deps []int) error
- func (n *Notebook) SetFolds(folds []Fold) error
- func (n *Notebook) SetFrontMatter(f FrontMatter) error
- func (n *Notebook) SetHistory(on, restart bool) (restarted bool, err error)
- func (n *Notebook) SetHistoryRC(path string)
- func (n *Notebook) SetHistoryReuse(on bool)
- func (n *Notebook) SetIncludeRange(i, from, to int) error
- func (n *Notebook) SetRunOptions(ro RunOptions) (waiting bool, err error)
- func (n *Notebook) SetTask(task int, done bool) error
- func (n *Notebook) SetTerminalSize(cols, rows int)
- func (n *Notebook) SetText(base, text string) (bool, error)
- func (n *Notebook) SetTextbox(i int, text string) error
- func (n *Notebook) Stop()
- func (n *Notebook) StopBackground(i int) bool
- func (n *Notebook) TerminalSize() (cols, rows int)
- func (n *Notebook) Text() string
- func (n *Notebook) TextAt() (string, Version)
- func (n *Notebook) Type(keys string)
- func (n *Notebook) Undo() (string, error)
- func (n *Notebook) Version() Version
- func (n *Notebook) WriteReport(r Report) error
- type Options
- type Problem
- type Prompt
- type Report
- type RunOptions
- type SourceBlock
- type TextboxCell
- type Version
Constants ¶
const DocPrefix = "/doc"
DocPrefix starts the URL of a file beside a document, as the window's asset server serves it: DocPrefix, then the file's absolute path.
const Unrecorded = -2
Unrecorded is the block a command typed in the History pane with recording off runs as, in terminal events: it is in no card.
Variables ¶
var ErrBadEdit = errors.New("edit lines out of order or out of range")
ErrBadEdit is an edit whose lines aren't in the text, or that overlaps the one before it.
var ErrBusy = errors.New("a block is running")
ErrBusy is returned when a run is asked for while one is going.
var ErrHistoryOff = errors.New("the History pane is off")
ErrHistoryOff is returned by Enter while the History pane is off.
var ErrNoMove = doc.ErrNoMove
ErrNoMove is returned for a move up from the top or down from the bottom.
var ErrRestartNeeded = errors.New("the shells need to start again, which loses the variables, functions and aliases blocks set in them")
ErrRestartNeeded is the answer when doing what was asked needs the shells to start again, which would lose what blocks set in them, and the user hasn't said that's fine.
var ErrStale = errors.New("the file changed since, so that edit can't be undone here")
ErrStale is returned by Undo and Redo when the file has changed since the edit, by a run, the source view or reloading, so taking it back would lose that change. Both stacks are emptied.
Functions ¶
func Describe ¶
Describe says what an audit event, with its fields besides v, seq, t and event, means, and whether what blocks set in a shell was lost with it.
func DocURL ¶
DocURL is the URL the window loads the file at path from. The file's modification time is added, so an image a run writes again is loaded again.
func OutsideImage ¶
OutsideImage is the file link, an image in the document at file, names when that is outside the document's folder, or hidden in it: an image the window shows only when the user asks.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
// Seq counts up from 1, so a page can tell it missed one.
Seq int `json:"seq"`
// Time is when it happened, RFC 3339 with milliseconds, in UTC.
Time string `json:"time"`
// Event names it, such as session.start or block.end; see
// docs/audit.md.
Event string `json:"event"`
// Text says what happened, in words.
Text string `json:"text"`
// Lost is set when what blocks set in a shell, its variables,
// functions and aliases, went with it.
Lost bool `json:"lost,omitempty"`
// JSON is the event as the audit log writes it, one line.
JSON string `json:"json"`
}
AuditEvent is one entry of a file's event log, as the Events pane shows it: what the shells, the file and the blocks run in it did, and why.
type Cell ¶
type Cell struct {
// Block is the block's index in the document, or -1 for prose.
Block int `json:"block"`
// HTML is the prose, rendered. Empty for a block.
HTML string `json:"html,omitempty"`
// Tasks number the task list checkboxes in HTML, in order, for
// SetTask.
Tasks []int `json:"tasks,omitempty"`
// Textbox is set for a textbox, which is drawn as one to type in.
Textbox *TextboxCell `json:"textbox,omitempty"`
// Choice is set for a choice, which is drawn as a dropdown, radio
// buttons or checkboxes.
Choice *ChoiceCell `json:"choice,omitempty"`
// ID, Lang and Body describe a block.
ID string `json:"id,omitempty"`
// Name is how the block is shown: its id, or "line N" when mdsh
// made the id up; see doc.Document.Label.
Name string `json:"name,omitempty"`
Lang string `json:"lang,omitempty"`
Body string `json:"body,omitempty"`
// Attrs are the block's attributes other than its id, as written,
// such as confirm timeout=5m.
Attrs string `json:"attrs,omitempty"`
// Depends are the ids of the blocks the block's depends= names, in
// order, for the lines the rendered view draws between them.
Depends []string `json:"depends,omitempty"`
// Output is the block's output, saved or from this session, rendered.
Output string `json:"output,omitempty"`
// At is when the run that made Output started (RFC 3339, in UTC):
// this session's run, or the at= saved with the output. Empty when
// there is no output or it was saved without a time.
At string `json:"at,omitempty"`
// Earlier are the block's earlier runs, kept by history=N, newest
// first.
Earlier []EarlierRun `json:"earlier,omitempty"`
// OutputTasks number the task list checkboxes in Output, as Tasks
// does for HTML.
OutputTasks []int `json:"outputTasks,omitempty"`
// Links is true when the block has the links attribute, so the web
// addresses in Output are made clickable.
Links bool `json:"links,omitempty"`
// Secret is set when the block's output may hold a secret: it is
// marked secret, or its code names a variable mdsh ctl set --secret
// made. The view masks the output until asked to show it, and with
// SecretCode, set for the secret attribute, the code too, since only
// there may the code itself hold one. Copying still works.
Secret bool `json:"secret,omitempty"`
SecretCode bool `json:"secretCode,omitempty"`
// Ran is true when the block ran this session; Status and Failed say
// how it went.
Ran bool `json:"ran"`
Status int `json:"status"`
Failed bool `json:"failed"`
// Stale is true when the block ran, but a block its depends= names
// has run again since, had its run cleared, or is stale itself.
Stale bool `json:"stale,omitempty"`
// NoSave is true for a block marked nosave: its output lives in
// the session, and saving keeps what the file holds after it.
NoSave bool `json:"nosave,omitempty"`
// Running is true while a background block is still going; its
// output and status come in when it ends.
Running bool `json:"running"`
// Ms is how long the block's last run this session took, in
// milliseconds, and TimedOut is true when its timeout= ended it.
Ms int64 `json:"ms,omitempty"`
TimedOut bool `json:"timedOut,omitempty"`
// Timeout is the block's timeout=, in milliseconds, or 0 when it has
// none, so a running block can show how close it is.
Timeout int64 `json:"timeout,omitempty"`
// Heading is the level of a prose cell that is a heading, 1 to 6;
// its section runs to the next heading of the same or a higher level.
Heading int `json:"heading,omitempty"`
// SectionFrom and SectionTo are the blocks a heading's section
// holds, its subsections' included: Blocks[SectionFrom:SectionTo],
// for RunRange. They are both 0 when no block in it runs.
SectionFrom int `json:"sectionFrom,omitempty"`
SectionTo int `json:"sectionTo,omitempty"`
// Collapsed is true when the view should open with a block's code, or
// a heading's section, folded: collapse= holds, or an mdsh:collapse
// line in the section does. CollapsedOutput is collapse-output='s.
Collapsed bool `json:"collapsed,omitempty"`
CollapsedOutput bool `json:"collapsedOutput,omitempty"`
// OutputLine is the line a block's saved output starts on, counting
// from 1, or 0 when it has none, for folding it in the source.
OutputLine int `json:"outputLine,omitempty"`
// HTTP is set for an http block with a response to show, from this
// session's run or saved in the file.
HTTP *HTTPCell `json:"http,omitempty"`
// Include is set for an include block, whose lines come from a
// file: the view can drag its range, and show the whole file.
Include *IncludeCell `json:"include,omitempty"`
// FirstLine is set on the cell of an include with from= past 1: the
// line in its file the included lines start on, where the code's line
// numbers count from, so they are the file's.
FirstLine int `json:"firstLine,omitempty"`
// From and To are the cell's bytes in the file, output included.
From int `json:"from"`
To int `json:"to"`
// Line is the line From is on, counting from 1.
Line int `json:"line"`
// Movable is set on a top-level block, which can move up and down
// the document (see MoveBlock), and LastLine is the last line of the
// block with its output and tape.
Movable bool `json:"movable,omitempty"`
LastLine int `json:"lastLine,omitempty"`
// Hidden says why a block, or a tape, that printing leaves out is
// drawn anyway: show= is false or its mdsh:if section is off, but
// Run all still runs it. Its code is never drawn folded.
Hidden string `json:"hidden,omitempty"`
// Undeletable says why a top-level block can't be deleted: what else
// in the document uses it, such as another block's depends=. Empty
// when it can.
Undeletable string `json:"undeletable,omitempty"`
// History is set on a top-level block the History pane added,
// #history-N, which deletes without asking.
History bool `json:"history,omitempty"`
// Drop is set when a block or section can be moved to just before
// the cell, with MoveTo at From.
Drop bool `json:"drop,omitempty"`
// DropAfter and DropBefore limit where a movable block, or a
// heading's section, can be dragged, so no block goes above one its
// depends= names: only to a cell whose From is above DropAfter and
// at or above DropBefore. DropAfter is -1 when nothing holds the
// move up, and DropBefore -1 when nothing holds it down, so the end
// is fine.
DropAfter int `json:"dropAfter"`
DropBefore int `json:"dropBefore"`
}
Cell is one piece of the document as the frontend draws it: a top-level block of prose, or a block the user can run.
type ChoiceCell ¶
type ChoiceCell struct {
// Block is the choice's index in the document, for SetChoice.
Block int `json:"block"`
ID string `json:"id"`
Mode string `json:"mode"` // dropdown, radio or multi
Options []doc.Option `json:"options"`
Placeholder string `json:"placeholder,omitempty"`
// Problem is why its var= binds nothing, if it doesn't.
Problem string `json:"problem,omitempty"`
// NoSave is true for a nosave choice: the picks are kept for the
// session, and saving leaves the file's marks as they are.
NoSave bool `json:"nosave,omitempty"`
}
ChoiceCell is a choice, as the frontend draws it.
type Completion ¶
Completion is what Tab offers in the History pane for the word before the cursor: each of Items replaces Word, the end of what was typed.
type Deleted ¶
type Deleted struct {
// Name is how the status line names the block, as #id.
Name string `json:"name"`
// Warnings are what the delete left behind, such as output copies of
// the block elsewhere in the file.
Warnings []string `json:"warnings,omitempty"`
}
Deleted is what a block delete did.
type DependsProblem ¶
type DependsProblem struct {
Line int `json:"line"`
Name string `json:"name"`
Input bool `json:"input"`
}
DependsProblem is a name in the depends= of the block whose fence is on Line, from 1, that isn't a block that runs: there is none, or it is an input.
type EarlierRun ¶
type EarlierRun struct {
// K is its place: 1 for the run before the current one, 2 for the
// one before that, and so on.
K int `json:"k"`
// At is when it ran, as its at= has it (RFC 3339, in UTC), or ""
// for output saved without one.
At string `json:"at,omitempty"`
// Exit is its exit status. Failed is set when it isn't 0 or the
// block ended its shell, and Region when its output is markdown, an
// image or a recording, which have no exit status of their own.
Exit int `json:"exit"`
Failed bool `json:"failed,omitempty"`
Region bool `json:"region,omitempty"`
// Output is its output, rendered.
Output string `json:"output"`
}
EarlierRun is one of a block's earlier runs, as the card draws it.
type EditReply ¶
type EditReply struct {
Applied bool `json:"applied"`
Version Version `json:"version"`
Events []LineEvent `json:"events"`
Reset bool `json:"reset"`
}
EditReply is Edit's answer: Applied says the edits were made. When they weren't, because the file changed since the version they were made against, Events and Reset say how, as Lines does.
type Event ¶
type Event struct {
// Kind is started, stdout, stderr or done; background when a
// background block starts, which goes on while other blocks run,
// with done when it ends; or, for a tty block, terminal (it takes
// the terminal pane), tty (it showed Bytes there) and terminal-end.
Kind string `json:"kind"`
Block int `json:"block"`
Data string `json:"data,omitempty"`
Bytes []byte `json:"bytes,omitempty"`
}
Event is what OnEvent reports while a block runs.
type EventLog ¶
type EventLog struct {
// contains filtered or unexported fields
}
EventLog is a file's event log, kept by its tab so that it outlives the notebook, as when the file is reloaded. It writes in mdsh --audit's format (see package audit) and keeps the last eventsMax events for the Events pane. A nil *EventLog logs nothing.
func NewEventLog ¶
func NewEventLog(notify func(AuditEvent)) *EventLog
NewEventLog returns an empty log. notify, if set, is called with each new event; it must not block or call back into the log.
func (*EventLog) List ¶
func (l *EventLog) List() []AuditEvent
List returns the events kept, oldest first.
type Fix ¶
type Fix struct {
// Label names it for a button.
Label string `json:"label"`
// Detail says what it does, for asking first.
Detail string `json:"detail"`
}
Fix is an edit that makes a warning go away.
type Fold ¶
type Fold struct {
// Block is the block whose code, or with Output its output, folds,
// or -1 for a section.
Block int `json:"block"`
Output bool `json:"output"`
// Heading is where a section's heading starts in the file: its
// cell's From.
Heading int `json:"heading"`
On bool `json:"on"`
}
Fold is a fold made by hand in the rendered view, for SetFolds to write to the file.
type FrontMatter ¶
type FrontMatter struct {
// Exists is whether the file has front matter at all.
Exists bool `json:"exists"`
Title string `json:"title"`
// Description is the first of description, summary and abstract
// the file has, the start screen's description; DescriptionKey is
// which, or description when it has none.
Description string `json:"description"`
DescriptionKey string `json:"descriptionKey"`
Tags []string `json:"tags"`
// The rest are under mdsh:, as doc.Options reads them.
Shell string `json:"shell"`
OnError string `json:"onError"` // "", "continue" or "stop"
Step bool `json:"step"`
// Interpolate and ShowStderr are "" when unset, else "on" or "off".
Interpolate string `json:"interpolate"`
ShowStderr string `json:"showStderr"`
Cols int `json:"cols"`
Rows int `json:"rows"`
// ShareAll is env.share left out, which shares every variable;
// otherwise Share lists those shared, maybe none.
Source []string `json:"source"`
// Other is the other top-level keys, as YAML, in the file's order.
Other string `json:"other"`
}
FrontMatter is the document's front matter as the rendered view's form edits it: the keys mdsh and the start screen read, each in a field of its own, and the rest as YAML.
type HTTPCell ¶
type HTTPCell struct {
// Status is the status line's code and text, such as 201 Created,
// and Code its number; both are empty when there is no response.
Status string `json:"status,omitempty"`
Code int `json:"code,omitempty"`
// Headers and Body are the response's parts, as the output shows
// them: the body pretty-printed, the credential headers masked.
Headers string `json:"headers,omitempty"`
Body string `json:"body,omitempty"`
// Checks are the last run's checks, in order: none for a response
// read from the file.
Checks []HTTPCheck `json:"checks,omitempty"`
}
HTTPCell is what the view shows of an http block's response, over its output: the status, the body and the headers as two tabs, and the checks with a tick or a cross. Headers are masked as the output is.
type HTTPCheck ¶
type HTTPCheck struct {
Text string `json:"text"`
OK bool `json:"ok"`
Got string `json:"got,omitempty"`
}
HTTPCheck is one check's result.
type IncludeCell ¶
type IncludeCell struct {
// Block is the include's index in the document, for SetIncludeRange
// and IncludeFile.
Block int `json:"block"`
// File is its file= and Lang its language, for highlighting the
// whole file.
File string `json:"file"`
Lang string `json:"lang"`
// From and To are its from= and to=, as the file holds them: 0 for
// one it doesn't have, which means the first and the last line.
From int `json:"from"`
To int `json:"to"`
}
IncludeCell is an include block, as the frontend draws it: a grip above and below its lines drags From and To, and a button shows the whole file.
type IncludeFile ¶
type IncludeFile struct {
Text string `json:"text"`
// Lines is how many lines Text has.
Lines int `json:"lines"`
}
IncludeFile is the whole of an include's file, for showing it and for dragging the include's range over it.
type LineEvent ¶
type LineEvent struct {
Tick int `json:"tick"`
First int `json:"first"`
Last int `json:"last"`
Text string `json:"text"`
}
LineEvent says lines [First, Last) of the text became Text, taking the file to Tick. Text is whole lines, so it ends with a newline unless it ends the file.
type Lines ¶
type Lines struct {
Version Version `json:"version"`
Events []LineEvent `json:"events"`
Reset bool `json:"reset"`
}
Lines is how the file changed after a version: Version is where it is now, and Events take a text at the version asked about there, in order. Reset is set when the events since that version are no longer kept, or it is another document's: the whole text is to be read again.
type Move ¶
type Move struct {
// Base is the file the move applies to, and Text the file after it.
// Base can differ from the file before the move was asked for, when
// blocks had to be given ids first (see PlanMove).
Base string `json:"base"`
Text string `json:"text"`
// Block is the block's index after the move, and Line the line its
// fence starts on, counting from 1. FromLine is the line it started
// on before, in Base.
Block int `json:"block"`
Line int `json:"line"`
FromLine int `json:"fromLine"`
// Warnings are what the move broke or changed that depends on block
// order, such as a condition that now reads a block below it.
Warnings []string `json:"warnings,omitempty"`
// Note is a softer word, for a block that ran: it ran in the old
// order.
Note string `json:"note,omitempty"`
// contains filtered or unexported fields
}
Move is a block move, planned or done.
type Names ¶
type Names struct {
IDs []string `json:"ids"`
Envs []string `json:"envs"`
Assets []string `json:"assets"`
Files []string `json:"files"`
// AssetsDir is the assets folder's name, <doc>.assets.
AssetsDir string `json:"assetsDir"`
}
Names are what attribute completion offers: block ids, for conditions, env names, and files for paths: those in the document's assets folder, for res:// paths, and those beside the document.
type Notebook ¶
type Notebook struct {
// contains filtered or unexported fields
}
Notebook is an open document.
func (*Notebook) BlockAt ¶
BlockAt is the top-level block whose fence, body, output or tape is on line (counting from 1), for moving it from the source view, or -1.
func (*Notebook) BlocksAt ¶
func (n *Notebook) BlocksAt() ([]SourceBlock, Version)
BlocksAt lists the blocks in the file, as SourceBlocks does for a text, with the version of the text they are in, so the source pane can complete depends= without sending the text it has: it maps their lines past what was typed since.
func (*Notebook) Cells ¶
Cells lays the document out for drawing: one cell per top-level markdown block of prose, such as a paragraph, heading, list or table, and one per fenced block. Blocks mdsh can't run are drawn as prose, as mdsh -i does. What printing leaves out, such as the front matter and mdsh:if sections that are off, is left out here too.
func (*Notebook) Changed ¶
Changed reports whether the file changed on disk since it was read or last saved.
func (*Notebook) ClearEarlierRuns ¶
ClearEarlierRuns takes top-level block i's earlier runs out of the file, and keeps its current output. Undo puts them back. Their image files go when the file is saved.
func (*Notebook) ClearOutput ¶
ClearOutput takes top-level block i's output out of the file, the output fences attached to it, and forgets this session's run of it, so saving doesn't write the output back, a block that depends on it asks to run it again, and the blocks that depend on it are stale. The shell keeps what the run did. It is a rendered-view edit, so Undo puts the output back.
func (*Notebook) ClearOutputs ¶
ClearOutputs takes every run's output out of the document, as render.Clear does, and forgets what ran, so the notebook shows no output and no statuses, and depends= runs what a block needs again. The shells stay as they are, with what blocks set in them: only Restart Shells starts them again. Like an edit, it isn't saved until Save.
func (*Notebook) Close ¶
func (n *Notebook) Close()
Close ends the shells blocks ran in, stopping any block that runs, background blocks included.
func (*Notebook) Complete ¶
Complete reports whether input is a whole command, a note or a block, so pressing enter in the History pane runs or adds it rather than starting another line. Input ending in \, |, && or ||, inside a quote, an if, a loop or a here-document, or inside a block it opens, isn't.
func (*Notebook) Completions ¶
func (n *Notebook) Completions(before string) (Completion, error)
Completions completes the word at the end of before, what is typed in the History pane up to the cursor, asking the document's shell, so it sees the directory and variables blocks left there: a $ word is a variable, the first word of a command is a command, and any other word, or one with a /, a file. A directory ends in /. Items are quoted for the shell, as they would be typed.
func (*Notebook) Curl ¶
Curl is http block i's request as a curl command line, with its placeholders filled in as running it now would: for Copy as curl. A placeholder with no value yet is left as written.
func (*Notebook) DeleteBlock ¶
DeleteBlock takes top-level block i out of the file, with its output and tape. It is a rendered-view edit, so Undo puts it back. Blocks without ids get them first if the delete would renumber them, as saving would give them, so nothing that names a block changes what it names.
func (*Notebook) DeleteEarlierRun ¶
DeleteEarlierRun takes block i's earlier run k out of the file, and numbers the rest again. Undo puts it back.
func (*Notebook) DependsAt ¶
func (n *Notebook) DependsAt() ([]DependsProblem, Version)
DependsAt is every name in a depends= that isn't a block that runs, with the version of the text whose lines it names, for the source pane to underline. It is what the pane checked from all the blocks it had Go parse out of its text, but is only what is wrong, so checking a long file moves a few bytes rather than the file.
func (*Notebook) DescribeFix ¶
DescribeFix says what FixWarning would do for warning, as logged.
func (*Notebook) Edit ¶
Edit makes edits, as typed in the source pane against the text at v, if the text is still at v. Edits are in order, don't overlap, and each names lines of the text at v. Blocks whose code didn't change keep their output, as with SetText.
func (*Notebook) Enter ¶
Enter takes what was typed in the History pane. A note, where every line starts with #, is added to the end of the document as prose with the # taken off, joining the paragraph of the note before it if nothing came between. Anything else is a command: it is added as a block, #history-N, and run on the terminal pane, waiting for it to finish; one ending in a lone & is added as a background block instead, without the &, and left running. A command that took over the screen, as vim does, is marked tty, so its output is a recording. A command that fails is kept, with its exit status. A block, from a line such as # ```bash to a line of ```, is added to the end of the document as it was typed, without running.
func (*Notebook) EnterUnrecorded ¶
EnterUnrecorded is Enter with recording off: a command runs on the terminal pane, in the shell blocks run in, but isn't added to the document, so nothing it does there is kept but what it changed in the shell. A command ending in a lone & runs in the shell's background, as a shell would run it. A note or a block is still added, since it is typed to be.
func (*Notebook) EnvBanner ¶
EnvBanner is the front matter's note that the file brings in more than the base set from the environment, or "" (see doc.Options.ShareBanner).
func (*Notebook) FixWarning ¶
FixWarning makes the fix for warning, as logged: it deletes an output copy for a block that isn't there, or takes an id that names no block that runs out of a depends=. It is a rendered-view edit, so Undo takes it back.
func (*Notebook) FrontMatter ¶
func (n *Notebook) FrontMatter() (FrontMatter, error)
FrontMatter reads the document's front matter for the form.
func (*Notebook) FrontMatterError ¶
FrontMatterError is why the front matter doesn't parse, or "" when it does. Until it does, the page says so and no block runs.
func (*Notebook) FrontMatterFix ¶
FrontMatterFix says what FixWarning does with FrontMatterError as the warning, or is the zero Fix when mdsh has no fix for the front matter.
func (*Notebook) HasOutput ¶
HasOutput reports whether ClearOutputs would take anything out of the document: any run's output, a filled output copy or a stored value. Once outputs are cleared it is false until a block's output comes in.
func (*Notebook) IncludeFile ¶
func (n *Notebook) IncludeFile(i int) (IncludeFile, error)
IncludeFile reads the whole of include block i's file.
func (*Notebook) Kill ¶
Kill ends the shell the running block runs in, at once, as when a stopped block won't stop and the user says to. What blocks set there is gone; the next block in that env starts a new shell. It reports whether a block was running.
func (*Notebook) KillProcess ¶
KillProcess kills process pid and what it started, if it runs under one of the notebook's shells, and reports whether it did.
func (*Notebook) LinesSince ¶
LinesSince is how the text changed after v.
func (*Notebook) MakeReport ¶
MakeReport renders the report r asks for. Image links are read from the file's folder, where runs write them.
func (*Notebook) MoveBlock ¶
MoveBlock moves top-level block i, with its output and tape, up (dir < 0) or down past the cell next to it, or with byBlock past the next block, prose and all. It is a rendered-view edit, so Undo takes it back. Blocks without ids get them first, as saving would give them, so the move renames nothing.
func (*Notebook) MoveTo ¶
MoveTo moves what starts at from, a cell's From, to at, one of the spots doc.Document.Boundaries lists (a cell's From where its Drop is set, or -1 for the end of the file), as dragging does: a top-level block with its output and tape, or a heading's whole section, which only goes before a heading of its level or higher, or to the end. Block is -1 for a section. Undo takes it back.
func (*Notebook) Names ¶
Names lists the document's block ids and envs, the files in its assets folder (<doc>.assets) as slash paths inside it, and the files in its folder as slash paths relative to it.
func (*Notebook) Outside ¶
Outside lists the files the document's includes and out= name outside its folder, or hidden in it: see run.Outside.
func (*Notebook) PlanMove ¶
PlanMove works out MoveBlock's move without making it, for the source view, which makes it as an edit of its own so its undo takes it back. If blocks had to be given ids first, that is done, and Base says what the file is now.
func (*Notebook) Processes ¶
func (n *Notebook) Processes() []env.ShellProcs
Processes lists the notebook's shells, each with the processes under it: blocks running, background blocks, and whatever blocks or the History pane left running.
func (*Notebook) Prompt ¶
Prompt asks the shell blocks run in for its prompts, so the History pane can show them, at the terminal's size. It returns ErrBusy while a block runs.
func (*Notebook) PromptAt ¶
PromptAt is Prompt at cols by rows, the History pane's size, which can differ from the terminal's: a block's card sizes that too.
func (*Notebook) Ran ¶
Ran counts the runnable blocks that have run in this window, and all of them.
func (*Notebook) Reload ¶
Reload reads the file from disk again, dropping output not saved and the edits Undo would take back. The shells stay as they are, with what blocks set in them. A change to the front matter's shell, or to what the shells share or source, which are fixed when they start, waits for Restart Shells; Reload reports whether one is waiting.
func (*Notebook) ReplaceCast ¶
ReplaceCast swaps tty block i's recording, in its output, for what as names: "text", the text frame n shows, counting from 1 (0 is the last), in an output fence; or "gif", an animated GIF made from it, saved beside the cast (or inline, for an inline cast) and linked in its place. The block still records a cast when it runs again. It is a rendered-view edit, so Undo puts the recording back.
func (*Notebook) ReportCommand ¶
ReportCommand is the mdsh command that makes the same report, run in the document's folder: files there are named on their own, and other paths under home as ~/…. For a report of the window's output, it is the command for the saved file, which is the same once it is saved.
func (*Notebook) Restart ¶
Restart ends the shells, and any background block still running, and starts them again, as if nothing had run, keeping the document as it is.
func (*Notebook) RunBlock ¶
RunBlock runs block i alone, waiting for it to finish. Asking for the block to run answers its confirm, so it isn't asked again.
func (*Notebook) RunOptions ¶
func (n *Notebook) RunOptions() RunOptions
RunOptions are the options blocks run with.
func (*Notebook) RunRange ¶
RunRange runs blocks from up to but not including to, as RunFrom runs them; a heading's SectionFrom and SectionTo run its section.
func (*Notebook) SaveAs ¶
SaveAs writes the document with its output to file, which becomes the notebook's file. If file is in another folder the shells start again there, as they would for a file opened from that folder.
func (*Notebook) SetCastFrame ¶
SetCastFrame writes frame=n, where a recording's player was left, so the file opens at that frame: on block i, a tty block, or with i < 0 on the first cast fence whose recording is body. n <= 0 takes frame= out, for the last frame. Frames set one after another are one undo.
func (*Notebook) SetChoice ¶
SetChoice checks the options of choice i as checked says, one bool per option, and those of every copy of it.
func (*Notebook) SetDepends ¶
SetDepends sets block i's depends= to the blocks deps names, by index and in order, or takes the attribute out when deps is empty. It is a rendered-view edit, so Undo takes it back. Blocks without ids get them first, as saving would give them, since depends= names blocks by id. Names already there that aren't a block that runs, which mdsh ignores, are kept, after the blocks deps names, so a typo isn't lost. A cycle comes back as its parse error and changes nothing, and a textbox or a choice, which never runs, is refused.
func (*Notebook) SetFolds ¶
SetFolds writes folds to the file, so it opens with them: a block's code folds with a bare collapse attribute and its output with a bare collapse-output, and a section with an mdsh:collapse line under its heading. Unfolding takes them out. Where the file folds by a condition, as with collapse={{$?}}!=0 or an mdsh:collapse line with a condition in the section, it is left as it is. Undo takes the change back.
func (*Notebook) SetFrontMatter ¶
func (n *Notebook) SetFrontMatter(f FrontMatter) error
SetFrontMatter writes f to the front matter, changing only the keys whose field differs from what the file has, so the rest keep their place. An empty field takes its key out, and front matter left with no keys is taken out too. It is a rendered-view edit, so Undo takes it back, and front matter mdsh refuses, such as on_error: maybe, comes back as its error and changes nothing.
func (*Notebook) SetHistory ¶
SetHistory turns the History pane on or off. Commands typed there run on a terminal, so turning it on needs shells with terminals of their own. If the shells have none, and blocks have run in them, starting them again would lose what those blocks set: then it starts them again only if restart is set, the user having said to, and otherwise leaves the pane off and returns ErrRestartNeeded. It reports whether the shells started again. The output shown so far is kept.
func (*Notebook) SetHistoryRC ¶
SetHistoryRC sets the file the shells read while the History pane is on, from the next time it is turned on.
func (*Notebook) SetHistoryReuse ¶
SetHistoryReuse sets whether a command typed in the History pane that was typed before, and so has a #history-N block, runs that block again, keeping its last output as an earlier run, rather than adding another block. It is off unless set.
func (*Notebook) SetIncludeRange ¶
SetIncludeRange writes from= and to= on include block i, as its grips were dragged to. Lines count from 1. from at the first line and to at the file's last line, or past it, take the attribute out, so the include follows the file as it changes. It is a rendered-view edit, so Undo takes it back.
func (*Notebook) SetRunOptions ¶
func (n *Notebook) SetRunOptions(ro RunOptions) (waiting bool, err error)
SetRunOptions changes the options blocks run with. It never starts the shells again: new arguments are set in the shells as they are, with set --, and --only, step mode and stop on error apply to the next run. A new shell, or new files to source, wait for Restart Shells, which is up to the user; it reports whether such a change is waiting. The output shown so far is kept.
func (*Notebook) SetTerminalSize ¶
SetTerminalSize sets the terminal pane's size in cells. The next tty block records at this size, and a running one follows it.
func (*Notebook) SetText ¶
SetText replaces the whole file with text, as typed in the split view, if the file is still base, the text the typing started from, and reports whether it did. When something else changed the file since, such as a run's output or an include filling its fence, it is left alone, so the editor can fold the change into what was typed and try again instead of throwing the change away. Blocks whose code didn't change keep their output.
func (*Notebook) SetTextbox ¶
SetTextbox replaces the text of textbox i, and of every copy of it.
func (*Notebook) StopBackground ¶
StopBackground kills block i if it is running in the background, and reports whether it was. Its result comes in as it would have had it ended, marked stopped.
func (*Notebook) TerminalSize ¶
TerminalSize is the terminal size the front matter asks for, in cells, with 0 for either it leaves to the window.
func (*Notebook) TextAt ¶
TextAt is the whole file and its version, for a source pane opening on it.
func (*Notebook) Type ¶
Type sends what was typed in the terminal pane to the block running in it. It is dropped if no block is.
func (*Notebook) Undo ¶
Undo takes back the last rendered-view edit, such as checking a task or picking a choice, and says what it was. It returns "" when there is nothing to undo, and ErrStale when the file changed since.
func (*Notebook) WriteReport ¶
WriteReport writes the report r asks for to r.Dest.
type Options ¶
type Options struct {
Run RunOptions
// OnEvent, if set, is called as blocks start, write and finish.
OnEvent func(Event)
// Confirm is asked before a block marked confirm runs. If it is nil
// such blocks don't run.
Confirm func(block int, question string) run.Answer
// Depend is asked before running block, which block of depends on
// and which hasn't run in this session. If it is nil, block of
// doesn't run.
Depend func(block, of int, question string) run.Answer
// Events, if set, gets the audit log of what the notebook's shells
// and blocks do, and why; see EventLog.
Events *EventLog
// Sources is asked before the first shell starts, whether a run's
// or one started to ask the shell something, as the History pane's
// prompt is, whether to read in the files the front matter's
// env.source names (see run.Options.ApproveSources). If it is nil,
// no shell starts for a document that names any.
Sources func(paths []string) run.Answer
// Outside says whether the document may reach the files run.Outside
// lists, outside its folder, or hidden in it, as the user last
// answered. It is asked as each session starts, and only the files
// listed then are let out, so one an edit adds stays in until it is
// asked about. If it is nil, nothing reaches outside.
Outside func(paths []string) bool
// Resolved, if set, is told of each warning logged for the console
// that the document no longer has, as logged, after an edit fixes
// it.
Resolved func(file, warning string)
}
Options configure a Notebook.
type Problem ¶
type Problem struct {
From int `json:"from"`
To int `json:"to"`
Severity string `json:"severity"` // error or warning
Message string `json:"message"`
}
Problem is something wrong in a fence's info string, for the block editor to underline. From and To are byte offsets in the info string.
type Prompt ¶
type Prompt struct {
PS1 string `json:"ps1"`
PS2 string `json:"ps2"`
// Dir is the shell's working directory, with the home folder as ~,
// shown on the pane's separator.
Dir string `json:"dir"`
}
Prompt is the shell's prompts, PS1 and PS2, expanded as the shell would show them, with their colors as ANSI escapes. Empty means the shell has none.
type Report ¶
type Report struct {
Format report.Format `json:"format"`
HideCode bool `json:"hideCode"`
HideOutput bool `json:"hideOutput"`
// History shows each block's earlier runs, kept by history=N, under
// its output, as mdsh --history does.
History bool `json:"history"`
// Saved reports the file as last saved, running nothing, like
// mdsh -n. Otherwise the report shows this window's output. "Run
// all first" is a run, then a report of the window.
Saved bool `json:"saved"`
// Ran says the window's output comes from running every block, for
// the command Command shows.
Ran bool `json:"ran"`
// Dest is the file to write.
Dest string `json:"dest"`
}
Report is what the Report dialog asks for.
type RunOptions ¶
type RunOptions struct {
// Args are the positional parameters, $1 and on.
Args []string `json:"args"`
// Only runs the named block and the earlier blocks in its env chain,
// like --only.
Only string `json:"only"`
// Step asks before every block, like --step.
Step bool `json:"step"`
// StopOnError stops at the first failing block, like --stop-on-error.
StopOnError bool `json:"stopOnError"`
// Shell overrides the front matter's shell, like --shell.
Shell string `json:"shell"`
// Source runs in every shell as it starts, like the files given to
// mdsh --source. It isn't sent to the window.
Source string `json:"-"`
// HistoryRC is a file, such as ~/.zshrc, the shells read as they
// start while the History pane is on, so the pane can be used as an
// everyday shell. It isn't sent to the window.
HistoryRC string `json:"-"`
}
RunOptions are the per-file choices mdsh takes as flags.
type SourceBlock ¶
type SourceBlock struct {
// Line is the line its opening fence is on, from 1.
Line int `json:"line"`
ID string `json:"id"`
// Runs says whether depends= can name it: an input never runs.
Runs bool `json:"runs"`
}
SourceBlock is a block in the source pane's text, for completing and checking depends= there.
func SourceBlocks ¶
func SourceBlocks(text string) []SourceBlock
SourceBlocks lists the blocks in text, the source pane's, in order, leaving out includes and tapes, which have no name. It is nil if text doesn't parse.
type TextboxCell ¶
type TextboxCell struct {
// Block is the textbox's index in the document, for SetTextbox.
Block int `json:"block"`
ID string `json:"id"`
Text string `json:"text"`
Lines int `json:"lines"`
// Fit is set by lines=fit: any number of lines, in a box as tall
// as the text.
Fit bool `json:"fit,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
// Problem is why its var= binds nothing, if it doesn't.
Problem string `json:"problem,omitempty"`
// NoSave is true for a nosave textbox: what is typed is kept for
// the session, and saving leaves the file's text as it is.
NoSave bool `json:"nosave,omitempty"`
}
TextboxCell is a textbox, as the frontend draws it.