Launch Week Day 3: Introducing Organization Notifications in Socket.Learn More
Socket
Book a DemoSign in
Socket

github.com/ispapp/psshclient/pkg/codeditor

Package Overview
Dependencies
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/ispapp/psshclient/pkg/codeditor

Source
Go Modules
Version
v0.0.0-20250902152542-4644bae162f7
Version published
Created
Source

codeditor

A powerful, customizable code editor widget for Fyne applications with syntax highlighting and VS Code-style theme support.

Features

  • Syntax Highlighting: Support for multiple programming languages including Go, Python, JavaScript, Java, C/C++
  • VS Code-Style Themes: Built-in themes (Dark, Light, VS Code Dark, Monokai) with JSON theme loading support
  • Customizable: Font size, tab size, line numbers, and more
  • Keyboard Navigation: Full cursor movement, text editing, and selection support
  • Extensible: Easy to add new languages and themes

Installation

go get github.com/ispapp/psshclient/pkg/codeditor

Quick Start

package main

import (
    "fyne.io/fyne/v2/app"
    editor "github.com/ispapp/psshclient/pkg/codeditor"
)

func main() {
    myApp := app.New()
    myWindow := myApp.NewWindow("Code Editor")
    
    // Create a new code editor
    codeEditor := editor.NewScriptEditor()
    codeEditor.SetLanguage("go")
    codeEditor.SetContent(`package main

import "fmt"

func main() {
    fmt.Println("Hello, World!")
}`)
    
    myWindow.SetContent(codeEditor)
    myWindow.ShowAndRun()
}

API Reference

Creating an Editor

// Create a new editor with default settings
editor := NewScriptEditor()

// Create with specific language and theme
editor := CreateCodeEditor("python", GetVSCodeDarkTheme())

// Create with initial content
editor := CreateCodeEditorWithContent(code, "go", GetDefaultTheme())

Content Management

// Set and get content
editor.SetContent("your code here")
content := editor.GetContent()

// Listen for changes
editor.SetOnChanged(func(content string) {
    // Handle content changes
    fmt.Println("Content changed:", len(content), "characters")
})

Language Support

// Set programming language for syntax highlighting
editor.SetLanguage("go")        // Go
editor.SetLanguage("python")    // Python
editor.SetLanguage("javascript") // JavaScript
editor.SetLanguage("java")      // Java
editor.SetLanguage("c")         // C
editor.SetLanguage("cpp")       // C++

// Get current language
language := editor.GetLanguage()

Theme Customization

// Use built-in themes
editor.SetTheme(GetDefaultTheme())    // Dark theme
editor.SetTheme(GetLightTheme())      // Light theme
editor.SetTheme(GetVSCodeDarkTheme()) // VS Code Dark
editor.SetTheme(GetMonokaiTheme())    // Monokai

// Load theme from JSON file
theme, err := LoadThemeFromJSON("my-theme.json")
if err == nil {
    editor.SetTheme(theme)
}

Appearance Settings

// Font size
editor.SetFontSize(14.0)
size := editor.GetFontSize()

// Tab size
editor.SetTabSize(4)
tabSize := editor.GetTabSize()

// Line numbers
editor.SetShowLineNumbers(true)
showLines := editor.GetShowLineNumbers()

Theme Format

Themes can be defined in JSON format:

{
  "name": "My Custom Theme",
  "background": "#1e1e1e",
  "foreground": "#d4d4d4",
  "tokenColors": {
    "keyword": "#569cd6",
    "string": "#ce9178",
    "comment": "#6a9955",
    "number": "#b5cea8",
    "operator": "#d4d4d4",
    "identifier": "#9cdcfe",
    "function": "#dcdcaa",
    "type": "#4ec9b0",
    "plain": "#d4d4d4"
  }
}

Saving Themes

// Save a theme to JSON file
theme := GetMonokaiTheme()
err := SaveThemeToJSON(theme, "monokai-theme.json")

Supported Languages

  • Go: Full syntax highlighting with keywords, types, functions, and more
  • Python: Support for Python 3 syntax including decorators, f-strings, and async/await
  • JavaScript: ES6+ support with classes, arrow functions, template literals
  • Java: Complete Java syntax highlighting
  • C/C++: Support for both C and C++ with preprocessor directives
  • Generic: Basic highlighting for unknown languages

Keyboard Controls

  • Arrow Keys: Navigate cursor
  • Home/End: Move to line start/end
  • Backspace/Delete: Delete characters
  • Tab: Insert spaces (configurable tab size)
  • Enter: Insert new line

Examples

See the example.go file for a complete demonstration including:

  • Theme switching
  • Language selection
  • Font size adjustment
  • Line number toggle
  • Different code samples

Extending the Editor

Adding New Languages

  • Add language-specific rules in lexer.go
  • Create a new initialize[Language]Rules() method
  • Add the language to the switch statement in initializeRules()

Creating Custom Themes

  • Create a new Theme struct with your colors
  • Use SaveThemeToJSON() to export as JSON
  • Load with LoadThemeFromJSON() for reuse

Architecture

The widget follows Fyne's architecture patterns:

  • ScriptEditor: Main widget implementing fyne.Widget
  • scriptEditorRenderer: Custom renderer implementing fyne.WidgetRenderer
  • Lexer: Tokenizes code for syntax highlighting
  • Theme: Defines colors for different token types

Contributing

  • Fork the repository
  • Create a feature branch
  • Add tests for new functionality
  • Submit a pull request

License

This project is licensed under the same license as the parent project.

FAQs

Package last updated on 02 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts