code

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DarkTheme = &Theme{
		Name:           "Dark",
		Background:     color.RGBA{30, 30, 30, 255},
		Foreground:     color.RGBA{212, 212, 212, 255},
		Selection:      color.RGBA{38, 79, 120, 255},
		LineNumber:     color.RGBA{133, 133, 133, 255},
		CurrentLine:    color.RGBA{40, 40, 40, 255},
		Comment:        color.RGBA{106, 153, 85, 255},
		Keyword:        color.RGBA{86, 156, 214, 255},
		String:         color.RGBA{206, 145, 120, 255},
		Number:         color.RGBA{181, 206, 168, 255},
		Function:       color.RGBA{220, 220, 170, 255},
		Operator:       color.RGBA{212, 212, 212, 255},
		Error:          color.RGBA{244, 71, 71, 255},
		Warning:        color.RGBA{255, 193, 7, 255},
		ScrollBarThumb: color.RGBA{79, 79, 79, 255},
		ScrollBarTrack: color.RGBA{51, 51, 51, 255},
	}

	LightTheme = &Theme{
		Name:           "Light",
		Background:     color.RGBA{255, 255, 255, 255},
		Foreground:     color.RGBA{0, 0, 0, 255},
		Selection:      color.RGBA{173, 214, 255, 255},
		LineNumber:     color.RGBA{149, 149, 149, 255},
		CurrentLine:    color.RGBA{245, 245, 245, 255},
		Comment:        color.RGBA{0, 128, 0, 255},
		Keyword:        color.RGBA{0, 0, 255, 255},
		String:         color.RGBA{163, 21, 21, 255},
		Number:         color.RGBA{9, 134, 88, 255},
		Function:       color.RGBA{121, 94, 38, 255},
		Operator:       color.RGBA{0, 0, 0, 255},
		Error:          color.RGBA{255, 0, 0, 255},
		Warning:        color.RGBA{255, 140, 0, 255},
		ScrollBarThumb: color.RGBA{196, 196, 196, 255},
		ScrollBarTrack: color.RGBA{240, 240, 240, 255},
	}

	MonokaiTheme = &Theme{
		Name:           "Monokai",
		Background:     color.RGBA{39, 40, 34, 255},
		Foreground:     color.RGBA{248, 248, 242, 255},
		Selection:      color.RGBA{73, 72, 62, 255},
		LineNumber:     color.RGBA{144, 144, 144, 255},
		CurrentLine:    color.RGBA{49, 50, 44, 255},
		Comment:        color.RGBA{117, 113, 94, 255},
		Keyword:        color.RGBA{249, 38, 114, 255},
		String:         color.RGBA{230, 219, 116, 255},
		Number:         color.RGBA{174, 129, 255, 255},
		Function:       color.RGBA{166, 226, 46, 255},
		Operator:       color.RGBA{249, 38, 114, 255},
		Error:          color.RGBA{244, 71, 71, 255},
		Warning:        color.RGBA{255, 193, 7, 255},
		ScrollBarThumb: color.RGBA{79, 79, 79, 255},
		ScrollBarTrack: color.RGBA{51, 51, 51, 255},
	}

	SolarizedDarkTheme = &Theme{
		Name:           "Solarized Dark",
		Background:     color.RGBA{0, 43, 54, 255},
		Foreground:     color.RGBA{131, 148, 150, 255},
		Selection:      color.RGBA{7, 54, 66, 255},
		LineNumber:     color.RGBA{88, 110, 117, 255},
		CurrentLine:    color.RGBA{7, 54, 66, 255},
		Comment:        color.RGBA{88, 110, 117, 255},
		Keyword:        color.RGBA{38, 139, 210, 255},
		String:         color.RGBA{42, 161, 152, 255},
		Number:         color.RGBA{211, 54, 130, 255},
		Function:       color.RGBA{181, 137, 0, 255},
		Operator:       color.RGBA{131, 148, 150, 255},
		Error:          color.RGBA{220, 50, 47, 255},
		Warning:        color.RGBA{203, 75, 22, 255},
		ScrollBarThumb: color.RGBA{79, 79, 79, 255},
		ScrollBarTrack: color.RGBA{51, 51, 51, 255},
	}
)

Predefined themes

Available themes

Functions

func GetSupportedLanguages

func GetSupportedLanguages() []string

GetSupportedLanguages returns a list of supported programming languages

func GetThemeNames

func GetThemeNames() []string

GetThemeNames returns a list of available theme names

Types

type CodeEditor

type CodeEditor struct {
	widget.BaseWidget
	// contains filtered or unexported fields
}

