micro: github.com/zyedidia/micro/internal/config Index | Files

package config

import "github.com/zyedidia/micro/internal/config"


Package Files

autosave.go colorscheme.go config.go globals.go plugin.go plugin_installer.go plugin_manager.go rtfiles.go runtime.go settings.go


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

CorePluginName is a plugin dependency name for the micro core.

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


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")
var (
    ErrInvalidOption = errors.New("Invalid option")
    ErrInvalidValue  = errors.New("Invalid value")

    // The options that the user can set
    GlobalSettings map[string]interface{}
var Autosave chan bool
var Bindings map[string]string
var Colorscheme map[string]tcell.Style

The current colorscheme

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

Micro's default style

var DefaultGlobalOnlySettings = map[string]interface{}{
    "autosave":       float64(0),
    "colorscheme":    "default",
    "infobar":        true,
    "keymenu":        false,
    "mouse":          true,
    "paste":          false,
    "savehistory":    true,
    "sucmd":          "sudo",
    "pluginchannels": []string{"https://raw.githubusercontent.com/micro-editor/plugin-channel/master/channel.json"},
    "pluginrepos":    []string{},
    "xterm":          false,

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

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

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

var LocalSettings = []string{

a list of settings that should never be globally modified

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

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

func AddRealRuntimeFile Uses

func AddRealRuntimeFile(fileType RTFiletype, file RuntimeFile)

AddRealRuntimeFile registers a file for the given filetype

func AddRuntimeFile Uses

func AddRuntimeFile(fileType RTFiletype, file RuntimeFile)

AddRuntimeFile registers a file for the given filetype

func AddRuntimeFilesFromAssets Uses

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 Uses

func AddRuntimeFilesFromDirectory(fileType RTFiletype, directory, pattern string)

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

func Asset Uses

func Asset(name string) ([]byte, error)

Asset loads and returns the asset for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetDir Uses

func AssetDir(name string) ([]string, error)

AssetDir returns the file names below a certain directory embedded in the file by go-bindata. For example if you run go-bindata on data/... and data contains the following hierarchy:


then AssetDir("data") would return []string{"foo.txt", "img"} AssetDir("data/img") would return []string{"a.png", "b.png"} AssetDir("foo.txt") and AssetDir("notexist") would return an error AssetDir("") will return []string{"data"}.

func AssetInfo Uses

func AssetInfo(name string) (os.FileInfo, error)

AssetInfo loads and returns the asset info for the given name. It returns an error if the asset could not be found or could not be loaded.

func AssetNames Uses

func AssetNames() []string

AssetNames returns the names of the assets.

func ColorschemeExists Uses

func ColorschemeExists(colorschemeName string) bool

ColorschemeExists checks if a given colorscheme exists

func DefaultAllSettings Uses

func DefaultAllSettings() map[string]interface{}

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

func DefaultCommonSettings Uses

func DefaultCommonSettings() map[string]interface{}

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

func DefaultGlobalSettings Uses

func DefaultGlobalSettings() map[string]interface{}

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

func GetAutoTime Uses

func GetAutoTime() int

func GetColor Uses

func GetColor(color string) tcell.Style

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

func GetColor256 Uses

func GetColor256(color int) tcell.Color

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

func GetGlobalOption Uses

func GetGlobalOption(name string) interface{}

GetGlobalOption returns the global value of the given option

func GetInfoBarOffset Uses

func GetInfoBarOffset() int

func GetInstalledPluginVersion Uses

func GetInstalledPluginVersion(name string) string

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

func GetNativeValue Uses

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

GetNativeValue parses and validates a value for a given option

func InitColorscheme Uses

func InitColorscheme() error

InitColorscheme picks and initializes the colorscheme when micro starts

func InitConfigDir Uses

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 Uses

func InitGlobalSettings()

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

func InitLocalSettings Uses

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 Uses

func InitRuntimeFiles()

InitRuntimeFiles initializes all assets file and the config directory

func LoadAllPlugins Uses

func LoadAllPlugins() error

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

func LoadColorscheme Uses

func LoadColorscheme(colorschemeName string) error

LoadColorscheme loads the given colorscheme from a directory

func LoadDefaultColorscheme Uses

func LoadDefaultColorscheme() error

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

func MustAsset Uses

func MustAsset(name string) []byte

MustAsset is like Asset but panics when Asset would return an error. It simplifies safe initialization of global variables.

func NewRTFiletype Uses

func NewRTFiletype() int

NewRTFiletype creates a new RTFiletype

func OptionIsValid Uses

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

OptionIsValid checks if a value is valid for a certain option

func OverwriteSettings Uses

func OverwriteSettings(filename string) error

func ParseColorscheme Uses

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 Uses

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

PluginAddRuntimeFile adds a file to the runtime files for a plugin

func PluginAddRuntimeFileFromMemory Uses

func PluginAddRuntimeFileFromMemory(filetype RTFiletype, filename, data string)

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

func PluginAddRuntimeFilesFromDirectory Uses

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 Uses

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

func PluginListRuntimeFiles Uses

func PluginListRuntimeFiles(fileType RTFiletype) []string

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

func PluginReadRuntimeFile Uses

func PluginReadRuntimeFile(fileType RTFiletype, name string) string

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

func ReadSettings Uses

func ReadSettings() error

func RegisterCommonOptionPlug Uses

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 Uses

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

RegisterGlobalOption creates a new global-only option

func RegisterGlobalOptionPlug Uses

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

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

func RestoreAsset Uses

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets Uses

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

func RunPluginFn Uses

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 Uses

func RunPluginFnBool(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 Uses

func SetAutoTime(a int)

func StartAutoSave Uses

func StartAutoSave()

func StringToColor Uses

func StringToColor(str string) tcell.Color

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 Uses

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, or underline

func UninstallPlugin Uses

func UninstallPlugin(out io.Writer, name string)

UninstallPlugin deletes the plugin folder of the given plugin

func UpdatePlugins Uses

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

UpdatePlugins updates the given plugins

func WriteSettings Uses

func WriteSettings(filename string) error

WriteSettings writes the settings to the specified filename as JSON

type Plugin Uses

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 Uses

func FindAnyPlugin(name string) *Plugin

FindAnyPlugin does not require the plugin to be enabled

func FindPlugin Uses

func FindPlugin(name string) *Plugin

FindPlugin returns the plugin with the given name

func (*Plugin) Call Uses

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

Call calls a given function in this plugin

func (*Plugin) IsEnabled Uses

func (p *Plugin) IsEnabled() bool

IsEnabled returns if a plugin is enabled

func (*Plugin) Load Uses

func (p *Plugin) Load() error

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

type PluginChannel Uses

type PluginChannel string

PluginChannel contains an url to a json list of PluginRepository

func (PluginChannel) Fetch Uses

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

Fetch retrieves all available PluginPackages from the given channel

type PluginChannels Uses

type PluginChannels []PluginChannel

PluginChannels is a slice of PluginChannel

func (PluginChannels) Fetch Uses

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

Fetch retrieves all available PluginPackages from the given channels

type PluginDependencies Uses

type PluginDependencies []*PluginDependency

PluginDependencies is a slice of PluginDependency

func (PluginDependencies) Join Uses

func (req PluginDependencies) Join(other PluginDependencies) PluginDependencies

type PluginDependency Uses

type PluginDependency struct {
    Name  string
    Range semver.Range

PluginDependency descripes a dependency to another plugin or micro itself.

type PluginInfo Uses

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 Uses

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 Uses

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 Uses

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

Install installs the plugin

func (PluginPackage) IsInstallable Uses

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

IsInstallable returns true if the package can be installed.

func (PluginPackage) Match Uses

func (pp PluginPackage) Match(text string) bool

Match returns true if the package matches a given search text

func (*PluginPackage) String Uses

func (pp *PluginPackage) String() string

func (*PluginPackage) UnmarshalJSON Uses

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

UnmarshalJSON unmarshals raw json to a PluginPackage

type PluginPackages Uses

type PluginPackages []*PluginPackage

PluginPackages is a list of PluginPackage instances.

func GetAllPluginPackages Uses

func GetAllPluginPackages(out io.Writer) PluginPackages

GetAllPluginPackages gets all PluginPackages which may be available.

func SearchPlugin Uses

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 Uses

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

func (PluginPackages) GetAllVersions Uses

func (pl PluginPackages) GetAllVersions(name string) PluginVersions

func (PluginPackages) Resolve Uses

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

Resolve resolves dependencies between different plugins

type PluginRepository Uses

type PluginRepository string

PluginRepository contains an url to json file containing PluginPackages

func (PluginRepository) Fetch Uses

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

Fetch retrieves all available PluginPackages from the given repository

type PluginVersion Uses

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 Uses

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

DownloadAndInstall downloads and installs the given plugin and version

func (*PluginVersion) Pack Uses

func (pv *PluginVersion) Pack() *PluginPackage

func (*PluginVersion) UnmarshalJSON Uses

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

UnmarshalJSON unmarshals raw json to a PluginVersion

type PluginVersions Uses

type PluginVersions []*PluginVersion

PluginVersions is a slice of PluginVersion

func GetInstalledVersions Uses

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 Uses

func (pv PluginVersions) Len() int

Len returns the number of pluginversions in this slice

func (PluginVersions) Less Uses

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 Uses

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

Swap two entries of the slice

type RTFiletype Uses

type RTFiletype int

type RuntimeFile Uses

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 Uses

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 Uses

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 Uses

func ListRuntimeFiles(fileType RTFiletype) []RuntimeFile

ListRuntimeFiles lists all known runtime files for the given filetype

Package config imports 29 packages (graph) and is imported by 6 packages. Updated 2020-03-25. Refresh now. Tools for package owners.