Documentation
¶
Overview ¶
internal/plugin/manager.go
internal/plugin/plugin.go
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CommandFunc ¶
CommandFunc defines the signature for commands registered by plugins. It takes arguments (e.g., from user input) and returns an error.
type EditorAPI ¶
type EditorAPI interface {
// --- Buffer Access (Read-Only Preferred) ---
// GetBufferContent(start, end types.Position) ([]byte, error) // Get specific range
GetBufferLines(startLine, endLine int) ([][]byte, error) // Get range of lines
GetBufferLine(line int) ([]byte, error) // Get single line
GetBufferLineCount() int // Get line count
GetBufferFilePath() string // Get current file path
IsBufferModified() bool // Check modified status
GetBufferBytes() []byte
// --- Buffer Modification ---
// Use with caution! Ensure plugins don't corrupt state.
InsertText(pos types.Position, text []byte) error
DeleteRange(start, end types.Position) error
// ReplaceRange(start, end types.Position, text []byte) error // Combine delete/insert
SaveBuffer(filePath ...string) error // Save buffer to file with optional path
Replace(pattern, replacement string, global bool) (int, error) // Replace on current line
ReplaceAll(pattern, replacement string) (int, error) // :%s – replace across entire buffer
ReplaceInRange(pattern, replacement string, startLine, endLine int) (int, error) // :'<,'>s – replace within line range
// --- Cursor & Viewport ---
GetCursor() types.Position
SetCursor(pos types.Position) // Will clamp and scroll
GetViewport() (y, x int) // Get ViewportY, ViewportX
// --- Event Bus Interaction ---
DispatchEvent(eventType event.Type, data interface{})
SubscribeEvent(eventType event.Type, handler event.Handler) // Plugins can listen too
// --- Command Registration ---
RegisterCommand(name string, cmdFunc CommandFunc) error // Allow plugins to expose commands
// --- Status Bar ---
SetStatusMessage(format string, args ...interface{}) // Show temporary messages
// --- Theme Access ---
GetThemeStyle(styleName string) tcell.Style // Get a style from the active theme
SetTheme(name string) error
GetTheme() *theme.Theme
ListThemes() []string
// --- Application Control ---
RequestQuit(force bool) // Signal the application to quit
// --- Buffer Management ---
OpenFile(filePath string)
NextBuffer()
PrevBuffer()
CloseBuffer() error
ForceCloseBuffer()
// --- Configuration ---
// GetPluginConfigValue retrieves a configuration value for a specific plugin.
// Keys within a plugin's config are case-sensitive as defined in the TOML.
// Returns the value and true if found, otherwise nil and false.
GetPluginConfigValue(pluginName, key string) (interface{}, bool)
}
EditorAPI defines the methods plugins can use to interact with the editor core. This acts as a controlled interface, preventing plugins from accessing everything.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles the registration, initialization, and lifecycle of plugins.
func (*Manager) GetPlugin ¶
GetPlugin returns a registered plugin by name (e.g., for inter-plugin communication). Use cautiously.
func (*Manager) InitializePlugins ¶
InitializePlugins iterates through registered plugins and calls their Init method. It requires the EditorAPI instance to be provided.
func (*Manager) Register ¶
Register adds a plugin instance to the manager. This should be called before InitializePlugins.
func (*Manager) ShutdownPlugins ¶
func (m *Manager) ShutdownPlugins()
ShutdownPlugins calls Shutdown on all registered plugins.
type Plugin ¶
type Plugin interface {
// Name returns the unique identifier name of the plugin.
Name() string
// Initialize is called once when the plugin is loaded.
// It receives the EditorAPI to interact with the core.
// Used for setup, subscribing to events, registering commands.
Initialize(api EditorAPI) error
// Shutdown is called once when the editor is closing.
// Used for cleanup tasks.
Shutdown() error
}
Plugin defines the interface that all plugins must implement.