config

package
v1.4.2-0...-d7b39fe Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2020 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RTColorscheme  = 0
	RTSyntax       = 1
	RTHelp         = 2
	RTPlugin       = 3
	RTSyntaxHeader = 4
	NumTypes       = 5 // How many filetypes are there
)
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")
	ErrMissingInstall = errors.New("Missing or empty install field")
	ErrMissingVstr    = errors.New("Missing or empty versions field")
	ErrMissingRequire = errors.New("Missing or empty require 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{}
)
View Source
var Autosave chan bool
View Source
var Bindings map[string]string
View Source
var Colorscheme map[string]tcell.Style

The current colorscheme

View Source
var ConfigDir string

Micro's default style

View Source
var ErrNoSuchFunction = errors.New("No such function exists")
View Source
var Plugins []*Plugin

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 Asset

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

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:

data/
  foo.txt
  img/
    a.png
    b.png

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

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

func AssetNames() []string

AssetNames returns the names of the assets.

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 GetNativeValue

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

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()

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 MustAsset

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 OptionIsValid

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

OptionIsValid checks if a value is valid for a certain option

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 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. This is meant to be called by plugins to add options.

func RegisterGlobalOption

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

func RestoreAsset

func RestoreAsset(dir, name string) error

RestoreAsset restores an asset under the given directory

func RestoreAssets

func RestoreAssets(dir, name string) error

RestoreAssets restores an asset under the given directory recursively

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

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

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
}

func FindPlugin

func FindPlugin(name string) *Plugin

func (*Plugin) Call

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

func (*Plugin) IsEnabled

func (p *Plugin) IsEnabled() bool

func (*Plugin) Load

func (p *Plugin) Load() error

type PluginInfo

type PluginInfo struct {
	Name    string   `json:"name"`
	Desc    string   `json:"description"`
	Site    string   `json:"website"`
	Install string   `json:"install"`
	Vstr    string   `json:"version"`
	Require []string `json:"require"`
}

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 RTFiletype

type RTFiletype byte

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