euporie.core.tabs.console

Contains the Console tab base class.

Functions

abstractmethod(funcobj)

A decorator indicating abstract methods.

edit_in_editor(filename[, line_number])

Suspend the current app and edit a file in an external editor.

get_cmd(name)

Get a command from the centralized command system by name.

has_focus(value)

Enable when this buffer has the focus.

new_notebook(**kwargs)

Create a new notebook, without validation.

Classes

BaseConsole(app[, path, use_kernel_history, ...])

Base class for Consoles.

Buffer([completer, auto_suggest, history, ...])

The core data structure that holds the text and cursor position of the current input line and implements all text manipulations on top of it.

Condition(func)

Turn any callable into a Filter.

Event(sender[, handler])

Simple event to which event handlers can be attached. For instance::.

KernelInput(kernel_tab[, text, multiline, ...])

Kernel input text areas.

KernelTab(app[, path, kernel, comms, ...])

A Tab which connects to a kernel.

KernelValidator(kernel)

Validate kernel input using a kernel code completeness call.

KeyBindings()

A container for a set of key bindings.

LspCell(id, idx, path, kind, language, text, ...)

An LSP client's representation of a cell.

MouseEventType(*values)

MsgCallbacks

Typed dictionary for named message callbacks.

Report([iterable])

Class for storing a diagnostic report.

StdInput(kernel_tab)

A widget to accept kernel input.

UPath(*args[, protocol])

ValidationState(*values)

The validation state of a buffer.

partial(func, /, *args, **keywords)

Create a new function with partial application of the given arguments and keywords.

class euporie.core.tabs.console.BaseConsole(app: BaseApp, path: Path | None = None, use_kernel_history: bool = True, connection_file: Path | None = None)

Bases: KernelTab

Base class for Consoles.

Provides common functionality for console implementations, including input validation, code execution, and kernel interaction.

allow_stdin: bool
bg_init = False
change_kernel(msg: str | None = None, startup: bool = False) None

Prompt the user to select a new kernel.

abstractmethod clear_output(wait: bool = False) None

Remove the last output, optionally when new output is generated.

Parameters:

wait – If True, clear output when new output is generated.

close(cb: Callable | None = None) None

Shut down kernel when tab is closed.

comm_close(content: dict, buffers: Sequence[bytes]) None

Close a notebook Comm.

comm_msg(content: dict, buffers: Sequence[bytes]) None

Respond to a Comm message from the kernel.

comm_open(content: dict, buffers: Sequence[bytes]) None

Register a new kernel Comm object in the notebook.

complete(content: dict | None = None) None

Re-render any changes.

container: AnyContainer
property current_input: KernelInput

Return the currently active kernel input, if any.

default_callbacks: MsgCallbacks
execution_count: int
file_extensions: ClassVar[dict[str, None]] = {}
focus() None

Focus the tab (or make it visible).

init_kernel(kernel: BaseKernel | None = None, comms: dict[str, Comm] | None = None, use_kernel_history: bool = False, connection_file: Path | None = None) None

Set up the tab’s kernel and related components.

input_box: KernelInput
interrupt_kernel() None

Interrupt the current Notebook’s kernel.

kernel_died() None

Call if the kernel dies.

property kernel_display_name: str

Return the display name of the kernel defined in the notebook JSON.

property kernel_lang_file_ext: str

Return the display name of the kernel defined in the notebook JSON.

kernel_language: str
property kernel_name: str

Return the name of the kernel defined in the notebook JSON.

kernel_started(result: dict[str, Any] | None = None) None

Task to run when the kernel has started.

lang_file_ext() str

Return the file extension for scripts in the notebook’s language.

Returns:

The file extension including the leading dot.

property language: str

The language of the current kernel.

async load_history() None

Load kernel history.

async load_lsps() None

Load the LSP clients.

lsp_add_cell(lsp: LspClient) None

Notify the LSP of a new cell.

lsp_after_save_handler(lsp: LspClient) None

Tell the the LSP we saved a document.

lsp_before_save_handler(lsp: LspClient) None

Tell the the LSP we are about to save a document.

property lsp_cell: LspCell

Return a LSP cell representation of the current input.

lsp_change_handler(lsp: LspClient) None

Tell the LSP server a file has changed.

lsp_close_handler(lsp: LspClient) None

Tell the LSP we opened a file.

lsp_open_handler(lsp: LspClient) None

Tell the LSP we opened a file.

lsp_update_diagnostics(lsp: LspClient) None

Process a new diagnostic report from the LSP.

property metadata: dict[str, Any]

Return a dictionary to hold notebook / kernel metadata.

mime_types: ClassVar[set[str]] = {}
name: str | None = None
abstractmethod new_input(input_json: dict[str, Any], own: bool, force: bool = False) None

Create new cell inputs in response to kernel execute_input messages.

Parameters:
  • input_json – The input data from the kernel message.

  • own – Whether this input originated from this console.

  • force – Whether to force rendering even if it’s our own input.

abstractmethod new_output(output_json: dict[str, Any], own: bool) None

Handle new output from the kernel.

Parameters:
  • output_json – The output data from the kernel message.

  • own – Whether this output originated from this console.

property path_cell: Path

Return the virtual path of the console as a notebook cell.

property path_nb: Path

Return the virtual path of the console as a notebook.

post_init_kernel() None

Start the kernel after if has been loaded.

pre_init_kernel() None

Run stuff before the kernel is loaded.

prompt(text: str, count: int | None = None, offset: int = 0, show_busy: bool = False) StyleAndTextTuples

Determine what should be displayed in the prompt of the cell.

abstractmethod refresh(now: bool = True) None

Request the output is refreshed (refresh the whole app).

report() Report

Return the current diagnostic reports.

report_kernel_error(error: Exception | None) None

Report a kernel error to the user.

reset() None

Reset the state of the tab.

restart_kernel(cb: Callable | None = None) None

Restart the current Notebook’s kernel.

abstractmethod run(buffer: Buffer | None = None) None

Run the code in the input box.

Parameters:

buffer – The buffer containing the code to run. If None, uses the current input buffer.

save(path: Path | None = None, cb: Callable | None = None) None

Save the current file.

set_kernel_info(info: dict) None

Receive and process kernel metadata.

Parameters:

info – Kernel information dictionary.

abstractmethod set_next_input(text: str, replace: bool = False) None

Set the text for the next prompt.

Parameters:
  • text – The text to set in the input.

  • replace – Whether to replace existing text.

stdin_box: StdInput
switch_kernel(factory: KernelFactory) None

Shut down the current kernel and change to another.

property title: str

Return the tab title.

validate_input(code: str) bool

Determine if the entered code is ready to run.

Parameters:

code – The code to validate.

Returns:

True if the code is complete and ready to execute.

weight: int = 0
write_file(path: Path) None

Write the tab’s data to a path.

Not implement in the base tab.

Parameters:

path – An path at which to save the file