Documentation
¶
Index ¶
- Variables
- type Bundle
- type Context
- func (c *Context) Cancel()
- func (c *Context) Display(o Output)
- func (c *Context) DisplayWithID(o Output, displayID string, update bool)
- func (c *Context) Err() error
- func (c *Context) GetPointer(name string) unsafe.Pointer
- func (c *Context) HasInput() bool
- func (c *Context) Input(prompt string, password bool) (string, error)
- func (c *Context) ResetCancel()
- func (c *Context) SetAutoResult(v any)
- func (c *Context) SetDisplayHook(fn func(o Output, displayID string, update bool))
- func (c *Context) SetInputFunc(fn func(prompt string, password bool) (string, error))
- func (c *Context) SetPointer(name string, typeName string, ptr unsafe.Pointer, keepAlive any)
- func (c *Context) StdContext() context.Context
- func (c *Context) TakeDisplays() []Output
- func (c *Context) TakeResult() (Output, bool)
- type MIMEBundler
- type Output
- type Registry
- type Symbol
- type TypeRegistry
Constants ¶
This section is empty.
Variables ¶
var ErrInterrupted = errors.New("interrupted")
ErrInterrupted is the error Err returns once Cancel has been called -- and the value every injected interrupt check panics with (see pkg/compiler's injectInterruptChecks), since Go has no way to forcibly stop a running goroutine: a loop can only be asked to notice and stop itself.
Functions ¶
This section is empty.
Types ¶
type Bundle ¶
Bundle maps a MIME type to its payload, mirroring the shape of Jupyter's `data` field exactly so no conversion is needed on the way to the socket. Binary payloads (images) are base64-encoded strings, as the protocol requires.
type Context ¶
type Context struct {
Registry *Registry
Types *TypeRegistry
// contains filtered or unexported fields
}
Context is the object passed to the Execute(ctx) function of every plugin.
func Current ¶
func Current() *Context
Current returns the Context of the running session, or nil if none has been created. pkg/display is a separate package and has no other way to reach it.
func NewContext ¶
func NewContext(reg *Registry, tr *TypeRegistry) *Context
NewContext initializes an execution Context and binds it as the current one.
The binding lives here rather than behind an exported setter for two reasons: session.New already calls this exactly once, so it cannot be forgotten, and nothing new is exported for cell code to misuse.
func (*Context) Cancel ¶
func (c *Context) Cancel()
Cancel flags the cell currently running against this Context as interrupted. Safe to call from a different goroutine than the one executing the cell (e.g. the ZMQ Control loop handling an interrupt_request while the Shell loop is blocked inside Execute).
func (*Context) Display ¶
Display queues an Output to be published as a display_data message. Unlike the single SetAutoResult slot, this appends: a cell may show as many things as it likes.
func (*Context) DisplayWithID ¶
DisplayWithID shows an Output under a handle the frontend can find again. update=false creates the output, update=true replaces whatever is already showing under that id -- including outputs from earlier cells, which is how a single progress bar can be driven from several of them.
func (*Context) Err ¶
Err returns ErrInterrupted if Cancel has been called since the last ResetCancel, nil otherwise. Every injected loop check calls this.
func (*Context) GetPointer ¶
GetPointer retrieves the raw memory address of a symbol by its name.
func (*Context) HasInput ¶
HasInput reports whether anything can be prompted. The session uses it to decide whether the cell is running somewhere with a frontend attached.
func (*Context) ResetCancel ¶
func (c *Context) ResetCancel()
ResetCancel clears a previous interrupt before a new cell starts, so a resolved interrupt from one cell can never bleed into the next.
func (*Context) SetAutoResult ¶
SetAutoResult records a cell's last expression, displayed by the kernel as an execute_result (equivalent to Jupyter's "Out[n]"). Generated code passes the expression itself rather than a pre-rendered string, so the choice between a rich representation and %#v is made here, in one testable place, instead of in the code generator.
func (*Context) SetDisplayHook ¶
SetDisplayHook installs live publishing. Once set, Display goes out as it is called rather than at the end of the cell -- which is what makes an in-place update mean anything: a progress bar cannot progress if every frame is flushed after the cell has already finished.
func (*Context) SetInputFunc ¶
SetInputFunc installs the hook that Input uses. Called once at kernel start.
func (*Context) SetPointer ¶
SetPointer records the raw memory address, type name, and a GC KeepAlive reference.
func (*Context) StdContext ¶
StdContext returns a standard context.Context, cancelled the moment Cancel is called. Every generated Execute() declares it as the cell-local `_ctx`, so user code can hand it to any idiomatic Go API that accepts one (net/http, os/exec, database/sql, a raw `select` on Done()) -- reaching blocking calls the AST-injected loop checks cannot: those only ever run between iterations of a `for` loop in the cell's own code, never inside a call Go has already descended into.
func (*Context) TakeDisplays ¶
TakeDisplays returns everything queued since the last call and clears the queue.
Known limitation, the display twin of the captured-stdout bleed-through already documented in the README: draining happens per cell, so an Output queued by a background goroutine between cells is published under whichever cell runs next. The print is never lost, only misattributed.
func (*Context) TakeResult ¶
TakeResult returns the current cell's displayed result and resets the state for the next execution. The kernel calls this method once per cell.
type MIMEBundler ¶
type MIMEBundler interface {
MIMEBundle() Output
}
MIMEBundler is implemented by types that know how to render themselves. It is declared here, next to the type switch that consumes it, because the switch can only match the interface it was compiled against -- pkg/display re-exports it as an alias so notebook code never has to name this package.
type Output ¶
Output is one thing a cell chose to show: a Bundle plus the optional per-MIME metadata Jupyter carries alongside it. Meta is nil in the common case; it exists because that is where an image's display size lives (`{"image/png": {"width": 400}}`), which a bare Bundle cannot express.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry manages the thread-safe global symbol table.
func (*Registry) AllSymbols ¶
AllSymbols returns a copy of all registered symbols.
func (*Registry) GetPointer ¶
GetPointer returns the pointer to the data associated with the symbol `name`.
type Symbol ¶
type Symbol struct {
Name string
TypeName string
Ptr unsafe.Pointer
KeepAlive any
CreatedAt uint64
}
Symbol represents a symbol exported by a cell in memory.
type TypeRegistry ¶
type TypeRegistry struct {
// contains filtered or unexported fields
}
TypeRegistry stores type and function/method declarations that can be re-injected.
func NewTypeRegistry ¶
func NewTypeRegistry() *TypeRegistry
NewTypeRegistry creates a new declaration registry.
func (*TypeRegistry) AllTypes ¶
func (tr *TypeRegistry) AllTypes() map[string]string
AllTypes returns a copy of all registered declarations.
func (*TypeRegistry) RegisterType ¶
func (tr *TypeRegistry) RegisterType(name string, code string)
RegisterType registers a type, method, or function declaration.