X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=cmd%2Fmicro%2Fmicro.go;h=f6360255fa46d9f91c90895a20db5a343ee94363;hb=69b6c724fc6403ee28eadd53e16a9eb08b40fb51;hp=d1c591366c51238bf7079f98471192beef56cc7d;hpb=0301e3539ea3bba36f6105b9d4e40b0a6ff03994;p=micro.git diff --git a/cmd/micro/micro.go b/cmd/micro/micro.go index d1c59136..f6360255 100644 --- a/cmd/micro/micro.go +++ b/cmd/micro/micro.go @@ -5,9 +5,10 @@ import ( "fmt" "io/ioutil" "os" + "runtime" "sort" + "time" - "github.com/zyedidia/tcell" "github.com/go-errors/errors" isatty "github.com/mattn/go-isatty" "github.com/zyedidia/micro/internal/action" @@ -16,6 +17,7 @@ import ( "github.com/zyedidia/micro/internal/screen" "github.com/zyedidia/micro/internal/shell" "github.com/zyedidia/micro/internal/util" + "github.com/zyedidia/tcell" ) var ( @@ -27,22 +29,42 @@ var ( flagVersion = flag.Bool("version", false, "Show the version number and information") flagConfigDir = flag.String("config-dir", "", "Specify a custom location for the configuration directory") flagOptions = flag.Bool("options", false, "Show all option help") + flagDebug = flag.Bool("debug", false, "Enable debug mode (prints debug info to ./log.txt)") + flagPlugin = flag.String("plugin", "", "Plugin command") + flagClean = flag.Bool("clean", false, "Clean configuration directory") optionFlags map[string]*string ) func InitFlags() { flag.Usage = func() { fmt.Println("Usage: micro [OPTIONS] [FILE]...") + fmt.Println("-clean") + fmt.Println(" \tCleans the configuration directory") fmt.Println("-config-dir dir") fmt.Println(" \tSpecify a custom location for the configuration directory") fmt.Println("[FILE]:LINE:COL") fmt.Println(" \tSpecify a line and column to start the cursor at when opening a buffer") - fmt.Println(" \tThis can also be done by opening file:LINE:COL") fmt.Println("-options") fmt.Println(" \tShow all option help") + fmt.Println("-debug") + fmt.Println(" \tEnable debug mode (enables logging to ./log.txt)") fmt.Println("-version") fmt.Println(" \tShow the version number and information") + fmt.Print("\nMicro's plugin's can be managed at the command line with the following commands.\n") + fmt.Println("-plugin install [PLUGIN]...") + fmt.Println(" \tInstall plugin(s)") + fmt.Println("-plugin remove [PLUGIN]...") + fmt.Println(" \tRemove plugin(s)") + fmt.Println("-plugin update [PLUGIN]...") + fmt.Println(" \tUpdate plugin(s) (if no argument is given, updates all plugins)") + fmt.Println("-plugin search [PLUGIN]...") + fmt.Println(" \tSearch for a plugin") + fmt.Println("-plugin list") + fmt.Println(" \tList installed plugins") + fmt.Println("-plugin available") + fmt.Println(" \tList available plugins") + fmt.Print("\nMicro's options can also be set via command line arguments for quick\nadjustments. For real configuration, please use the settings.json\nfile (see 'help options').\n\n") fmt.Println("-option value") fmt.Println(" \tSet `option` to `value` for this session") @@ -81,6 +103,27 @@ func InitFlags() { } os.Exit(0) } + + if util.Debug == "OFF" && *flagDebug { + util.Debug = "ON" + } +} + +// DoPluginFlags parses and executes any flags that require LoadAllPlugins (-plugin and -clean) +func DoPluginFlags() { + if *flagClean || *flagPlugin != "" { + config.LoadAllPlugins() + + if *flagPlugin != "" { + args := flag.Args() + + config.PluginCommand(os.Stdout, *flagPlugin, args) + } else if *flagClean { + CleanConfig() + } + + os.Exit(0) + } } // LoadInput determines which files should be loaded into buffers @@ -143,10 +186,10 @@ func main() { var err error - InitLog() - InitFlags() + InitLog() + err = config.InitConfigDir(*flagConfigDir) if err != nil { screen.TermMessage(err) @@ -171,22 +214,7 @@ func main() { } } - action.InitBindings() - action.InitCommands() - - err = config.InitColorscheme() - if err != nil { - screen.TermMessage(err) - } - - err = config.LoadAllPlugins() - if err != nil { - screen.TermMessage(err) - } - err = config.RunPluginFn("init") - if err != nil { - screen.TermMessage(err) - } + DoPluginFlags() screen.Init() @@ -207,10 +235,35 @@ func main() { } }() + err = config.LoadAllPlugins() + if err != nil { + screen.TermMessage(err) + } + + action.InitBindings() + action.InitCommands() + + err = config.InitColorscheme() + if err != nil { + screen.TermMessage(err) + } + b := LoadInput() + + if len(b) == 0 { + // No buffers to open + screen.Screen.Fini() + runtime.Goexit() + } + action.InitTabs(b) action.InitGlobals() + err = config.RunPluginFn("init") + if err != nil { + screen.TermMessage(err) + } + events = make(chan tcell.Event) // Here is the event loop which runs in a separate thread @@ -225,6 +278,22 @@ func main() { } }() + // clear the drawchan so we don't redraw excessively + // if someone requested a redraw before we started displaying + for len(screen.DrawChan) > 0 { + <-screen.DrawChan + } + + var event tcell.Event + + // wait for initial resize event + select { + case event = <-events: + action.Tabs.HandleEvent(event) + case <-time.After(10 * time.Millisecond): + // time out after 10ms + } + for { // Display everything screen.Screen.Fill(' ', config.DefStyle) @@ -237,7 +306,7 @@ func main() { action.InfoBar.Display() screen.Screen.Show() - var event tcell.Event + event = nil // Check for new events select {