pub struct ScriptHost {
pub errors: Vec<String>,
/* private fields */
}Expand description
Loads TextWrite editor scripts and runs their commands.
Mirrors fast_text_plugin::PluginHost, but backed by the TextWrite
interpreter instead of Rhai.
Fields§
§errors: Vec<String>Errors encountered while loading or running scripts.
Implementations§
Source§impl ScriptHost
impl ScriptHost
Sourcepub fn set_module_dir(&mut self, dir: impl Into<PathBuf>)
pub fn set_module_dir(&mut self, dir: impl Into<PathBuf>)
Sets the directory that relative imports in loaded scripts resolve against (normally the plugin directory).
Sourcepub fn add_script(&mut self, name: &str, source: &str)
pub fn add_script(&mut self, name: &str, source: &str)
Adds a script by name, re-running all loaded scripts.
Sourcepub fn commands(&self) -> Vec<CommandInfo>
pub fn commands(&self) -> Vec<CommandInfo>
Every registered command, sorted by title.
Sourcepub fn command_titles(&self) -> Vec<String>
pub fn command_titles(&self) -> Vec<String>
Registered command titles, sorted.
Sourcepub fn keybindings(&self) -> Vec<(KeySpec, String)>
pub fn keybindings(&self) -> Vec<(KeySpec, String)>
All registered keybindings.
Sourcepub fn themes(&self) -> Vec<(String, Vec<(String, u32)>)>
pub fn themes(&self) -> Vec<(String, Vec<(String, u32)>)>
Every theme defined by a loaded script, as (name, colors).
Sourcepub fn theme_names(&self) -> Vec<String>
pub fn theme_names(&self) -> Vec<String>
The names of every theme defined by a loaded script.
Sourcepub fn lookup_key(&self, key: &KeySpec) -> Option<String>
pub fn lookup_key(&self, key: &KeySpec) -> Option<String>
Finds the command title bound to a key, if any.
Sourcepub fn has_command(&self, title: &str) -> bool
pub fn has_command(&self, title: &str) -> bool
True when a command with this title is registered.
Sourcepub fn run_command(
&mut self,
title: &str,
ctx: &EditorContext,
) -> Vec<EditorAction>
pub fn run_command( &mut self, title: &str, ctx: &EditorContext, ) -> Vec<EditorAction>
Runs a command by title, returning the actions it requested.
Sourcepub fn eval(&mut self, source: &str, ctx: &EditorContext) -> Result<Value>
pub fn eval(&mut self, source: &str, ctx: &EditorContext) -> Result<Value>
Evaluates a snippet of TextWrite against the current editor snapshot.
Actions requested by the snippet are available afterwards via
take_actions.
Sourcepub fn take_actions(&self) -> Vec<EditorAction>
pub fn take_actions(&self) -> Vec<EditorAction>
Takes the actions requested by the most recent eval.
Sourcepub fn has_hook(&self, name: &str) -> bool
pub fn has_hook(&self, name: &str) -> bool
True when a loaded script defines the lifecycle hook name.
Sourcepub fn run_hook(&mut self, name: &str, ctx: &EditorContext) -> Vec<EditorAction>
pub fn run_hook(&mut self, name: &str, ctx: &EditorContext) -> Vec<EditorAction>
Runs a lifecycle hook (on_buffer_open, on_buffer_save, …) against an
editor snapshot, returning the actions it queued.
A missing hook is not an error; a failing hook is recorded in
ScriptHost::errors and produces a message action.
Sourcepub fn compile_file(&mut self, path: &str) -> Result<()>
pub fn compile_file(&mut self, path: &str) -> Result<()>
Compiles a .tw file: parses it and resolves (recursively) every module
it imports, without running anything. The .tw extension is optional.
Sourcepub fn run_file(
&mut self,
path: &str,
ctx: &EditorContext,
) -> Result<Vec<EditorAction>>
pub fn run_file( &mut self, path: &str, ctx: &EditorContext, ) -> Result<Vec<EditorAction>>
Compiles and runs a .tw file against a snapshot of the editor state,
returning the actions it queued. The .tw extension is optional.