plugin

package
v0.0.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2025 License: MIT Imports: 7 Imported by: 0

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

type CommandFunc func(args []string) error

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) // Add Replace for substitution command

	// --- 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

}

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 NewManager

func NewManager() *Manager

NewManager creates a new plugin manager.

func (*Manager) GetPlugin

func (m *Manager) GetPlugin(name string) (Plugin, bool)

GetPlugin returns a registered plugin by name (e.g., for inter-plugin communication). Use cautiously.

func (*Manager) InitializePlugins

func (m *Manager) InitializePlugins(api EditorAPI)

InitializePlugins iterates through registered plugins and calls their Init method. It requires the EditorAPI instance to be provided.

func (*Manager) Register

func (m *Manager) Register(plugin Plugin) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL