Documentation
¶
Overview ¶
Package nbview draws a notebook tab and takes its keys and clicks, as Jupyter does: cells one under another, a code cell's pipeline in a box with its [n]: prompt and a ▶ that runs it, its output under it after Out[n]:, and a note cell's Markdown drawn as text. The active cell has a bar at its left. Like Jupyter it has two modes: in command mode keys act on cells (move, select several, add, delete, move them, run), in edit mode they type into the active cell. A toolbar over the cells runs the same commands. It knows the UI only through Host: the cells and outputs, the state of runs, and running the registered commands every action is.
Index ¶
- Constants
- func KeyLabel(k string) string
- type Checker
- type Completer
- type Completion
- type Diagnostic
- type Drafter
- type Entry
- type Full
- type Highlighter
- type Host
- type Instant
- type Kernel
- type Nu
- func (n *Nu) Check(ctx context.Context, src string) []Diagnostic
- func (n *Nu) Complete(ctx context.Context, src string, offset int) []Completion
- func (n *Nu) Draft(src string) []Span
- func (n *Nu) Highlight(ctx context.Context, src string) []Span
- func (n *Nu) Instant() bool
- func (n *Nu) SetWords(names []string, words []Word)
- type NuSession
- type Providers
- type Span
- type State
- type Tokens
- type View
- func (v *View) Boxes(top int) []overlay.Box
- func (v *View) Cell() (notebook.Cell, bool)
- func (v *View) Click(x, y int, shift bool) tea.Cmd
- func (v *View) CloseFull()
- func (v *View) Commit()
- func (v *View) Completions() ([]Completion, int)
- func (v *View) ContextLine() (string, string)
- func (v *View) Cursor() (x, y int, ok bool)
- func (v *View) Diagnostic() string
- func (v *View) Editing() bool
- func (v *View) Fetch() tea.Cmd
- func (v *View) Full() *Full
- func (v *View) FullOpen() bool
- func (v *View) Head() (name, text string)
- func (v *View) Hidden(id int) bool
- func (v *View) Key(k tea.KeyPressMsg) (tea.Cmd, bool)
- func (v *View) Lines() []string
- func (v *View) OpenFull() bool
- func (v *View) Outline(cells bool) []Entry
- func (v *View) Paste(text string) tea.Cmd
- func (v *View) Pending() string
- func (v *View) Range() (from, to int)
- func (v *View) Resize(width, height int)
- func (v *View) Reveal(id int)
- func (v *View) RightClick(y int)
- func (v *View) Rule(left, right string, width int) string
- func (v *View) Select(i int, out bool)
- func (v *View) SelectRange(from, to int)
- func (v *View) Selected() (int, bool)
- func (v *View) StartEdit() tea.Cmd
- func (v *View) StopEdit()
- func (v *View) ToggleHidden()
- func (v *View) ToggleWhole()
- func (v *View) Toolbar(width int) string
- func (v *View) ToolbarAt(x, width int) string
- func (v *View) Update(msg tea.Msg) (tea.Cmd, bool)
- func (v *View) Wheel(y, d int)
- func (v *View) Whole(id int) bool
- type Word
- type Words
Constants ¶
const Back = "back"
Back is what ToolbarAt says of the button that leaves a full-screen output, which has no command.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Checker ¶
type Checker interface {
Check(ctx context.Context, src string) []Diagnostic
}
Checker finds the problems in a pipeline.
type Completer ¶
type Completer interface {
Complete(ctx context.Context, src string, offset int) []Completion
}
Completer lists what can go at the caret, a byte offset into src.
type Completion ¶
Completion is a word Tab can put at the caret: Text in place of src[From:To].
type Diagnostic ¶
Diagnostic is a problem with part of a pipeline, by byte offsets.
type Drafter ¶
Drafter is a slow highlighter with a quick draft, drawn until its answer comes, and in place of one while it's Instant.
type Entry ¶
type Entry struct {
Cell int // the cell's index
Level int // a heading's level, 1 for #; 0 for a cell
Title string // the heading's text, or the cell's first line
}
Entry is a place in the notebook to jump to: a heading of a note, or a cell.
type Full ¶
type Full struct {
Title string
// contains filtered or unexported fields
}
Full is an output shown full-screen, read-only: a table as a grid with a pointer, sorted by a column (s, S) and filtered to the rows holding some text (/), without changing the output; anything else as its lines, scrolled. Esc goes back to the notebook.
func (*Full) ContextLine ¶
ContextLine says what's shown and the keys.
type Highlighter ¶
Highlighter says what each part of a pipeline is.
type Host ¶
type Host interface {
Theme() *theme.Theme
Locale() *locale.Locale
// Cells are the notebook's cells, and Output a cell's output.
Cells() []notebook.Cell
Output(id int) *notebook.Output
// State is how a cell's run stands, and Kernel how running stands.
State(id int) State
Kernel() Kernel
// Run runs a registered command, as its key would.
Run(command string) tea.Cmd
// Edit keeps a cell's new source, as one undo step.
Edit(id int, source string)
}
Host is what the notebook needs of the UI.
type Instant ¶
type Instant interface{ Instant() bool }
Instant is a highlighter quick enough to ask while drawing, as the built-in tokenizer is.
type Kernel ¶
type Kernel struct {
Busy bool // a cell is running
Waiting int // cells waiting to run
Off string // why cells don't run here, or ""
Reactive bool // cells reading a cell run again when it runs
Clip int // cells copied, for Paste
}
Kernel is how running cells stands, for the toolbar: Jupyter's kernel, which here is nu started for each cell.
type Nu ¶
type Nu struct {
// contains filtered or unexported fields
}
Nu is a notebook's language as nu itself knows it: highlighting from its --ide-ast shapes, completions from --ide-complete after the notebook's own words, and problems from --ide-check.
nu doesn't know the variables a notebook binds ($sales, $selection, $sheet.A1:C9) nor a cell's `name =`, so it's asked about the source with those declared before it, in a prelude, and the cell's name and ranges of sheets masked to as many bytes, so offsets map back by the prelude's length alone (see prepare).
func (*Nu) Check ¶
func (n *Nu) Check(ctx context.Context, src string) []Diagnostic
Check implements Checker: nu's problems with the pipeline, leaving out those that only say it's unfinished at its end, as it is while it's typed.
func (*Nu) Complete ¶
Complete implements Completer: the notebook's words, then nu's that they don't have.
func (*Nu) Highlight ¶
Highlight implements Highlighter: nu's shapes, or the tokenizer's when nu doesn't answer.
func (*Nu) Instant ¶
Instant implements Instant: while nu isn't asked, the tokenizer answers at once.
type NuSession ¶
type NuSession struct {
Runner nushell.Runner
// Timeout bounds each question; 0 is a second and a half.
Timeout time.Duration
// contains filtered or unexported fields
}
NuSession is what a session's questions to nu share: whether nu may be asked, whether it answers, and how many questions are out. Each question is a process of its own, asked in the background once typing pauses, at most two at a time, stopped when the text it's about is stale and after Timeout. While nu can't be asked (SetOn said no, it isn't installed, it's older than nushell.MinVersion, or it timed out three times in a row) the notebook's Nu answers as the built-ins do, and nu isn't started.
func NewNuSession ¶
NewNuSession returns a session asking nu through r, once SetOn allows it.
func (*NuSession) Asking ¶
Asking reports whether nu is asked: allowed, and not found missing, old or slow.
type Providers ¶
type Providers struct {
Highlighter Highlighter
Completer Completer
Checker Checker
}
Providers are the language's answers for a notebook; any may be nil.
type State ¶
type State struct {
Waiting, Running bool
Started time.Time // when it started running
Stale bool // what it read, or its source, changed since it ran
// Problem says why it can't run as it is: its name is taken.
Problem string
}
State is how a cell's run stands, as the runner knows it.
type Tokens ¶
type Tokens struct{}
Tokens is the built-in highlighter: a small tokenizer of nushell's shapes, which knows commands by where they stand rather than by name.
type View ¶
type View struct {
// Keys bind command mode's keys to commands, EditKeys edit mode's;
// "d d" is d pressed twice.
Keys, EditKeys map[string]string
Providers Providers
// contains filtered or unexported fields
}
View is a notebook tab's view and its state: the selected cells, the scroll position, the mode, and what's worked out from the cells.
func (*View) Click ¶
Click takes a left click at column x of line y of the body; shift extends the selection to the cell clicked.
func (*View) Commit ¶
func (v *View) Commit()
Commit keeps what's typed as the cell's source, still editing.
func (*View) Completions ¶
func (v *View) Completions() ([]Completion, int)
Completions are the completions shown, and the highlighted one.
func (*View) ContextLine ¶
ContextLine is what the context line says in the notebook, at its left and its right: a problem, a key waiting for its pair, or what the selection is, and the keys that apply that the toolbar doesn't show.
func (*View) Cursor ¶
Cursor is where the terminal's caret goes in the body, while a cell is edited.
func (*View) Diagnostic ¶
Diagnostic is the problem the caret is on, for the context line, or "" when it is on none.
func (*View) Fetch ¶
Fetch asks the highlighter about the sources drawn without an answer, in the background.
func (*View) Head ¶
Head is what the formula bar says of the selection: the cell's name or number, and what it reads, or what its output holds.
func (*View) Hidden ¶
Hidden reports whether cell id's output is folded to a line, and Whole whether it shows every row rather than a window.
func (*View) Outline ¶
Outline is the notebook's headings in order, from its notes' Markdown: its table of contents. With cells, every cell is there too, a code cell by its first line and a note by its first heading or line.
func (*View) Range ¶
Range is the selected cells, first and last: the active cell alone, or the run of cells Shift+Up and Down selected with it.
func (*View) Resize ¶
Resize sets the body's size: the lines under the toolbar and above the status line.
func (*View) Reveal ¶
Reveal scrolls so cell id's block shows, as far as it fits, without selecting it: the cell running while every cell runs.
func (*View) RightClick ¶
RightClick selects the cell at line y for its context menu, unless it's one of the cells selected.
func (*View) Rule ¶
Rule is the context line drawn at width: left, then a rule, then right, the rule closing off the toolbar above the cells.
func (*View) SelectRange ¶
SelectRange selects cells from to to, the last one active.
func (*View) Selected ¶
Selected is the active cell's index, and whether its output is selected rather than the cell.
func (*View) StopEdit ¶
func (v *View) StopEdit()
StopEdit leaves edit mode, keeping what was typed.
func (*View) ToggleHidden ¶
func (v *View) ToggleHidden()
ToggleHidden folds the selected cells' outputs to a line, or shows them again, as Jupyter's o.
func (*View) ToggleWhole ¶
func (v *View) ToggleWhole()
ToggleWhole shows the selected cells' outputs whole, or in their windows again, as Jupyter's Shift+O toggles scrolling.
func (*View) Toolbar ¶
Toolbar draws the toolbar at width: the full-screen output's title while one is open.