config

package
v2.0.0-...-bc2b1ed Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RTColorscheme  = 0
	RTSyntax       = 1
	RTHelp         = 2
	RTPlugin       = 3
	RTSyntaxHeader = 4
)
View Source
const CorePluginName = "micro"

CorePluginName is a plugin dependency name for the micro core.

View Source
const (
	DoubleClickThreshold = 400 // How many milliseconds to wait before a second click is not a double click
)

Variables

View Source
var (
	ErrMissingName = errors.New("Missing or empty name field")
	ErrMissingDesc = errors.New("Missing or empty description field")
	ErrMissingSite = errors.New("Missing or empty website field")
)
View Source
var (
	ErrInvalidOption = errors.New("Invalid option")
	ErrInvalidValue  = errors.New("Invalid value")

	// The options that the user can set
	GlobalSettings map[string]interface{}

	// ModifiedSettings is a map of settings which should be written to disk
	// because they have been modified by the user in this session
	ModifiedSettings map[string]bool
)
View Source
var Autosave chan bool
View Source
var Bindings map[string]map[string]string
View Source
var Colorscheme map[string]tcell.Style

Colorscheme is the current colorscheme

View Source
var ConfigDir string
View Source
var DefStyle tcell.Style = tcell.StyleDefault

DefStyle is Micro's default style

View Source
var DefaultGlobalOnlySettings = map[string]interface{}{
	"autosave":       float64(0),
	"clipboard":      "external",
	"colorscheme":    "good",
	"divchars":       "|-",
	"divreverse":     true,
	"fakecursor":     false,
	"infobar":        true,
	"keymenu":        false,
	"mouse":          true,
	"multiopen":      "tab",
	"parsecursor":    false,
	"paste":          false,
	"pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
	"pluginrepos":    []string{},
	"savehistory":    true,
	"scrollbarchar":  "|",
	"sucmd":          "sudo",
	"tabhighlight":   false,
	"tabreverse":     true,
	"xterm":          false,
}

a list of settings that should only be globally modified and their default values

View Source
var ErrNoSuchFunction = errors.New("No such function exists")

ErrNoSuchFunction is returned when Call is executed on a function that does not exist

View Source
var LocalSettings = []string{
	"filetype",
	"readonly",
}

a list of settings that should never be globally modified

View Source
var (
	NumTypes = 5 // How many filetypes are there
)
View Source
var Plugins []*Plugin

Plugins is a list of all detected plugins (enabled or disabled)

Functions

func AddRealRuntimeFile

func AddRealRuntimeFile(fileType RTFiletype, file RuntimeFile)

AddRealRuntimeFile registers a file for the given filetype

func AddRuntimeFile

func AddRuntimeFile(fileType RTFiletype, file RuntimeFile)

AddRuntimeFile registers a file for the given filetype

func AddRuntimeFilesFromAssets

func AddRuntimeFilesFromAssets(fileType RTFiletype, directory, pattern string)

AddRuntimeFilesFromAssets registers each file from the given asset-directory for the filetype which matches the file-pattern

func AddRuntimeFilesFromDirectory

func AddRuntimeFilesFromDirectory(fileType RTFiletype, directory, pattern string)

AddRuntimeFilesFromDirectory registers each file from the given directory for the filetype which matches the file-pattern

func ColorschemeExists

func ColorschemeExists(colorschemeName string) bool

ColorschemeExists checks if a given colorscheme exists

func DefaultAllSettings

func DefaultAllSettings() map[string]interface{}

DefaultAllSettings returns a map of all settings and their default values (both common and global settings)

func DefaultCommonSettings

func DefaultCommonSettings() map[string]interface{}

DefaultCommonSettings returns the default global settings for micro Note that colorscheme is a global only option

func DefaultGlobalSettings

func DefaultGlobalSettings() map[string]interface{}

DefaultGlobalSettings returns the default global settings for micro Note that colorscheme is a global only option

func GetAutoTime

func GetAutoTime() int

func GetColor

func GetColor(color string) tcell.Style

GetColor takes in a syntax group and returns the colorscheme's style for that group

func GetColor256

func GetColor256(color int) tcell.Color

