]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/settings.go
Fix some issues with unicode handling
[micro.git] / cmd / micro / settings.go
index a9b1d35851cd6ec89f75867cf0eddaf0560a26d0..4df44237eaf1400a5664f696024f6a76482fd424 100644 (file)
@@ -6,7 +6,6 @@ import (
        "os"
        "reflect"
        "strconv"
-       "strings"
 )
 
 // The options that the user can set
@@ -72,66 +71,76 @@ func GetOption(name string) interface{} {
 // DefaultSettings returns the default settings for micro
 func DefaultSettings() map[string]interface{} {
        return map[string]interface{}{
-               "colorscheme":  "default",
-               "tabsize":      float64(4),
-               "indentchar":   " ",
-               "ignorecase":   false,
                "autoindent":   true,
-               "syntax":       true,
-               "tabstospaces": false,
+               "colorscheme":  "monokai",
+               "cursorline":   false,
+               "ignorecase":   false,
+               "indentchar":   " ",
                "ruler":        true,
-               "statusline":   true,
-               "scrollmargin": float64(3),
+               "savecursor":   false,
+               "saveundo":     false,
                "scrollspeed":  float64(2),
+               "scrollmargin": float64(3),
+               "statusline":   true,
+               "syntax":       true,
+               "tabsize":      float64(4),
+               "tabstospaces": false,
        }
 }
 
 // SetOption prompts the user to set an option and checks that the response is valid
-func SetOption(view *View, args []string) {
+func SetOption(option, value string) {
        filename := configDir + "/settings.json"
-       if len(args) == 2 {
-               option := strings.TrimSpace(args[0])
-               value := strings.TrimSpace(args[1])
+       if _, ok := settings[option]; !ok {
+               messenger.Error(option + " is not a valid option")
+               return
+       }
 
-               if _, ok := settings[option]; !ok {
-                       messenger.Error(option + " is not a valid option")
+       kind := reflect.TypeOf(settings[option]).Kind()
+       if kind == reflect.Bool {
+               b, err := ParseBool(value)
+               if err != nil {
+                       messenger.Error("Invalid value for " + option)
                        return
                }
-
-               kind := reflect.TypeOf(settings[option]).Kind()
-               if kind == reflect.Bool {
-                       b, err := ParseBool(value)
-                       if err != nil {
-                               messenger.Error("Invalid value for " + option)
-                               return
-                       }
-                       settings[option] = b
-               } else if kind == reflect.String {
-                       settings[option] = value
-               } else if kind == reflect.Float64 {
-                       i, err := strconv.Atoi(value)
-                       if err != nil {
-                               messenger.Error("Invalid value for " + option)
-                               return
-                       }
-                       settings[option] = float64(i)
+               settings[option] = b
+       } else if kind == reflect.String {
+               settings[option] = value
+       } else if kind == reflect.Float64 {
+               i, err := strconv.Atoi(value)
+               if err != nil {
+                       messenger.Error("Invalid value for " + option)
+                       return
                }
+               settings[option] = float64(i)
+       }
 
-               if option == "colorscheme" {
-                       LoadSyntaxFiles()
-                       view.Buf.UpdateRules()
+       if option == "colorscheme" {
+               LoadSyntaxFiles()
+               for _, tab := range tabs {
+                       for _, view := range tab.views {
+                               view.Buf.UpdateRules()
+                               if settings["syntax"].(bool) {
+                                       view.matches = Match(view)
+                               }
+                       }
                }
+       }
 
-               if option == "statusline" {
-                       view.Resize(screen.Size())
+       if option == "statusline" {
+               for _, tab := range tabs {
+                       for _, view := range tab.views {
+                               view.ToggleStatusLine()
+                               if settings["syntax"].(bool) {
+                                       view.matches = Match(view)
+                               }
+                       }
                }
+       }
 
-               err := WriteSettings(filename)
-               if err != nil {
-                       messenger.Error("Error writing to settings.json: " + err.Error())
-                       return
-               }
-       } else {
-               messenger.Error("No value given")
+       err := WriteSettings(filename)
+       if err != nil {
+               messenger.Error("Error writing to settings.json: " + err.Error())
+               return
        }
 }