CodeEditor represents the main code editor widget

func NewCodeEditor

func NewCodeEditor(theme *Theme, language string) *CodeEditor

NewCodeEditor creates a new code editor with the specified theme and language

func (*CodeEditor) CommentToggle

func (e *CodeEditor) CommentToggle()

CommentToggle toggles line comments for the current line or selection

func (*CodeEditor) CreateRenderer

func (e *CodeEditor) CreateRenderer() fyne.WidgetRenderer

CreateRenderer creates the widget renderer

func (*CodeEditor) FindAndReplace

func (e *CodeEditor) FindAndReplace(find, replace string, replaceAll bool) int

FindAndReplace provides find and replace functionality

func (*CodeEditor) GetCurrentLineNumber

func (e *CodeEditor) GetCurrentLineNumber() int

GetCurrentLineNumber returns the current line number

func (*CodeEditor) GetText

func (e *CodeEditor) GetText() string

GetText returns the editor content

func (*CodeEditor) GetTotalLines

func (e *CodeEditor) GetTotalLines() int

GetTotalLines returns the total number of lines

func (*CodeEditor) GoToLine

func (e *CodeEditor) GoToLine(lineNumber int)

GoToLine moves the cursor to a specific line

func (*CodeEditor) IndentSelection

func (e *CodeEditor) IndentSelection()

IndentSelection indents the selected text or current line

func (*CodeEditor) IsEditMode

func (e *CodeEditor) IsEditMode() bool

IsEditMode returns true if the editor is in edit mode

func (*CodeEditor) Save

func (e *CodeEditor) Save()

Save triggers the save callback if set

func (*CodeEditor) SetAutoIndent

func (e *CodeEditor) SetAutoIndent(auto bool)

SetAutoIndent toggles auto-indentation

func (*CodeEditor) SetFontSize

func (e *CodeEditor) SetFontSize(size float32)

SetFontSize sets the font size

func (*CodeEditor) SetLanguage

func (e *CodeEditor) SetLanguage(language string)

SetLanguage changes the syntax highlighting language

func (*CodeEditor) SetOnSave

func (e *CodeEditor) SetOnSave(callback func(string))

SetOnSave sets the callback for save action

func (*CodeEditor) SetOnTextChanged

func (e *CodeEditor) SetOnTextChanged(callback func(string))

SetOnTextChanged sets the callback for text changes

func (*CodeEditor) SetReadOnly

func (e *CodeEditor) SetReadOnly(readonly bool)

SetReadOnly sets the editor to read-only mode

func (*CodeEditor) SetShowLineNumbers

func (e *CodeEditor) SetShowLineNumbers(show bool)

SetShowLineNumbers toggles line numbers display

func (*CodeEditor) SetTabSize

func (e *CodeEditor) SetTabSize(size int)

SetTabSize sets the tab size

func (*CodeEditor) SetText

func (e *CodeEditor) SetText(text string)

SetText sets the editor content

func (*CodeEditor) SetTheme

func (e *CodeEditor) SetTheme(newTheme *Theme)

SetTheme changes the editor theme

func (*CodeEditor) SetWordWrap

func (e *CodeEditor) SetWordWrap(wrap bool)

SetWordWrap toggles word wrapping

func (*CodeEditor) ToggleMode

func (e *CodeEditor) ToggleMode()

ToggleMode switches between edit and view modes

func (*CodeEditor) UnindentSelection

func (e *CodeEditor) UnindentSelection()

UnindentSelection unindents the selected text or current line

type CodeWidget

type CodeWidget interface {
	fyne.CanvasObject
	CreateRenderer() CodeWidgetRenderer
}

Legacy interface implementations for compatibility

type CodeWidgetRenderer

type CodeWidgetRenderer interface {
	Layout(fyne.Size)
	MinSize() fyne.Size
	Refresh()
	Objects() []fyne.CanvasObject
	Destroy()
}

type EditorSettings

type EditorSettings struct {
	// Appearance
	Theme      string  `json:"theme"`
	FontSize   float32 `json:"fontSize"`
	FontFamily string  `json:"fontFamily"`
	LineHeight float32 `json:"lineHeight"`

	// Editor behavior
	TabSize         int  `json:"tabSize"`
	InsertSpaces    bool `json:"insertSpaces"`
	AutoIndent      bool `json:"autoIndent"`
	WordWrap        bool `json:"wordWrap"`
	ShowLineNumbers bool `json:"showLineNumbers"`
	ShowWhitespace  bool `json:"showWhitespace"`

	// Advanced features
	AutoSave       bool `json:"autoSave"`
	AutoSaveDelay  int  `json:"autoSaveDelay"` // in seconds
	FormatOnSave   bool `json:"formatOnSave"`
	TrimWhitespace bool `json:"trimWhitespace"`

	// Language-specific settings
	LanguageSettings map[string]*LanguageConfig `json:"languageSettings"`

	// Shortcuts (customizable)
	KeyBindings map[string]string `json:"keyBindings"`
}