GetColor256 returns the tcell color for a number between 0 and 255

func GetGlobalOption

func GetGlobalOption(name string) interface{}

GetGlobalOption returns the global value of the given option

func GetInfoBarOffset

func GetInfoBarOffset() int

func GetInstalledPluginVersion

func GetInstalledPluginVersion(name string) string

GetInstalledPluginVersion returns the string of the exported VERSION variable of a loaded plugin

func GetNativeValue

func GetNativeValue(option string, realValue interface{}, value string) (interface{}, error)

GetNativeValue parses and validates a value for a given option

func InitColorscheme

func InitColorscheme() error

InitColorscheme picks and initializes the colorscheme when micro starts

func InitConfigDir

func InitConfigDir(flagConfigDir string) error

InitConfigDir finds the configuration directory for micro according to the XDG spec. If no directory is found, it creates one.

func InitGlobalSettings

func InitGlobalSettings() error

InitGlobalSettings initializes the options map and sets all options to their default values Must be called after ReadSettings

func InitLocalSettings

func InitLocalSettings(settings map[string]interface{}, path string) error

InitLocalSettings scans the json in settings.json and sets the options locally based on whether the filetype or path matches ft or glob local settings Must be called after ReadSettings

func InitRuntimeFiles

func InitRuntimeFiles()

InitRuntimeFiles initializes all assets file and the config directory

func LoadAllPlugins

func LoadAllPlugins() error

LoadAllPlugins loads all detected plugins (in runtime/plugins and ConfigDir/plugins)

func LoadColorscheme

func LoadColorscheme(colorschemeName string) error

LoadColorscheme loads the given colorscheme from a directory

func LoadDefaultColorscheme

func LoadDefaultColorscheme() error

LoadDefaultColorscheme loads the default colorscheme from $(ConfigDir)/colorschemes

func NewRTFiletype

func NewRTFiletype() int

NewRTFiletype creates a new RTFiletype

func OptionIsValid

func OptionIsValid(option string, value interface{}) error

OptionIsValid checks if a value is valid for a certain option

func OverwriteSettings

func OverwriteSettings(filename string) error

OverwriteSettings writes the current settings to settings.json and resets any user configuration of local settings present in settings.json

func ParseColorscheme

func ParseColorscheme(text string) (map[string]tcell.Style, error)

ParseColorscheme parses the text definition for a colorscheme and returns the corresponding object Colorschemes are made up of color-link statements linking a color group to a list of colors For example, color-link keyword (blue,red) makes all keywords have a blue foreground and red background

func PluginAddRuntimeFile

func PluginAddRuntimeFile(plugin string, filetype RTFiletype, filePath string) error

PluginAddRuntimeFile adds a file to the runtime files for a plugin

func PluginAddRuntimeFileFromMemory

func PluginAddRuntimeFileFromMemory(filetype RTFiletype, filename, data string)

PluginAddRuntimeFileFromMemory adds a file to the runtime files for a plugin from a given string

func PluginAddRuntimeFilesFromDirectory

func PluginAddRuntimeFilesFromDirectory(plugin string, filetype RTFiletype, directory, pattern string) error

PluginAddRuntimeFilesFromDirectory adds files from a directory to the runtime files for a plugin

func PluginCommand

func PluginCommand(out io.Writer, cmd string, args []string)

func PluginListRuntimeFiles

func PluginListRuntimeFiles(fileType RTFiletype) []string

PluginListRuntimeFiles allows plugins to lists all runtime files of the given type

func PluginReadRuntimeFile

func PluginReadRuntimeFile(fileType RTFiletype, name string) string

PluginReadRuntimeFile allows plugin scripts to read the content of a runtime file

func ReadSettings

func ReadSettings() error

func RegisterCommonOption

func RegisterCommonOption(name string, defaultvalue interface{}) error

RegisterCommonOption creates a new option

func RegisterCommonOptionPlug

func RegisterCommonOptionPlug(pl string, name string, defaultvalue interface{}) error

RegisterCommonOptionPlug creates a new option (called pl.name). This is meant to be called by plugins to add options.

func RegisterGlobalOption

func RegisterGlobalOption(name string, defaultvalue interface{}) error

