diff --git a/internal/action/actions.go b/internal/action/actions.go index 94fe3cf7..be2c1c05 100644 --- a/internal/action/actions.go +++ b/internal/action/actions.go @@ -2083,14 +2083,14 @@ func (h *BufPane) LastSplit() bool { return true } -var curmacro []interface{} +var curmacro []any var recordingMacro bool // ToggleMacro toggles recording of a macro func (h *BufPane) ToggleMacro() bool { recordingMacro = !recordingMacro if recordingMacro { - curmacro = []interface{}{} + curmacro = []any{} InfoBar.Message("Recording") } else { InfoBar.Message("Stopped recording") diff --git a/internal/action/bindings.go b/internal/action/bindings.go index c8c6afb2..37517d9b 100644 --- a/internal/action/bindings.go +++ b/internal/action/bindings.go @@ -36,7 +36,7 @@ func createBindingsIfNotExist(fname string) { // InitBindings intializes the bindings map by reading from bindings.json func InitBindings() { - var parsed map[string]interface{} + var parsed map[string]any filename := filepath.Join(config.ConfigDir, "bindings.json") createBindingsIfNotExist(filename) @@ -66,7 +66,7 @@ func InitBindings() { switch val := v.(type) { case string: BindKey(k, val, Binder["buffer"]) - case map[string]interface{}: + case map[string]any: bind, ok := Binder[k] if !ok || bind == nil { screen.TermMessage(fmt.Sprintf("%s is not a valid pane type", k)) @@ -265,7 +265,7 @@ func eventsEqual(e1 Event, e2 Event) bool { // Returns true if the keybinding already existed and a possible error func TryBindKey(k, v string, overwrite bool) (bool, error) { var e error - var parsed map[string]interface{} + var parsed map[string]any filename := filepath.Join(config.ConfigDir, "bindings.json") createBindingsIfNotExist(filename) @@ -318,7 +318,7 @@ func TryBindKey(k, v string, overwrite bool) (bool, error) { // UnbindKey removes the binding for a key from the bindings.json file func UnbindKey(k string) error { var e error - var parsed map[string]interface{} + var parsed map[string]any filename := filepath.Join(config.ConfigDir, "bindings.json") createBindingsIfNotExist(filename) diff --git a/internal/action/bufpane.go b/internal/action/bufpane.go index b4030a95..3f0c4b1e 100644 --- a/internal/action/bufpane.go +++ b/internal/action/bufpane.go @@ -16,7 +16,7 @@ import ( "github.com/zyedidia/micro/v2/internal/util" ) -type BufAction interface{} +type BufAction any // BufKeyAction represents an action bound to a key. type BufKeyAction func(*BufPane) bool @@ -324,7 +324,7 @@ func (h *BufPane) ResizePane(size int) { // error if there is one and returns the aggregate boolean response. // The bufpane is passed as the first argument to the callbacks, // optional args are passed as the next arguments. -func (h *BufPane) PluginCB(cb string, args ...interface{}) bool { +func (h *BufPane) PluginCB(cb string, args ...any) bool { largs := []lua.LValue{luar.New(ulua.L, h)} for _, a := range args { largs = append(largs, luar.New(ulua.L, a)) diff --git a/internal/action/command.go b/internal/action/command.go index dbc3bdf5..d46ae49d 100644 --- a/internal/action/command.go +++ b/internal/action/command.go @@ -569,7 +569,7 @@ func (h *BufPane) NewTabCmd(args []string) { } } -func doSetGlobalOptionNative(option string, nativeValue interface{}) error { +func doSetGlobalOptionNative(option string, nativeValue any) error { if reflect.DeepEqual(config.GlobalSettings[option], nativeValue) { return nil } @@ -628,7 +628,7 @@ func doSetGlobalOptionNative(option string, nativeValue interface{}) error { return nil } -func SetGlobalOptionNative(option string, nativeValue interface{}) error { +func SetGlobalOptionNative(option string, nativeValue any) error { if err := config.OptionIsValid(option, nativeValue); err != nil { return err } @@ -737,7 +737,7 @@ func (h *BufPane) ShowCmd(args []string) { return } - var option interface{} + var option any if opt, ok := h.Buf.Settings[args[0]]; ok { option = opt } else if opt, ok := config.GlobalSettings[args[0]]; ok { diff --git a/internal/action/infocomplete.go b/internal/action/infocomplete.go index b8ee879a..3b90d507 100644 --- a/internal/action/infocomplete.go +++ b/internal/action/infocomplete.go @@ -193,7 +193,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) { inputOpt = strings.TrimSpace(inputOpt) var suggestions []string // localSettings := config.DefaultLocalSettings() - var optionVal interface{} + var optionVal any for k, option := range config.GlobalSettings { if k == inputOpt { optionVal = option diff --git a/internal/action/terminal_supported.go b/internal/action/terminal_supported.go index 702114e2..e24ae71d 100644 --- a/internal/action/terminal_supported.go +++ b/internal/action/terminal_supported.go @@ -14,7 +14,7 @@ const TermEmuSupported = true // if wait is true it will wait for the user to exit by pressing enter once the executable has terminated // if getOutput is true it will redirect the stdout of the process to a pipe which will be passed to the // callback which is a function that takes a string and a list of optional user arguments -func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback func(out string, userargs []interface{}), userargs []interface{}) error { +func RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, callback func(out string, userargs []any), userargs []any) error { args, err := shellquote.Split(input) if err != nil { return err diff --git a/internal/action/terminal_unsupported.go b/internal/action/terminal_unsupported.go index 814825a6..460cee12 100644 --- a/internal/action/terminal_unsupported.go +++ b/internal/action/terminal_unsupported.go @@ -8,6 +8,6 @@ import "errors" const TermEmuSupported = false // RunTermEmulator returns an error for unsupported systems (non-unix systems -func RunTermEmulator(input string, wait bool, getOutput bool, callback func(out string, userargs []interface{}), userargs []interface{}) error { +func RunTermEmulator(input string, wait bool, getOutput bool, callback func(out string, userargs []any), userargs []any) error { return errors.New("Unsupported operating system") } diff --git a/internal/buffer/buffer.go b/internal/buffer/buffer.go index 72f6a8b8..998979b9 100644 --- a/internal/buffer/buffer.go +++ b/internal/buffer/buffer.go @@ -82,7 +82,7 @@ type SharedBuffer struct { toStdout bool // Settings customized by the user - Settings map[string]interface{} + Settings map[string]any // LocalSettings customized by the user for this buffer only LocalSettings map[string]bool @@ -236,7 +236,7 @@ type Buffer struct { // is properly updated when needed. This is a workaround for the fact that // the buffer module cannot directly call the display's API (it would mean // a circular dependency between packages). - OptionCallback func(option string, nativeValue interface{}) + OptionCallback func(option string, nativeValue any) // The display module registers its own GetVisualX function for getting // the correct visual x location of a cursor when softwrap is used. diff --git a/internal/buffer/message.go b/internal/buffer/message.go index 4c8fc35c..f0d12249 100644 --- a/internal/buffer/message.go +++ b/internal/buffer/message.go @@ -84,7 +84,7 @@ func (b *Buffer) ClearAllMessages() { } type Messager interface { - Message(msg ...interface{}) + Message(msg ...any) } var prompt Messager diff --git a/internal/buffer/settings.go b/internal/buffer/settings.go index 9c8b3ce1..48be3306 100644 --- a/internal/buffer/settings.go +++ b/internal/buffer/settings.go @@ -59,7 +59,7 @@ func (b *Buffer) ReloadSettings(reloadFiletype bool) { } } -func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) { +func (b *Buffer) DoSetOptionNative(option string, nativeValue any) { oldValue := b.Settings[option] if reflect.DeepEqual(oldValue, nativeValue) { return @@ -138,7 +138,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) { b.doCallbacks(option, oldValue, nativeValue) } -func (b *Buffer) SetOptionNative(option string, nativeValue interface{}) error { +func (b *Buffer) SetOptionNative(option string, nativeValue any) error { if err := config.OptionIsValid(option, nativeValue); err != nil { return err } @@ -163,7 +163,7 @@ func (b *Buffer) SetOption(option, value string) error { return b.SetOptionNative(option, nativeValue) } -func (b *Buffer) doCallbacks(option string, oldValue interface{}, newValue interface{}) { +func (b *Buffer) doCallbacks(option string, oldValue any, newValue any) { if b.OptionCallback != nil { b.OptionCallback(option, newValue) } diff --git a/internal/config/plugin.go b/internal/config/plugin.go index b77e3f62..12a2c968 100644 --- a/internal/config/plugin.go +++ b/internal/config/plugin.go @@ -42,7 +42,7 @@ func RunPluginFn(fn string, args ...lua.LValue) 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 RunPluginFnBool(settings map[string]interface{}, fn string, args ...lua.LValue) (bool, error) { +func RunPluginFnBool(settings map[string]any, fn string, args ...lua.LValue) (bool, error) { var reterr error retbool := true for _, p := range Plugins { diff --git a/internal/config/plugin_installer.go b/internal/config/plugin_installer.go index 04e7e15f..85899852 100644 --- a/internal/config/plugin_installer.go +++ b/internal/config/plugin_installer.go @@ -228,7 +228,7 @@ func GetAllPluginPackages(out io.Writer) PluginPackages { if strs, ok := data.([]string); ok { return strs } - if ifs, ok := data.([]interface{}); ok { + if ifs, ok := data.([]any); ok { result := make([]string, len(ifs)) for i, urlIf := range ifs { if url, ok := urlIf.(string); ok { diff --git a/internal/config/settings.go b/internal/config/settings.go index c087ced8..edfa76c0 100644 --- a/internal/config/settings.go +++ b/internal/config/settings.go @@ -17,7 +17,7 @@ import ( "golang.org/x/text/encoding/htmlindex" ) -type optionValidator func(string, interface{}) error +type optionValidator func(string, any) error // a list of settings that need option validators var optionValidators = map[string]optionValidator{ @@ -52,7 +52,7 @@ var OptionChoices = map[string][]string{ // a list of settings that can be globally and locally modified and their // default values -var defaultCommonSettings = map[string]interface{}{ +var defaultCommonSettings = map[string]any{ "autoindent": true, "autosu": false, "backup": true, @@ -108,7 +108,7 @@ var defaultCommonSettings = map[string]interface{}{ // a list of settings that should only be globally modified and their // default values -var DefaultGlobalOnlySettings = map[string]interface{}{ +var DefaultGlobalOnlySettings = map[string]any{ "autosave": float64(0), "clipboard": "external", "colorscheme": "default", @@ -143,10 +143,10 @@ var ( ErrInvalidValue = errors.New("Invalid value") // The options that the user can set - GlobalSettings map[string]interface{} + GlobalSettings map[string]any // This is the raw parsed json - parsedSettings map[string]interface{} + parsedSettings map[string]any settingsParseError bool // ModifiedSettings is a map of settings which should be written to disk @@ -173,11 +173,11 @@ func validateParsedSettings() error { for k, v := range parsedSettings { if strings.HasPrefix(reflect.TypeOf(v).String(), "map") { if strings.HasPrefix(k, "ft:") { - for k1, v1 := range v.(map[string]interface{}) { + for k1, v1 := range v.(map[string]any) { if _, ok := defaults[k1]; ok { if e := verifySetting(k1, v1, defaults[k1]); e != nil { err = e - parsedSettings[k].(map[string]interface{})[k1] = defaults[k1] + parsedSettings[k].(map[string]any)[k1] = defaults[k1] continue } } @@ -188,11 +188,11 @@ func validateParsedSettings() error { delete(parsedSettings, k) continue } - for k1, v1 := range v.(map[string]interface{}) { + for k1, v1 := range v.(map[string]any) { if _, ok := defaults[k1]; ok { if e := verifySetting(k1, v1, defaults[k1]); e != nil { err = e - parsedSettings[k].(map[string]interface{})[k1] = defaults[k1] + parsedSettings[k].(map[string]any)[k1] = defaults[k1] continue } } @@ -225,7 +225,7 @@ func validateParsedSettings() error { } func ReadSettings() error { - parsedSettings = make(map[string]interface{}) + parsedSettings = make(map[string]any) filename := filepath.Join(ConfigDir, "settings.json") if _, e := os.Stat(filename); e == nil { input, err := os.ReadFile(filename) @@ -249,16 +249,16 @@ func ReadSettings() error { return nil } -func ParsedSettings() map[string]interface{} { - s := make(map[string]interface{}) +func ParsedSettings() map[string]any { + s := make(map[string]any) for k, v := range parsedSettings { s[k] = v } return s } -func verifySetting(option string, value interface{}, def interface{}) error { - var interfaceArr []interface{} +func verifySetting(option string, value any, def any) error { + var interfaceArr []any valType := reflect.TypeOf(value) defType := reflect.TypeOf(def) assignable := false @@ -303,12 +303,12 @@ func InitGlobalSettings() error { // UpdatePathGlobLocals scans the already parsed settings and sets the options locally // based on whether the path matches a glob // Must be called after ReadSettings -func UpdatePathGlobLocals(settings map[string]interface{}, path string) { +func UpdatePathGlobLocals(settings map[string]any, path string) { for k, v := range parsedSettings { if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && !strings.HasPrefix(k, "ft:") { g, _ := glob.Compile(k) if g.MatchString(path) { - for k1, v1 := range v.(map[string]interface{}) { + for k1, v1 := range v.(map[string]any) { settings[k1] = v1 } } @@ -319,11 +319,11 @@ func UpdatePathGlobLocals(settings map[string]interface{}, path string) { // UpdateFileTypeLocals scans the already parsed settings and sets the options locally // based on whether the filetype matches to "ft:" // Must be called after ReadSettings -func UpdateFileTypeLocals(settings map[string]interface{}, filetype string) { +func UpdateFileTypeLocals(settings map[string]any, filetype string) { for k, v := range parsedSettings { if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && strings.HasPrefix(k, "ft:") { if filetype == k[3:] { - for k1, v1 := range v.(map[string]interface{}) { + for k1, v1 := range v.(map[string]any) { if k1 != "filetype" { settings[k1] = v1 } @@ -377,7 +377,7 @@ func WriteSettings(filename string) error { // OverwriteSettings writes the current settings to settings.json and // resets any user configuration of local settings present in settings.json func OverwriteSettings(filename string) error { - settings := make(map[string]interface{}) + settings := make(map[string]any) var err error if _, e := os.Stat(ConfigDir); e == nil { @@ -398,17 +398,17 @@ func OverwriteSettings(filename string) error { } // RegisterCommonOptionPlug creates a new option (called pl.name). This is meant to be called by plugins to add options. -func RegisterCommonOptionPlug(pl string, name string, defaultvalue interface{}) error { +func RegisterCommonOptionPlug(pl string, name string, defaultvalue any) error { return RegisterCommonOption(pl+"."+name, defaultvalue) } // RegisterGlobalOptionPlug creates a new global-only option (named pl.name) -func RegisterGlobalOptionPlug(pl string, name string, defaultvalue interface{}) error { +func RegisterGlobalOptionPlug(pl string, name string, defaultvalue any) error { return RegisterGlobalOption(pl+"."+name, defaultvalue) } // RegisterCommonOption creates a new option -func RegisterCommonOption(name string, defaultvalue interface{}) error { +func RegisterCommonOption(name string, defaultvalue any) error { if _, ok := GlobalSettings[name]; !ok { GlobalSettings[name] = defaultvalue } @@ -417,7 +417,7 @@ func RegisterCommonOption(name string, defaultvalue interface{}) error { } // RegisterGlobalOption creates a new global-only option -func RegisterGlobalOption(name string, defaultvalue interface{}) error { +func RegisterGlobalOption(name string, defaultvalue any) error { if _, ok := GlobalSettings[name]; !ok { GlobalSettings[name] = defaultvalue } @@ -426,7 +426,7 @@ func RegisterGlobalOption(name string, defaultvalue interface{}) error { } // GetGlobalOption returns the global value of the given option -func GetGlobalOption(name string) interface{} { +func GetGlobalOption(name string) any { return GlobalSettings[name] } @@ -450,8 +450,8 @@ func GetInfoBarOffset() int { // DefaultCommonSettings returns a map of all common buffer settings // and their default values -func DefaultCommonSettings() map[string]interface{} { - commonsettings := make(map[string]interface{}) +func DefaultCommonSettings() map[string]any { + commonsettings := make(map[string]any) for k, v := range defaultCommonSettings { commonsettings[k] = v } @@ -460,8 +460,8 @@ func DefaultCommonSettings() map[string]interface{} { // DefaultAllSettings returns a map of all common buffer & global-only settings // and their default values -func DefaultAllSettings() map[string]interface{} { - allsettings := make(map[string]interface{}) +func DefaultAllSettings() map[string]any { + allsettings := make(map[string]any) for k, v := range defaultCommonSettings { allsettings[k] = v } @@ -472,7 +472,7 @@ func DefaultAllSettings() map[string]interface{} { } // GetNativeValue parses and validates a value for a given option -func GetNativeValue(option, value string) (interface{}, error) { +func GetNativeValue(option, value string) (any, error) { curVal := GetGlobalOption(option) if curVal == nil { return nil, ErrInvalidOption @@ -499,7 +499,7 @@ func GetNativeValue(option, value string) (interface{}, error) { } // OptionIsValid checks if a value is valid for a certain option -func OptionIsValid(option string, value interface{}) error { +func OptionIsValid(option string, value any) error { if validator, ok := optionValidators[option]; ok { return validator(option, value) } @@ -509,7 +509,7 @@ func OptionIsValid(option string, value interface{}) error { // Option validators -func validatePositiveValue(option string, value interface{}) error { +func validatePositiveValue(option string, value any) error { nativeValue, ok := value.(float64) if !ok { @@ -523,7 +523,7 @@ func validatePositiveValue(option string, value interface{}) error { return nil } -func validateNonNegativeValue(option string, value interface{}) error { +func validateNonNegativeValue(option string, value any) error { nativeValue, ok := value.(float64) if !ok { @@ -537,7 +537,7 @@ func validateNonNegativeValue(option string, value interface{}) error { return nil } -func validateChoice(option string, value interface{}) error { +func validateChoice(option string, value any) error { if choices, ok := OptionChoices[option]; ok { val, ok := value.(string) if !ok { @@ -557,7 +557,7 @@ func validateChoice(option string, value interface{}) error { return errors.New("Option has no pre-defined choices") } -func validateColorscheme(option string, value interface{}) error { +func validateColorscheme(option string, value any) error { colorscheme, ok := value.(string) if !ok { @@ -571,7 +571,7 @@ func validateColorscheme(option string, value interface{}) error { return nil } -func validateEncoding(option string, value interface{}) error { +func validateEncoding(option string, value any) error { _, err := htmlindex.Get(value.(string)) return err } diff --git a/internal/display/bufwindow.go b/internal/display/bufwindow.go index 1ecb4323..7348da66 100644 --- a/internal/display/bufwindow.go +++ b/internal/display/bufwindow.go @@ -46,7 +46,7 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow { // SetBuffer sets this window's buffer. func (w *BufWindow) SetBuffer(b *buffer.Buffer) { w.Buf = b - b.OptionCallback = func(option string, nativeValue interface{}) { + b.OptionCallback = func(option string, nativeValue any) { if option == "softwrap" { if nativeValue.(bool) { w.StartCol = 0 diff --git a/internal/display/statusline.go b/internal/display/statusline.go index f4040c92..409f862c 100644 --- a/internal/display/statusline.go +++ b/internal/display/statusline.go @@ -96,7 +96,7 @@ func NewStatusLine(win *BufWindow) *StatusLine { } // FindOpt finds a given option in the current buffer's settings -func (s *StatusLine) FindOpt(opt string) interface{} { +func (s *StatusLine) FindOpt(opt string) any { if val, ok := s.win.Buf.Settings[opt]; ok { return val } @@ -152,7 +152,7 @@ func (s *StatusLine) Display() { name := match[2 : len(match)-1] if bytes.HasPrefix(name, []byte("opt")) { option := name[4:] - return []byte(fmt.Sprint(s.FindOpt(string(option)))) + return fmt.Append(nil, s.FindOpt(string(option))) } else if bytes.HasPrefix(name, []byte("bind")) { binding := string(name[5:]) for k, v := range config.Bindings["buffer"] { diff --git a/internal/info/infobuffer.go b/internal/info/infobuffer.go index eaeadbe0..e4d3ff82 100644 --- a/internal/info/infobuffer.go +++ b/internal/info/infobuffer.go @@ -55,7 +55,7 @@ func (i *InfoBuf) Close() { } // Message sends a message to the user -func (i *InfoBuf) Message(msg ...interface{}) { +func (i *InfoBuf) Message(msg ...any) { // only display a new message if there isn't an active prompt // this is to prevent overwriting an existing prompt to the user if !i.HasPrompt { @@ -67,7 +67,7 @@ func (i *InfoBuf) Message(msg ...interface{}) { } // GutterMessage displays a message and marks it as a gutter message -func (i *InfoBuf) GutterMessage(msg ...interface{}) { +func (i *InfoBuf) GutterMessage(msg ...any) { i.Message(msg...) i.HasGutter = true } @@ -79,7 +79,7 @@ func (i *InfoBuf) ClearGutter() { } // Error sends an error message to the user -func (i *InfoBuf) Error(msg ...interface{}) { +func (i *InfoBuf) Error(msg ...any) { // only display a new message if there isn't an active prompt // this is to prevent overwriting an existing prompt to the user if !i.HasPrompt { diff --git a/internal/screen/message.go b/internal/screen/message.go index 1ca9141c..9477491d 100644 --- a/internal/screen/message.go +++ b/internal/screen/message.go @@ -14,7 +14,7 @@ import ( // The function must be called when the Screen is not initialized // This will write the message, and wait for the user // to press and key to continue -func TermMessage(msg ...interface{}) { +func TermMessage(msg ...any) { screenb := TempFini() fmt.Println(msg...) diff --git a/internal/shell/job.go b/internal/shell/job.go index 766b9516..00ad54bd 100644 --- a/internal/shell/job.go +++ b/internal/shell/job.go @@ -24,17 +24,17 @@ func init() { // JobFunction is a representation of a job (this data structure is what is loaded // into the jobs channel) type JobFunction struct { - Function func(string, []interface{}) + Function func(string, []any) Output string - Args []interface{} + Args []any } // A CallbackFile is the data structure that makes it possible to catch stderr and stdout write events type CallbackFile struct { io.Writer - callback func(string, []interface{}) - args []interface{} + callback func(string, []any) + args []any } // Job stores the executing command for the job, and the stdin pipe @@ -53,13 +53,13 @@ func (f *CallbackFile) Write(data []byte) (int, error) { // JobStart starts a shell command in the background with the given callbacks // It returns an *exec.Cmd as the job id -func JobStart(cmd string, onStdout, onStderr, onExit func(string, []interface{}), userargs ...interface{}) *Job { +func JobStart(cmd string, onStdout, onStderr, onExit func(string, []any), userargs ...any) *Job { return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...) } // JobSpawn starts a process with args in the background with the given callbacks // It returns an *exec.Cmd as the job id -func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func(string, []interface{}), userargs ...interface{}) *Job { +func JobSpawn(cmdName string, cmdArgs []string, onStdout, onStderr, onExit func(string, []any), userargs ...any) *Job { // Set up everything correctly if the functions have been provided proc := exec.Command(cmdName, cmdArgs...) var outbuf bytes.Buffer diff --git a/internal/shell/terminal.go b/internal/shell/terminal.go index 150400d3..6be4ac52 100644 --- a/internal/shell/terminal.go +++ b/internal/shell/terminal.go @@ -69,7 +69,7 @@ func (t *Terminal) GetSelection(width int) string { } // Start begins a new command in this terminal with a given view -func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback func(out string, userargs []interface{}), userargs []interface{}) error { +func (t *Terminal) Start(execCmd []string, getOutput bool, wait bool, callback func(out string, userargs []any), userargs []any) error { if len(execCmd) <= 0 { return nil } @@ -130,7 +130,7 @@ func (t *Terminal) Close() { if t.getOutput { if t.callback != nil { Jobs <- JobFunction{ - Function: func(out string, args []interface{}) { + Function: func(out string, args []any) { t.callback(out) }, Output: t.output.String(), diff --git a/internal/util/util.go b/internal/util/util.go index f2cb2a99..d0f20022 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -522,7 +522,7 @@ func HasTrailingWhitespace(b []byte) bool { } // IntOpt turns a float64 setting to an int -func IntOpt(opt interface{}) int { +func IntOpt(opt any) int { return int(opt.(float64)) } diff --git a/pkg/highlight/parser.go b/pkg/highlight/parser.go index ca6876cc..804e6bc0 100644 --- a/pkg/highlight/parser.go +++ b/pkg/highlight/parser.go @@ -54,7 +54,7 @@ type HeaderYaml struct { type File struct { FileType string - yamlSrc map[interface{}]interface{} + yamlSrc map[any]any } // A Pattern is one simple syntax rule @@ -197,7 +197,7 @@ func ParseFile(input []byte) (f *File, err error) { } }() - var rules map[interface{}]interface{} + var rules map[any]any if err = yaml.Unmarshal(input, &rules); err != nil { return nil, err } @@ -245,7 +245,7 @@ func ParseDef(f *File, header *Header) (s *Def, err error) { for k, v := range src { if k == "rules" { - inputRules := v.([]interface{}) + inputRules := v.([]any) rules, err := parseRules(inputRules, nil) if err != nil { @@ -336,7 +336,7 @@ func resolveIncludesInRegion(files []*File, region *region) { } } -func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) { +func parseRules(input []any, curRegion *region) (ru *rules, err error) { defer func() { if r := recover(); r != nil { var ok bool @@ -349,7 +349,7 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) { ru = new(rules) for _, v := range input { - rule := v.(map[interface{}]interface{}) + rule := v.(map[any]any) for k, val := range rule { group := k @@ -376,7 +376,7 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) { groupNum := Groups[groupStr] ru.patterns = append(ru.patterns, &pattern{groupNum, r}) } - case map[interface{}]interface{}: + case map[any]any: // region region, err := parseRegion(group.(string), object, curRegion) if err != nil { @@ -392,7 +392,7 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) { return ru, nil } -func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegion *region) (r *region, err error) { +func parseRegion(group string, regionInfo map[any]any, prevRegion *region) (r *region, err error) { defer func() { if r := recover(); r != nil { var ok bool @@ -478,7 +478,7 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio // rules are optional if rules, ok := regionInfo["rules"]; ok { - r.rules, err = parseRules(rules.([]interface{}), r) + r.rules, err = parseRules(rules.([]any), r) if err != nil { return nil, err } diff --git a/runtime/help/plugins.md b/runtime/help/plugins.md index f3cddd1a..c683804f 100644 --- a/runtime/help/plugins.md +++ b/runtime/help/plugins.md @@ -126,7 +126,7 @@ micro.Log("Hello") The packages and their contents are listed below (in Go type signatures): * `micro` - - `TermMessage(msg interface{}...)`: temporarily close micro and print a + - `TermMessage(msg any...)`: temporarily close micro and print a message - `TermError(filename string, lineNum int, err string)`: temporarily close @@ -134,7 +134,7 @@ The packages and their contents are listed below (in Go type signatures): - `InfoBar() *InfoPane`: return the infobar BufPane object. - - `Log(msg interface{}...)`: write a message to `log.txt` (requires + - `Log(msg any...)`: write a message to `log.txt` (requires `-debug` flag, or binary built with `build-dbg`). - `SetStatusInfoFn(fn string)`: register the given lua function as @@ -157,7 +157,6 @@ The packages and their contents are listed below (in Go type signatures): [InfoPane](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/action#InfoPane) [Tab](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/action#Tab) [TabList](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/action#TabList) - [interface{} / any](https://go.dev/tour/methods/14) * `micro/config` - `MakeCommand(name string, action func(bp *BufPane, args[]string), @@ -210,18 +209,18 @@ The packages and their contents are listed below (in Go type signatures): - `RTHelp`: runtime files for help documents. - `RTPlugin`: runtime files for plugin source code. - - `RegisterCommonOption(pl string, name string, defaultvalue interface{})`: + - `RegisterCommonOption(pl string, name string, defaultvalue any)`: registers a new option for the given plugin. The name of the option will be `pl.name`, and will have the given default value. Since this registers a common option, the option will be modifiable on a per-buffer basis, while also having a global value (in the GlobalSettings map). - - `RegisterGlobalOption(pl string, name string, defaultvalue interface{})`: + - `RegisterGlobalOption(pl string, name string, defaultvalue any)`: same as `RegisterCommonOption`, but the option cannot be modified locally to each buffer. - - `GetGlobalOption(name string) interface{}`: returns the value of a + - `GetGlobalOption(name string) any`: returns the value of a given plugin in the `GlobalSettings` map. - `SetGlobalOption(option, value string) error`: sets an option to a @@ -229,7 +228,7 @@ The packages and their contents are listed below (in Go type signatures): the value into the proper type for the option. Can return an error if the option name is not valid, or the value can not be converted. - - `SetGlobalOptionNative(option string, value interface{}) error`: sets + - `SetGlobalOptionNative(option string, value any) error`: sets an option to a given value, where the type of value is the actual type of the value internally. Can return an error if the provided value is not valid for the given option. @@ -240,7 +239,6 @@ The packages and their contents are listed below (in Go type signatures): [Buffer](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/buffer#Buffer) [buffer.Completer](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/buffer#Completer) [Error](https://pkg.go.dev/builtin#error) - [interface{} / any](https://go.dev/tour/methods/14) [filepath.Match](https://pkg.go.dev/path/filepath#Match) * `micro/shell` @@ -266,7 +264,7 @@ The packages and their contents are listed below (in Go type signatures): stdout from the command to the returned string. - `JobStart(cmd string, onStdout, onStderr, - onExit func(string, []interface{}), userargs ...interface{}) + onExit func(string, []any), userargs ...any) *exec.Cmd`: Starts a background job by running the shell on the given command (using `sh -c`). Three callbacks can be provided which will be called @@ -275,7 +273,7 @@ The packages and their contents are listed below (in Go type signatures): argument of the callback. Returns the started command. - `JobSpawn(cmd string, cmdArgs []string, onStdout, onStderr, - onExit func(string, []interface{}), userargs ...interface{}) + onExit func(string, []any), userargs ...any) *exec.Cmd`: same as `JobStart`, except doesn't run the command through the shell and instead takes as inputs the list of arguments. Returns the started @@ -285,8 +283,8 @@ The packages and their contents are listed below (in Go type signatures): - `JobSend(cmd *exec.Cmd, data string)`: sends some data to a job's stdin. - `RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, - callback func(out string, userargs []interface{}), - userargs []interface{}) error`: + callback func(out string, userargs []any), + userargs []any) error`: starts a terminal emulator from a given BufPane with the input command. If `wait` is true, it will wait for the user to exit by pressing enter once the executable has terminated, and if `getOutput` is true, it will diff --git a/runtime/syntax/syntax_converter.go b/runtime/syntax/syntax_converter.go index f96d4af7..1f3de5b8 100644 --- a/runtime/syntax/syntax_converter.go +++ b/runtime/syntax/syntax_converter.go @@ -28,7 +28,7 @@ func JoinRule(rule string) string { return joined } -func parseFile(text, filename string) (filetype, syntax, header string, rules []interface{}) { +func parseFile(text, filename string) (filetype, syntax, header string, rules []any) { lines := strings.Split(text, "\n") // Regex for parsing syntax statements @@ -129,7 +129,7 @@ func parseFile(text, filename string) (filetype, syntax, header string, rules [] return } -func generateFile(filetype, syntax, header string, rules []interface{}) string { +func generateFile(filetype, syntax, header string, rules []any) string { output := "" output += fmt.Sprintf("filetype: %s\n\n", filetype) diff --git a/tools/remove-nightly-assets.go b/tools/remove-nightly-assets.go index 3687eb15..9f06f5f4 100644 --- a/tools/remove-nightly-assets.go +++ b/tools/remove-nightly-assets.go @@ -21,16 +21,16 @@ func main() { defer resp.Body.Close() body, err := io.ReadAll(resp.Body) - var data interface{} + var data any err = json5.Unmarshal(body, &data) - for _, val := range data.([]interface{}) { - m := val.(map[string]interface{}) + for _, val := range data.([]any) { + m := val.(map[string]any) releaseName := m["name"].(string) - assets := m["assets"].([]interface{}) + assets := m["assets"].([]any) for _, asset := range assets { - assetInfo := asset.(map[string]interface{}) + assetInfo := asset.(map[string]any) url := assetInfo["url"].(string) if strings.Contains(strings.ToLower(releaseName), "nightly") { cmd := exec.Command("hub", "api", "-X", "DELETE", url)