refactor: use a more modern writing style to simplify code (#3834)

Signed-off-by: deepdring <deepdrink@icloud.com>
This commit is contained in:
deepdring
2025-08-26 08:00:51 +08:00
committed by GitHub
parent 094b02da4c
commit b8057f28c6
24 changed files with 98 additions and 100 deletions

View File

@@ -2083,14 +2083,14 @@ func (h *BufPane) LastSplit() bool {
return true return true
} }
var curmacro []interface{} var curmacro []any
var recordingMacro bool var recordingMacro bool
// ToggleMacro toggles recording of a macro // ToggleMacro toggles recording of a macro
func (h *BufPane) ToggleMacro() bool { func (h *BufPane) ToggleMacro() bool {
recordingMacro = !recordingMacro recordingMacro = !recordingMacro
if recordingMacro { if recordingMacro {
curmacro = []interface{}{} curmacro = []any{}
InfoBar.Message("Recording") InfoBar.Message("Recording")
} else { } else {
InfoBar.Message("Stopped recording") InfoBar.Message("Stopped recording")

View File

@@ -36,7 +36,7 @@ func createBindingsIfNotExist(fname string) {
// InitBindings intializes the bindings map by reading from bindings.json // InitBindings intializes the bindings map by reading from bindings.json
func InitBindings() { func InitBindings() {
var parsed map[string]interface{} var parsed map[string]any
filename := filepath.Join(config.ConfigDir, "bindings.json") filename := filepath.Join(config.ConfigDir, "bindings.json")
createBindingsIfNotExist(filename) createBindingsIfNotExist(filename)
@@ -66,7 +66,7 @@ func InitBindings() {
switch val := v.(type) { switch val := v.(type) {
case string: case string:
BindKey(k, val, Binder["buffer"]) BindKey(k, val, Binder["buffer"])
case map[string]interface{}: case map[string]any:
bind, ok := Binder[k] bind, ok := Binder[k]
if !ok || bind == nil { if !ok || bind == nil {
screen.TermMessage(fmt.Sprintf("%s is not a valid pane type", k)) 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 // Returns true if the keybinding already existed and a possible error
func TryBindKey(k, v string, overwrite bool) (bool, error) { func TryBindKey(k, v string, overwrite bool) (bool, error) {
var e error var e error
var parsed map[string]interface{} var parsed map[string]any
filename := filepath.Join(config.ConfigDir, "bindings.json") filename := filepath.Join(config.ConfigDir, "bindings.json")
createBindingsIfNotExist(filename) 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 // UnbindKey removes the binding for a key from the bindings.json file
func UnbindKey(k string) error { func UnbindKey(k string) error {
var e error var e error
var parsed map[string]interface{} var parsed map[string]any
filename := filepath.Join(config.ConfigDir, "bindings.json") filename := filepath.Join(config.ConfigDir, "bindings.json")
createBindingsIfNotExist(filename) createBindingsIfNotExist(filename)

View File

@@ -16,7 +16,7 @@ import (
"github.com/zyedidia/micro/v2/internal/util" "github.com/zyedidia/micro/v2/internal/util"
) )
type BufAction interface{} type BufAction any
// BufKeyAction represents an action bound to a key. // BufKeyAction represents an action bound to a key.
type BufKeyAction func(*BufPane) bool 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. // error if there is one and returns the aggregate boolean response.
// The bufpane is passed as the first argument to the callbacks, // The bufpane is passed as the first argument to the callbacks,
// optional args are passed as the next arguments. // 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)} largs := []lua.LValue{luar.New(ulua.L, h)}
for _, a := range args { for _, a := range args {
largs = append(largs, luar.New(ulua.L, a)) largs = append(largs, luar.New(ulua.L, a))

View File

@@ -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) { if reflect.DeepEqual(config.GlobalSettings[option], nativeValue) {
return nil return nil
} }
@@ -628,7 +628,7 @@ func doSetGlobalOptionNative(option string, nativeValue interface{}) error {
return nil return nil
} }
func SetGlobalOptionNative(option string, nativeValue interface{}) error { func SetGlobalOptionNative(option string, nativeValue any) error {
if err := config.OptionIsValid(option, nativeValue); err != nil { if err := config.OptionIsValid(option, nativeValue); err != nil {
return err return err
} }
@@ -737,7 +737,7 @@ func (h *BufPane) ShowCmd(args []string) {
return return
} }
var option interface{} var option any
if opt, ok := h.Buf.Settings[args[0]]; ok { if opt, ok := h.Buf.Settings[args[0]]; ok {
option = opt option = opt
} else if opt, ok := config.GlobalSettings[args[0]]; ok { } else if opt, ok := config.GlobalSettings[args[0]]; ok {

View File

@@ -193,7 +193,7 @@ func OptionValueComplete(b *buffer.Buffer) ([]string, []string) {
inputOpt = strings.TrimSpace(inputOpt) inputOpt = strings.TrimSpace(inputOpt)
var suggestions []string var suggestions []string
// localSettings := config.DefaultLocalSettings() // localSettings := config.DefaultLocalSettings()
var optionVal interface{} var optionVal any
for k, option := range config.GlobalSettings { for k, option := range config.GlobalSettings {
if k == inputOpt { if k == inputOpt {
optionVal = option optionVal = option

View File

@@ -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 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 // 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 // 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) args, err := shellquote.Split(input)
if err != nil { if err != nil {
return err return err

View File

@@ -8,6 +8,6 @@ import "errors"
const TermEmuSupported = false const TermEmuSupported = false
// RunTermEmulator returns an error for unsupported systems (non-unix systems // 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") return errors.New("Unsupported operating system")
} }

View File

@@ -82,7 +82,7 @@ type SharedBuffer struct {
toStdout bool toStdout bool
// Settings customized by the user // Settings customized by the user
Settings map[string]interface{} Settings map[string]any
// LocalSettings customized by the user for this buffer only // LocalSettings customized by the user for this buffer only
LocalSettings map[string]bool LocalSettings map[string]bool
@@ -236,7 +236,7 @@ type Buffer struct {
// is properly updated when needed. This is a workaround for the fact that // 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 // the buffer module cannot directly call the display's API (it would mean
// a circular dependency between packages). // 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 display module registers its own GetVisualX function for getting
// the correct visual x location of a cursor when softwrap is used. // the correct visual x location of a cursor when softwrap is used.

View File

@@ -84,7 +84,7 @@ func (b *Buffer) ClearAllMessages() {
} }
type Messager interface { type Messager interface {
Message(msg ...interface{}) Message(msg ...any)
} }
var prompt Messager var prompt Messager

View File

@@ -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] oldValue := b.Settings[option]
if reflect.DeepEqual(oldValue, nativeValue) { if reflect.DeepEqual(oldValue, nativeValue) {
return return
@@ -138,7 +138,7 @@ func (b *Buffer) DoSetOptionNative(option string, nativeValue interface{}) {
b.doCallbacks(option, oldValue, nativeValue) 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 { if err := config.OptionIsValid(option, nativeValue); err != nil {
return err return err
} }
@@ -163,7 +163,7 @@ func (b *Buffer) SetOption(option, value string) error {
return b.SetOptionNative(option, nativeValue) 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 { if b.OptionCallback != nil {
b.OptionCallback(option, newValue) b.OptionCallback(option, newValue)
} }

View File

@@ -42,7 +42,7 @@ func RunPluginFn(fn string, args ...lua.LValue) error {
// RunPluginFnBool runs a function in all plugins and returns // RunPluginFnBool runs a function in all plugins and returns
// false if any one of them returned false // false if any one of them returned false
// also returns an error if any of the plugins had an error // 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 var reterr error
retbool := true retbool := true
for _, p := range Plugins { for _, p := range Plugins {

View File

@@ -228,7 +228,7 @@ func GetAllPluginPackages(out io.Writer) PluginPackages {
if strs, ok := data.([]string); ok { if strs, ok := data.([]string); ok {
return strs return strs
} }
if ifs, ok := data.([]interface{}); ok { if ifs, ok := data.([]any); ok {
result := make([]string, len(ifs)) result := make([]string, len(ifs))
for i, urlIf := range ifs { for i, urlIf := range ifs {
if url, ok := urlIf.(string); ok { if url, ok := urlIf.(string); ok {

View File

@@ -17,7 +17,7 @@ import (
"golang.org/x/text/encoding/htmlindex" "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 // a list of settings that need option validators
var optionValidators = map[string]optionValidator{ 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 // a list of settings that can be globally and locally modified and their
// default values // default values
var defaultCommonSettings = map[string]interface{}{ var defaultCommonSettings = map[string]any{
"autoindent": true, "autoindent": true,
"autosu": false, "autosu": false,
"backup": true, "backup": true,
@@ -108,7 +108,7 @@ var defaultCommonSettings = map[string]interface{}{
// a list of settings that should only be globally modified and their // a list of settings that should only be globally modified and their
// default values // default values
var DefaultGlobalOnlySettings = map[string]interface{}{ var DefaultGlobalOnlySettings = map[string]any{
"autosave": float64(0), "autosave": float64(0),
"clipboard": "external", "clipboard": "external",
"colorscheme": "default", "colorscheme": "default",
@@ -143,10 +143,10 @@ var (
ErrInvalidValue = errors.New("Invalid value") ErrInvalidValue = errors.New("Invalid value")
// The options that the user can set // The options that the user can set
GlobalSettings map[string]interface{} GlobalSettings map[string]any
// This is the raw parsed json // This is the raw parsed json
parsedSettings map[string]interface{} parsedSettings map[string]any
settingsParseError bool settingsParseError bool
// ModifiedSettings is a map of settings which should be written to disk // ModifiedSettings is a map of settings which should be written to disk
@@ -173,11 +173,11 @@ func validateParsedSettings() error {
for k, v := range parsedSettings { for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") { if strings.HasPrefix(reflect.TypeOf(v).String(), "map") {
if strings.HasPrefix(k, "ft:") { 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 _, ok := defaults[k1]; ok {
if e := verifySetting(k1, v1, defaults[k1]); e != nil { if e := verifySetting(k1, v1, defaults[k1]); e != nil {
err = e err = e
parsedSettings[k].(map[string]interface{})[k1] = defaults[k1] parsedSettings[k].(map[string]any)[k1] = defaults[k1]
continue continue
} }
} }
@@ -188,11 +188,11 @@ func validateParsedSettings() error {
delete(parsedSettings, k) delete(parsedSettings, k)
continue continue
} }
for k1, v1 := range v.(map[string]interface{}) { for k1, v1 := range v.(map[string]any) {
if _, ok := defaults[k1]; ok { if _, ok := defaults[k1]; ok {
if e := verifySetting(k1, v1, defaults[k1]); e != nil { if e := verifySetting(k1, v1, defaults[k1]); e != nil {
err = e err = e
parsedSettings[k].(map[string]interface{})[k1] = defaults[k1] parsedSettings[k].(map[string]any)[k1] = defaults[k1]
continue continue
} }
} }
@@ -225,7 +225,7 @@ func validateParsedSettings() error {
} }
func ReadSettings() error { func ReadSettings() error {
parsedSettings = make(map[string]interface{}) parsedSettings = make(map[string]any)
filename := filepath.Join(ConfigDir, "settings.json") filename := filepath.Join(ConfigDir, "settings.json")
if _, e := os.Stat(filename); e == nil { if _, e := os.Stat(filename); e == nil {
input, err := os.ReadFile(filename) input, err := os.ReadFile(filename)
@@ -249,16 +249,16 @@ func ReadSettings() error {
return nil return nil
} }
func ParsedSettings() map[string]interface{} { func ParsedSettings() map[string]any {
s := make(map[string]interface{}) s := make(map[string]any)
for k, v := range parsedSettings { for k, v := range parsedSettings {
s[k] = v s[k] = v
} }
return s return s
} }
func verifySetting(option string, value interface{}, def interface{}) error { func verifySetting(option string, value any, def any) error {
var interfaceArr []interface{} var interfaceArr []any
valType := reflect.TypeOf(value) valType := reflect.TypeOf(value)
defType := reflect.TypeOf(def) defType := reflect.TypeOf(def)
assignable := false assignable := false
@@ -303,12 +303,12 @@ func InitGlobalSettings() error {
// UpdatePathGlobLocals scans the already parsed settings and sets the options locally // UpdatePathGlobLocals scans the already parsed settings and sets the options locally
// based on whether the path matches a glob // based on whether the path matches a glob
// Must be called after ReadSettings // 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 { for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && !strings.HasPrefix(k, "ft:") { if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && !strings.HasPrefix(k, "ft:") {
g, _ := glob.Compile(k) g, _ := glob.Compile(k)
if g.MatchString(path) { if g.MatchString(path) {
for k1, v1 := range v.(map[string]interface{}) { for k1, v1 := range v.(map[string]any) {
settings[k1] = v1 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 // UpdateFileTypeLocals scans the already parsed settings and sets the options locally
// based on whether the filetype matches to "ft:" // based on whether the filetype matches to "ft:"
// Must be called after ReadSettings // 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 { for k, v := range parsedSettings {
if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && strings.HasPrefix(k, "ft:") { if strings.HasPrefix(reflect.TypeOf(v).String(), "map") && strings.HasPrefix(k, "ft:") {
if filetype == k[3:] { if filetype == k[3:] {
for k1, v1 := range v.(map[string]interface{}) { for k1, v1 := range v.(map[string]any) {
if k1 != "filetype" { if k1 != "filetype" {
settings[k1] = v1 settings[k1] = v1
} }
@@ -377,7 +377,7 @@ func WriteSettings(filename string) error {
// OverwriteSettings writes the current settings to settings.json and // OverwriteSettings writes the current settings to settings.json and
// resets any user configuration of local settings present in settings.json // resets any user configuration of local settings present in settings.json
func OverwriteSettings(filename string) error { func OverwriteSettings(filename string) error {
settings := make(map[string]interface{}) settings := make(map[string]any)
var err error var err error
if _, e := os.Stat(ConfigDir); e == nil { 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. // 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) return RegisterCommonOption(pl+"."+name, defaultvalue)
} }
// RegisterGlobalOptionPlug creates a new global-only option (named pl.name) // 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) return RegisterGlobalOption(pl+"."+name, defaultvalue)
} }
// RegisterCommonOption creates a new option // RegisterCommonOption creates a new option
func RegisterCommonOption(name string, defaultvalue interface{}) error { func RegisterCommonOption(name string, defaultvalue any) error {
if _, ok := GlobalSettings[name]; !ok { if _, ok := GlobalSettings[name]; !ok {
GlobalSettings[name] = defaultvalue GlobalSettings[name] = defaultvalue
} }
@@ -417,7 +417,7 @@ func RegisterCommonOption(name string, defaultvalue interface{}) error {
} }
// RegisterGlobalOption creates a new global-only option // 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 { if _, ok := GlobalSettings[name]; !ok {
GlobalSettings[name] = defaultvalue GlobalSettings[name] = defaultvalue
} }
@@ -426,7 +426,7 @@ func RegisterGlobalOption(name string, defaultvalue interface{}) error {
} }
// GetGlobalOption returns the global value of the given option // GetGlobalOption returns the global value of the given option
func GetGlobalOption(name string) interface{} { func GetGlobalOption(name string) any {
return GlobalSettings[name] return GlobalSettings[name]
} }
@@ -450,8 +450,8 @@ func GetInfoBarOffset() int {
// DefaultCommonSettings returns a map of all common buffer settings // DefaultCommonSettings returns a map of all common buffer settings
// and their default values // and their default values
func DefaultCommonSettings() map[string]interface{} { func DefaultCommonSettings() map[string]any {
commonsettings := make(map[string]interface{}) commonsettings := make(map[string]any)
for k, v := range defaultCommonSettings { for k, v := range defaultCommonSettings {
commonsettings[k] = v commonsettings[k] = v
} }
@@ -460,8 +460,8 @@ func DefaultCommonSettings() map[string]interface{} {
// DefaultAllSettings returns a map of all common buffer & global-only settings // DefaultAllSettings returns a map of all common buffer & global-only settings
// and their default values // and their default values
func DefaultAllSettings() map[string]interface{} { func DefaultAllSettings() map[string]any {
allsettings := make(map[string]interface{}) allsettings := make(map[string]any)
for k, v := range defaultCommonSettings { for k, v := range defaultCommonSettings {
allsettings[k] = v allsettings[k] = v
} }
@@ -472,7 +472,7 @@ func DefaultAllSettings() map[string]interface{} {
} }
// GetNativeValue parses and validates a value for a given option // 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) curVal := GetGlobalOption(option)
if curVal == nil { if curVal == nil {
return nil, ErrInvalidOption 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 // 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 { if validator, ok := optionValidators[option]; ok {
return validator(option, value) return validator(option, value)
} }
@@ -509,7 +509,7 @@ func OptionIsValid(option string, value interface{}) error {
// Option validators // Option validators
func validatePositiveValue(option string, value interface{}) error { func validatePositiveValue(option string, value any) error {
nativeValue, ok := value.(float64) nativeValue, ok := value.(float64)
if !ok { if !ok {
@@ -523,7 +523,7 @@ func validatePositiveValue(option string, value interface{}) error {
return nil return nil
} }
func validateNonNegativeValue(option string, value interface{}) error { func validateNonNegativeValue(option string, value any) error {
nativeValue, ok := value.(float64) nativeValue, ok := value.(float64)
if !ok { if !ok {
@@ -537,7 +537,7 @@ func validateNonNegativeValue(option string, value interface{}) error {
return nil return nil
} }
func validateChoice(option string, value interface{}) error { func validateChoice(option string, value any) error {
if choices, ok := OptionChoices[option]; ok { if choices, ok := OptionChoices[option]; ok {
val, ok := value.(string) val, ok := value.(string)
if !ok { if !ok {
@@ -557,7 +557,7 @@ func validateChoice(option string, value interface{}) error {
return errors.New("Option has no pre-defined choices") 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) colorscheme, ok := value.(string)
if !ok { if !ok {
@@ -571,7 +571,7 @@ func validateColorscheme(option string, value interface{}) error {
return nil return nil
} }
func validateEncoding(option string, value interface{}) error { func validateEncoding(option string, value any) error {
_, err := htmlindex.Get(value.(string)) _, err := htmlindex.Get(value.(string))
return err return err
} }

View File

@@ -46,7 +46,7 @@ func NewBufWindow(x, y, width, height int, buf *buffer.Buffer) *BufWindow {
// SetBuffer sets this window's buffer. // SetBuffer sets this window's buffer.
func (w *BufWindow) SetBuffer(b *buffer.Buffer) { func (w *BufWindow) SetBuffer(b *buffer.Buffer) {
w.Buf = b w.Buf = b
b.OptionCallback = func(option string, nativeValue interface{}) { b.OptionCallback = func(option string, nativeValue any) {
if option == "softwrap" { if option == "softwrap" {
if nativeValue.(bool) { if nativeValue.(bool) {
w.StartCol = 0 w.StartCol = 0

View File

@@ -96,7 +96,7 @@ func NewStatusLine(win *BufWindow) *StatusLine {
} }
// FindOpt finds a given option in the current buffer's settings // 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 { if val, ok := s.win.Buf.Settings[opt]; ok {
return val return val
} }
@@ -152,7 +152,7 @@ func (s *StatusLine) Display() {
name := match[2 : len(match)-1] name := match[2 : len(match)-1]
if bytes.HasPrefix(name, []byte("opt")) { if bytes.HasPrefix(name, []byte("opt")) {
option := name[4:] 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")) { } else if bytes.HasPrefix(name, []byte("bind")) {
binding := string(name[5:]) binding := string(name[5:])
for k, v := range config.Bindings["buffer"] { for k, v := range config.Bindings["buffer"] {

View File

@@ -55,7 +55,7 @@ func (i *InfoBuf) Close() {
} }
// Message sends a message to the user // 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 // only display a new message if there isn't an active prompt
// this is to prevent overwriting an existing prompt to the user // this is to prevent overwriting an existing prompt to the user
if !i.HasPrompt { if !i.HasPrompt {
@@ -67,7 +67,7 @@ func (i *InfoBuf) Message(msg ...interface{}) {
} }
// GutterMessage displays a message and marks it as a gutter message // 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.Message(msg...)
i.HasGutter = true i.HasGutter = true
} }
@@ -79,7 +79,7 @@ func (i *InfoBuf) ClearGutter() {
} }
// Error sends an error message to the user // 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 // only display a new message if there isn't an active prompt
// this is to prevent overwriting an existing prompt to the user // this is to prevent overwriting an existing prompt to the user
if !i.HasPrompt { if !i.HasPrompt {

View File

@@ -14,7 +14,7 @@ import (
// The function must be called when the Screen is not initialized // The function must be called when the Screen is not initialized
// This will write the message, and wait for the user // This will write the message, and wait for the user
// to press and key to continue // to press and key to continue
func TermMessage(msg ...interface{}) { func TermMessage(msg ...any) {
screenb := TempFini() screenb := TempFini()
fmt.Println(msg...) fmt.Println(msg...)

View File

@@ -24,17 +24,17 @@ func init() {
// JobFunction is a representation of a job (this data structure is what is loaded // JobFunction is a representation of a job (this data structure is what is loaded
// into the jobs channel) // into the jobs channel)
type JobFunction struct { type JobFunction struct {
Function func(string, []interface{}) Function func(string, []any)
Output string Output string
Args []interface{} Args []any
} }
// A CallbackFile is the data structure that makes it possible to catch stderr and stdout write events // A CallbackFile is the data structure that makes it possible to catch stderr and stdout write events
type CallbackFile struct { type CallbackFile struct {
io.Writer io.Writer
callback func(string, []interface{}) callback func(string, []any)
args []interface{} args []any
} }
// Job stores the executing command for the job, and the stdin pipe // 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 // JobStart starts a shell command in the background with the given callbacks
// It returns an *exec.Cmd as the job id // 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...) return JobSpawn("sh", []string{"-c", cmd}, onStdout, onStderr, onExit, userargs...)
} }
// JobSpawn starts a process with args in the background with the given callbacks // JobSpawn starts a process with args in the background with the given callbacks
// It returns an *exec.Cmd as the job id // 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 // Set up everything correctly if the functions have been provided
proc := exec.Command(cmdName, cmdArgs...) proc := exec.Command(cmdName, cmdArgs...)
var outbuf bytes.Buffer var outbuf bytes.Buffer

View File

@@ -69,7 +69,7 @@ func (t *Terminal) GetSelection(width int) string {
} }
// Start begins a new command in this terminal with a given view // 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 { if len(execCmd) <= 0 {
return nil return nil
} }
@@ -130,7 +130,7 @@ func (t *Terminal) Close() {
if t.getOutput { if t.getOutput {
if t.callback != nil { if t.callback != nil {
Jobs <- JobFunction{ Jobs <- JobFunction{
Function: func(out string, args []interface{}) { Function: func(out string, args []any) {
t.callback(out) t.callback(out)
}, },
Output: t.output.String(), Output: t.output.String(),

View File

@@ -522,7 +522,7 @@ func HasTrailingWhitespace(b []byte) bool {
} }
// IntOpt turns a float64 setting to an int // IntOpt turns a float64 setting to an int
func IntOpt(opt interface{}) int { func IntOpt(opt any) int {
return int(opt.(float64)) return int(opt.(float64))
} }

View File

@@ -54,7 +54,7 @@ type HeaderYaml struct {
type File struct { type File struct {
FileType string FileType string
yamlSrc map[interface{}]interface{} yamlSrc map[any]any
} }
// A Pattern is one simple syntax rule // 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 { if err = yaml.Unmarshal(input, &rules); err != nil {
return nil, err return nil, err
} }
@@ -245,7 +245,7 @@ func ParseDef(f *File, header *Header) (s *Def, err error) {
for k, v := range src { for k, v := range src {
if k == "rules" { if k == "rules" {
inputRules := v.([]interface{}) inputRules := v.([]any)
rules, err := parseRules(inputRules, nil) rules, err := parseRules(inputRules, nil)
if err != 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() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
var ok bool var ok bool
@@ -349,7 +349,7 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) {
ru = new(rules) ru = new(rules)
for _, v := range input { for _, v := range input {
rule := v.(map[interface{}]interface{}) rule := v.(map[any]any)
for k, val := range rule { for k, val := range rule {
group := k group := k
@@ -376,7 +376,7 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) {
groupNum := Groups[groupStr] groupNum := Groups[groupStr]
ru.patterns = append(ru.patterns, &pattern{groupNum, r}) ru.patterns = append(ru.patterns, &pattern{groupNum, r})
} }
case map[interface{}]interface{}: case map[any]any:
// region // region
region, err := parseRegion(group.(string), object, curRegion) region, err := parseRegion(group.(string), object, curRegion)
if err != nil { if err != nil {
@@ -392,7 +392,7 @@ func parseRules(input []interface{}, curRegion *region) (ru *rules, err error) {
return ru, nil 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() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
var ok bool var ok bool
@@ -478,7 +478,7 @@ func parseRegion(group string, regionInfo map[interface{}]interface{}, prevRegio
// rules are optional // rules are optional
if rules, ok := regionInfo["rules"]; ok { if rules, ok := regionInfo["rules"]; ok {
r.rules, err = parseRules(rules.([]interface{}), r) r.rules, err = parseRules(rules.([]any), r)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -126,7 +126,7 @@ micro.Log("Hello")
The packages and their contents are listed below (in Go type signatures): The packages and their contents are listed below (in Go type signatures):
* `micro` * `micro`
- `TermMessage(msg interface{}...)`: temporarily close micro and print a - `TermMessage(msg any...)`: temporarily close micro and print a
message message
- `TermError(filename string, lineNum int, err string)`: temporarily close - `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. - `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`). `-debug` flag, or binary built with `build-dbg`).
- `SetStatusInfoFn(fn string)`: register the given lua function as - `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) [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) [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) [TabList](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/action#TabList)
[interface{} / any](https://go.dev/tour/methods/14)
* `micro/config` * `micro/config`
- `MakeCommand(name string, action func(bp *BufPane, args[]string), - `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. - `RTHelp`: runtime files for help documents.
- `RTPlugin`: runtime files for plugin source code. - `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 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 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 this registers a common option, the option will be modifiable on a
per-buffer basis, while also having a global value (in the per-buffer basis, while also having a global value (in the
GlobalSettings map). 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 same as `RegisterCommonOption`, but the option cannot be modified
locally to each buffer. 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. given plugin in the `GlobalSettings` map.
- `SetGlobalOption(option, value string) error`: sets an option to a - `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 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. 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 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 type of the value internally. Can return an error if the provided value
is not valid for the given option. 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](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) [buffer.Completer](https://pkg.go.dev/github.com/zyedidia/micro/v2/internal/buffer#Completer)
[Error](https://pkg.go.dev/builtin#error) [Error](https://pkg.go.dev/builtin#error)
[interface{} / any](https://go.dev/tour/methods/14)
[filepath.Match](https://pkg.go.dev/path/filepath#Match) [filepath.Match](https://pkg.go.dev/path/filepath#Match)
* `micro/shell` * `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. stdout from the command to the returned string.
- `JobStart(cmd string, onStdout, onStderr, - `JobStart(cmd string, onStdout, onStderr,
onExit func(string, []interface{}), userargs ...interface{}) onExit func(string, []any), userargs ...any)
*exec.Cmd`: *exec.Cmd`:
Starts a background job by running the shell on the given command Starts a background job by running the shell on the given command
(using `sh -c`). Three callbacks can be provided which will be called (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. argument of the callback. Returns the started command.
- `JobSpawn(cmd string, cmdArgs []string, onStdout, onStderr, - `JobSpawn(cmd string, cmdArgs []string, onStdout, onStderr,
onExit func(string, []interface{}), userargs ...interface{}) onExit func(string, []any), userargs ...any)
*exec.Cmd`: *exec.Cmd`:
same as `JobStart`, except doesn't run the command through the shell same as `JobStart`, except doesn't run the command through the shell
and instead takes as inputs the list of arguments. Returns the started 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. - `JobSend(cmd *exec.Cmd, data string)`: sends some data to a job's stdin.
- `RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool, - `RunTermEmulator(h *BufPane, input string, wait bool, getOutput bool,
callback func(out string, userargs []interface{}), callback func(out string, userargs []any),
userargs []interface{}) error`: userargs []any) error`:
starts a terminal emulator from a given BufPane with the input command. 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 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 once the executable has terminated, and if `getOutput` is true, it will

View File

@@ -28,7 +28,7 @@ func JoinRule(rule string) string {
return joined 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") lines := strings.Split(text, "\n")
// Regex for parsing syntax statements // Regex for parsing syntax statements
@@ -129,7 +129,7 @@ func parseFile(text, filename string) (filetype, syntax, header string, rules []
return return
} }
func generateFile(filetype, syntax, header string, rules []interface{}) string { func generateFile(filetype, syntax, header string, rules []any) string {
output := "" output := ""
output += fmt.Sprintf("filetype: %s\n\n", filetype) output += fmt.Sprintf("filetype: %s\n\n", filetype)

View File

@@ -21,16 +21,16 @@ func main() {
defer resp.Body.Close() defer resp.Body.Close()
body, err := io.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
var data interface{} var data any
err = json5.Unmarshal(body, &data) err = json5.Unmarshal(body, &data)
for _, val := range data.([]interface{}) { for _, val := range data.([]any) {
m := val.(map[string]interface{}) m := val.(map[string]any)
releaseName := m["name"].(string) releaseName := m["name"].(string)
assets := m["assets"].([]interface{}) assets := m["assets"].([]any)
for _, asset := range assets { for _, asset := range assets {
assetInfo := asset.(map[string]interface{}) assetInfo := asset.(map[string]any)
url := assetInfo["url"].(string) url := assetInfo["url"].(string)
if strings.Contains(strings.ToLower(releaseName), "nightly") { if strings.Contains(strings.ToLower(releaseName), "nightly") {
cmd := exec.Command("hub", "api", "-X", "DELETE", url) cmd := exec.Command("hub", "api", "-X", "DELETE", url)