EditorSettings represents the configuration for the code editor

func DefaultSettings

func DefaultSettings() *EditorSettings

DefaultSettings returns the default editor settings

type KeyboardShortcuts

type KeyboardShortcuts struct {
	// contains filtered or unexported fields
}

KeyboardShortcuts handles VS Code-like keyboard shortcuts

func NewKeyboardShortcuts

func NewKeyboardShortcuts(editor *CodeEditor) *KeyboardShortcuts

NewKeyboardShortcuts creates a new keyboard shortcut handler

func (*KeyboardShortcuts) GetSelectedText

func (ks *KeyboardShortcuts) GetSelectedText() string

GetSelectedText returns the currently selected text

func (*KeyboardShortcuts) HandleKeyEvent

func (ks *KeyboardShortcuts) HandleKeyEvent(event *fyne.KeyEvent) bool

HandleKeyEvent processes keyboard events for shortcuts

func (*KeyboardShortcuts) InsertTextAtCursor

func (ks *KeyboardShortcuts) InsertTextAtCursor(text string)

InsertTextAtCursor inserts text at the current cursor position

func (*KeyboardShortcuts) ReplaceSelectedText

func (ks *KeyboardShortcuts) ReplaceSelectedText(newText string)

ReplaceSelectedText replaces the selected text with new text

type LanguageConfig

type LanguageConfig struct {
	TabSize      int    `json:"tabSize"`
	InsertSpaces bool   `json:"insertSpaces"`
	Formatter    string `json:"formatter"`
	Linter       string `json:"linter"`
	FilePattern  string `json:"filePattern"`
}

LanguageConfig represents language-specific configuration

type SettingsManager

type SettingsManager struct {
	// contains filtered or unexported fields
}

SettingsManager handles loading and saving editor settings

func NewSettingsManager

func NewSettingsManager() *SettingsManager

NewSettingsManager creates a new settings manager

func (*SettingsManager) ApplySettingsToEditor

func (sm *SettingsManager) ApplySettingsToEditor(editor *CodeEditor)

ApplySettingsToEditor applies the settings to a code editor instance

func (*SettingsManager) ExportSettings

func (sm *SettingsManager) ExportSettings() (string, error)

ExportSettings exports settings to a JSON string

func (*SettingsManager) GetLanguageConfig

func (sm *SettingsManager) GetLanguageConfig(language string) *LanguageConfig

GetLanguageConfig returns the configuration for a specific language

func (*SettingsManager) GetSettings

func (sm *SettingsManager) GetSettings() *EditorSettings

GetSettings returns the current settings

func (*SettingsManager) ImportSettings

func (sm *SettingsManager) ImportSettings(jsonData string) error

ImportSettings imports settings from a JSON string

func (*SettingsManager) Load

func (sm *SettingsManager) Load() error

Load loads settings from the configuration file

func (*SettingsManager) ResetToDefaults

func (sm *SettingsManager) ResetToDefaults() error

ResetToDefaults resets all settings to default values

func (*SettingsManager) Save

func (sm *SettingsManager) Save() error

Save saves the current settings to the configuration file

func (*SettingsManager) SetLanguageConfig

func (sm *SettingsManager) SetLanguageConfig(language string, config *LanguageConfig)

SetLanguageConfig sets the configuration for a specific language

func (*SettingsManager) UpdateSettings

func (sm *SettingsManager) UpdateSettings(settings *EditorSettings) error

UpdateSettings updates the settings and saves them

func (*SettingsManager) ValidateSettings

func (sm *SettingsManager) ValidateSettings() []string

ValidateSettings validates the settings for correctness

type Theme

type Theme struct {
	Name           string
	Background     color.Color
	Foreground     color.Color
	Selection      color.Color
	LineNumber     color.Color
	CurrentLine    color.Color
	Comment        color.Color
	Keyword        color.Color
	String         color.Color
	Number         color.Color
	Function       color.Color
	Operator       color.Color
	Error          color.Color
	Warning        color.Color
	ScrollBarThumb color.Color
	ScrollBarTrack color.Color
}

Theme represents a color theme for the code editor

Jump to

Keyboard shortcuts

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