X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fmicro.go;h=35d1721d88f54c4c1cc24138788da0367955c01c;hb=7b6430af1cd40bf701c36647df240b22cf973a2b;hp=f2c1e4668aca7832d09f4dca776ca0faa9eb2db4;hpb=8d1618692e84ee491331601b35e0c388d418d6b4;p=micro.git diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index f2c1e466..35d1721d 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -21,8 +21,6 @@ import ( ) const ( - synLinesUp = 75 // How many lines up to look to do syntax highlighting - synLinesDown = 75 // How many lines down to look to do syntax highlighting doubleClickThreshold = 400 // How many milliseconds to wait before a second click is not a double click undoThreshold = 500 // If two events are less than n milliseconds apart, undo both of them autosaveTime = 8 // Number of seconds to wait before autosaving @@ -50,10 +48,6 @@ var ( CommitHash = "Unknown" CompileDate = "Unknown" - // L is the lua state - // This is the VM that runs the plugins - L *lua.LState - // The list of views tabs []*Tab // This is the currently open tab @@ -149,6 +143,15 @@ func InitConfigDir() { } configDir = xdgHome + "/micro" + if len(*flagConfigDir) > 0 { + if _, err := os.Stat(*flagConfigDir); os.IsNotExist(err) { + TermMessage("Error: " + *flagConfigDir + " does not exist. Defaulting to " + configDir + ".") + } else { + configDir = *flagConfigDir + return + } + } + if _, err := os.Stat(xdgHome); os.IsNotExist(err) { // If the xdgHome doesn't exist we should create it err = os.Mkdir(xdgHome, os.ModePerm) @@ -183,6 +186,10 @@ func InitScreen() { screen, err = tcell.NewScreen() if err != nil { fmt.Println(err) + if err == tcell.ErrTermNotFound { + fmt.Println("Micro does not recognize your terminal:", oldTerm) + fmt.Println("Please go to https://github.com/zyedidia/mkinfo to read about how to fix this problem (it should be easy to fix).") + } os.Exit(1) } if err = screen.Init(); err != nil { @@ -195,8 +202,11 @@ func InitScreen() { os.Setenv("TERM", oldTerm) } + if GetGlobalOption("mouse").(bool) { + screen.EnableMouse() + } + screen.SetStyle(defStyle) - screen.EnableMouse() } // RedrawAll redraws everything -- all the views and the messenger @@ -215,6 +225,9 @@ func RedrawAll() { } DisplayTabs() messenger.Display() + if globalSettings["keymenu"].(bool) { + DisplayKeyMenu() + } screen.Show() } @@ -243,12 +256,26 @@ func LoadAll() { // Passing -version as a flag will have micro print out the version number var flagVersion = flag.Bool("version", false, "Show the version number and information") var flagStartPos = flag.String("startpos", "", "LINE,COL to start the cursor at when opening a buffer.") +var flagConfigDir = flag.String("config-dir", "", "Specify a custom location for the configuration directory") +var flagOptions = flag.Bool("options", false, "Show all option help") func main() { flag.Usage = func() { fmt.Println("Usage: micro [OPTIONS] [FILE]...") - fmt.Print("Micro's options can be set via command line arguments for quick adjustments. For real configuration, please use the bindings.json file (see 'help options').\n\n") - flag.PrintDefaults() + fmt.Println("-config-dir dir") + fmt.Println(" \tSpecify a custom location for the configuration directory") + fmt.Println("-startpos LINE,COL") + fmt.Println(" \tSpecify a line and column to start the cursor at when opening a buffer") + fmt.Println("-options") + fmt.Println(" \tShow all option help") + fmt.Println("-version") + fmt.Println(" \tShow the version number and information") + + fmt.Print("\nMicro's options can also be set via command line arguments for quick\nadjustments. For real configuration, please use the bindings.json\nfile (see 'help options').\n\n") + fmt.Println("-option value") + fmt.Println(" \tSet `option` to `value` for this session") + fmt.Println(" \tFor example: `micro -syntax off file.c`") + fmt.Println("\nUse `micro -options` to see the full list of configuration options") } optionFlags := make(map[string]*string) @@ -267,6 +294,15 @@ func main() { os.Exit(0) } + if *flagOptions { + // If -options was passed + for k, v := range DefaultGlobalSettings() { + fmt.Printf("-%s value\n", k) + fmt.Printf(" \tThe %s option. Default value: '%v'\n", k, v) + } + os.Exit(0) + } + // Start the Lua VM for running plugins L = lua.NewState() defer L.Close() @@ -306,8 +342,7 @@ func main() { // Create a new messenger // This is used for sending the user messages in the bottom of the editor messenger = new(Messenger) - messenger.history = make(map[string][]string) - InitColorscheme() + messenger.LoadHistory() // Now we load the input buffers := LoadInput() @@ -361,6 +396,7 @@ func main() { L.SetGlobal("Loc", luar.New(L, func(x, y int) Loc { return Loc{x, y} })) + L.SetGlobal("WorkingDirectory", luar.New(L, os.Getwd)) L.SetGlobal("JoinPaths", luar.New(L, filepath.Join)) L.SetGlobal("DirectoryName", luar.New(L, filepath.Dir)) L.SetGlobal("configDir", luar.New(L, configDir)) @@ -381,6 +417,9 @@ func main() { L.SetGlobal("AddRuntimeFilesFromDirectory", luar.New(L, PluginAddRuntimeFilesFromDirectory)) L.SetGlobal("AddRuntimeFileFromMemory", luar.New(L, PluginAddRuntimeFileFromMemory)) + // Access to Go stdlib + L.SetGlobal("import", luar.New(L, Import)) + jobs = make(chan JobFunction, 100) events = make(chan tcell.Event, 100) autosave = make(chan bool) @@ -399,10 +438,14 @@ func main() { } } + InitColorscheme() + // Here is the event loop which runs in a separate thread go func() { for { - events <- screen.PollEvent() + if screen != nil { + events <- screen.PollEvent() + } } }()