RegisterGlobalOption creates a new global-only option

func RegisterGlobalOptionPlug

func RegisterGlobalOptionPlug(pl string, name string, defaultvalue interface{}) error

RegisterGlobalOptionPlug creates a new global-only option (named pl.name)

func RunPluginFn

func RunPluginFn(fn string, args ...lua.LValue) error

RunPluginFn runs a given function in all plugins returns an error if any of the plugins had an error

func RunPluginFnBool

func RunPluginFnBool(settings map[string]interface{}, fn string, args ...lua.LValue) (bool, error)

RunPluginFnBool runs a function in all plugins and returns false if any one of them returned false also returns an error if any of the plugins had an error

func SetAutoTime

func SetAutoTime(a int)

func StartAutoSave

func StartAutoSave()

func StringToColor

func StringToColor(str string) (tcell.Color, bool)

StringToColor returns a tcell color from a string representation of a color We accept either bright... or light... to mean the brighter version of a color

func StringToStyle

func StringToStyle(str string) tcell.Style

StringToStyle returns a style from a string The strings must be in the format "extra foregroundcolor,backgroundcolor" The 'extra' can be bold, reverse, italic or underline

func UninstallPlugin

func UninstallPlugin(out io.Writer, name string)

UninstallPlugin deletes the plugin folder of the given plugin

func UpdatePlugins

func UpdatePlugins(out io.Writer, plugins []string)

UpdatePlugins updates the given plugins

func WriteSettings

func WriteSettings(filename string) error

WriteSettings writes the settings to the specified filename as JSON

Types

type Plugin

type Plugin struct {
	DirName string        // name of plugin folder
	Name    string        // name of plugin
	Info    *PluginInfo   // json file containing info
	Srcs    []RuntimeFile // lua files
	Loaded  bool
	Default bool // pre-installed plugin
}

Plugin stores information about the source files/info for a plugin

func FindAnyPlugin

func FindAnyPlugin(name string) *Plugin

FindAnyPlugin does not require the plugin to be enabled

func FindPlugin

func FindPlugin(name string) *Plugin

FindPlugin returns the plugin with the given name

func (*Plugin) Call

func (p *Plugin) Call(fn string, args ...lua.LValue) (lua.LValue, error)

Call calls a given function in this plugin

func (*Plugin) IsLoaded

func (p *Plugin) IsLoaded() bool

IsLoaded returns if a plugin is enabled

func (*Plugin) Load

func (p *Plugin) Load() error

Load creates an option for the plugin and runs all source files

type PluginChannel

type PluginChannel string

PluginChannel contains an url to a json list of PluginRepository

func (PluginChannel) Fetch

func (pc PluginChannel) Fetch(out io.Writer) PluginPackages

Fetch retrieves all available PluginPackages from the given channel

type PluginChannels

type PluginChannels []PluginChannel

PluginChannels is a slice of PluginChannel

func (PluginChannels) Fetch

func (pc PluginChannels) Fetch(out io.Writer) PluginPackages

Fetch retrieves all available PluginPackages from the given channels

type PluginDependencies

type PluginDependencies []*PluginDependency

PluginDependencies is a slice of PluginDependency

func (PluginDependencies) Join

type PluginDependency

type PluginDependency struct {
	Name  string
	Range semver.Range
}

PluginDependency descripes a dependency to another plugin or micro itself.

type PluginInfo

type PluginInfo struct {
	Name string `json:"Name"`
	Desc string `json:"Description"`
	Site string `json:"Website"`
}

PluginInfo contains all the needed info about a plugin The info is just strings and are not used beyond that (except the Site and Install fields should be valid URLs). This means that the requirements for example can be formatted however the plugin maker decides, the fields will only be parsed by humans Name: name of plugin Desc: description of plugin Site: home website of plugin Install: install link for plugin (can be link to repo or zip file) Vstr: version Require: list of dependencies and requirements

func NewPluginInfo

func NewPluginInfo(data []byte) (*PluginInfo, error)

NewPluginInfo parses a JSON input into a valid PluginInfo struct Returns an error if there are any missing fields or any invalid fields There are no optional fields in a plugin info json file

type PluginPackage

type PluginPackage struct {
	Name        string
	Description string
	Author      string
	Tags        []string
	Versions    PluginVersions
}

PluginPackage contains the meta-data of a plugin and all available versions

func (PluginPackage) Install

func (pl PluginPackage) Install(out io.Writer)

Install installs the plugin

func (PluginPackage) IsInstallable

func (pp PluginPackage) IsInstallable(out io.Writer) error

IsInstallable returns true if the package can be installed.

func (PluginPackage) Match

func (pp PluginPackage) Match(text string) bool

Match returns true if the package matches a given search text

func (*PluginPackage) String

func (pp *PluginPackage) String() string

func (*PluginPackage) UnmarshalJSON

func (pp *PluginPackage) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals raw json to a PluginPackage

type PluginPackages

type PluginPackages []*PluginPackage

PluginPackages is a list of PluginPackage instances.

func GetAllPluginPackages

func GetAllPluginPackages(out io.Writer) PluginPackages

GetAllPluginPackages gets all PluginPackages which may be available.

func SearchPlugin

func SearchPlugin(out io.Writer, texts []string) (plugins PluginPackages)

SearchPlugin retrieves a list of all PluginPackages which match the given search text and could be or are already installed

func (PluginPackages) Get

func (pl PluginPackages) Get(name string) *PluginPackage

func (PluginPackages) GetAllVersions

func (pl PluginPackages) GetAllVersions(name string) PluginVersions

func (PluginPackages) Resolve

func (all PluginPackages) Resolve(selectedVersions PluginVersions, open PluginDependencies) (PluginVersions, error)

Resolve resolves dependencies between different plugins

type PluginRepository

type PluginRepository string

PluginRepository contains an url to json file containing PluginPackages

func (PluginRepository) Fetch

func (pr PluginRepository) Fetch(out io.Writer) PluginPackages

Fetch retrieves all available PluginPackages from the given repository

type PluginVersion

type PluginVersion struct {
	Version semver.Version
	Url     string
	Require PluginDependencies
	// contains filtered or unexported fields
}

PluginVersion descripes a version of a PluginPackage. Containing a version, download url and also dependencies.

func (*PluginVersion) DownloadAndInstall

func (pv *PluginVersion) DownloadAndInstall(out io.Writer) error

DownloadAndInstall downloads and installs the given plugin and version

func (*PluginVersion) Pack

func (pv *PluginVersion) Pack() *PluginPackage

func (*PluginVersion) UnmarshalJSON

func (pv *PluginVersion) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals raw json to a PluginVersion

type PluginVersions

type PluginVersions []*PluginVersion

PluginVersions is a slice of PluginVersion

func GetInstalledVersions

func GetInstalledVersions(withCore bool) PluginVersions

GetInstalledVersions returns a list of all currently installed plugins including an entry for micro itself. This can be used to resolve dependencies.

func (PluginVersions) Len

func (pv PluginVersions) Len() int

Len returns the number of pluginversions in this slice

func (PluginVersions) Less

func (pv PluginVersions) Less(i, j int) bool

Less returns true if the version at position i is greater then the version at position j (used for sorting)

func (PluginVersions) Swap

func (pv PluginVersions) Swap(i, j int)

Swap two entries of the slice

type RTFiletype

type RTFiletype int

type RuntimeFile

type RuntimeFile interface {
	// Name returns a name of the file without paths or extensions
	Name() string
	// Data returns the content of the file.
	Data() ([]byte, error)
}

RuntimeFile allows the program to read runtime data like colorschemes or syntax files

func FindRuntimeFile

func FindRuntimeFile(fileType RTFiletype, name string) RuntimeFile

FindRuntimeFile finds a runtime file of the given filetype and name will return nil if no file was found

func ListRealRuntimeFiles

func ListRealRuntimeFiles(fileType RTFiletype) []RuntimeFile

ListRealRuntimeFiles lists all real runtime files (on disk) for a filetype these runtime files will be ones defined by the user and loaded from the config directory

func ListRuntimeFiles

func ListRuntimeFiles(fileType RTFiletype) []RuntimeFile

ListRuntimeFiles lists all known runtime files for the given filetype

Jump to

Keyboard shortcuts

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