"os"
"path/filepath"
"runtime"
+ "strings"
"time"
"github.com/go-errors/errors"
"github.com/mitchellh/go-homedir"
"github.com/yuin/gopher-lua"
"github.com/zyedidia/clipboard"
+ "github.com/zyedidia/micro/cmd/micro/terminfo"
"github.com/zyedidia/tcell"
"github.com/zyedidia/tcell/encoding"
"layeh.com/gopher-luar"
// Option 1
// We go through each file and load it
for i := 0; i < len(args); i++ {
- filename = args[i]
-
- // Check that the file exists
- var input *os.File
- if _, e := os.Stat(filename); e == nil {
- // If it exists we load it into a buffer
- input, err = os.Open(filename)
- stat, _ := input.Stat()
- defer input.Close()
- if err != nil {
- TermMessage(err)
- continue
- }
- if stat.IsDir() {
- TermMessage("Cannot read", filename, "because it is a directory")
- continue
+ if strings.HasPrefix(args[i], "+") {
+ if strings.Contains(args[i], ":") {
+ split := strings.Split(args[i], ":")
+ *flagStartPos = split[0][1:] + "," + split[1]
+ } else {
+ *flagStartPos = args[i][1:] + ",0"
}
+ continue
}
- // If the file didn't exist, input will be empty, and we'll open an empty buffer
- if input != nil {
- buffers = append(buffers, NewBuffer(input, FSize(input), filename))
- } else {
- buffers = append(buffers, NewBufferFromString("", filename))
+
+ buf, err := NewBufferFromFile(args[i])
+ if err != nil {
+ TermMessage(err)
+ continue
}
+ // If the file didn't exist, input will be empty, and we'll open an empty buffer
+ buffers = append(buffers, buf)
}
} else if !isatty.IsTerminal(os.Stdin.Fd()) {
// Option 2
// Should we enable true color?
truecolor := os.Getenv("MICRO_TRUECOLOR") == "1"
+ tcelldb := os.Getenv("TCELLDB")
+ os.Setenv("TCELLDB", configDir+"/.tcelldb")
+
// In order to enable true color, we have to set the TERM to `xterm-truecolor` when
// initializing tcell, but after that, we can set the TERM back to whatever it was
oldTerm := os.Getenv("TERM")
var err error
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).")
+ terminfo.WriteDB(configDir + "/.tcelldb")
+ screen, err = tcell.NewScreen()
+ if err != nil {
+ fmt.Println(err)
+ fmt.Println("Fatal: Micro could not initialize a screen.")
+ os.Exit(1)
+ }
+ } else {
+ fmt.Println(err)
+ fmt.Println("Fatal: Micro could not initialize a screen.")
+ os.Exit(1)
}
- os.Exit(1)
}
if err = screen.Init(); err != nil {
fmt.Println(err)
screen.EnableMouse()
}
+ os.Setenv("TCELLDB", tcelldb)
+
// screen.SetStyle(defStyle)
}
}
}
- for _, v := range tabs[curTab].views {
+ for _, v := range tabs[curTab].Views {
v.Display()
}
DisplayTabs()
InitColorscheme()
for _, tab := range tabs {
- for _, v := range tab.views {
+ for _, v := range tab.Views {
v.Buf.UpdateRules()
}
}
fmt.Println("-config-dir dir")
fmt.Println(" \tSpecify a custom location for the configuration directory")
fmt.Println("-startpos LINE,COL")
+ fmt.Println("+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("-version")
tab.SetNum(len(tabs))
tabs = append(tabs, tab)
for _, t := range tabs {
- for _, v := range t.views {
+ for _, v := range t.Views {
v.Center(false)
}
L.SetGlobal("GetLeadingWhitespace", luar.New(L, GetLeadingWhitespace))
L.SetGlobal("MakeCompletion", luar.New(L, MakeCompletion))
L.SetGlobal("NewBuffer", luar.New(L, NewBufferFromString))
+ L.SetGlobal("NewBufferFromFile", luar.New(L, NewBufferFromFile))
L.SetGlobal("RuneStr", luar.New(L, func(r rune) string {
return string(r)
}))
LoadPlugins()
for _, t := range tabs {
- for _, v := range t.views {
+ for _, v := range t.Views {
GlobalPluginCall("onViewOpen", v)
GlobalPluginCall("onBufferOpen", v.Buf)
}
case <-updateterm:
continue
case vnum := <-closeterm:
- tabs[curTab].views[vnum].CloseTerminal()
+ tabs[curTab].Views[vnum].CloseTerminal()
case event = <-events:
}
if CurView().mouseReleased {
// We loop through each view in the current tab and make sure the current view
// is the one being clicked in
- for _, v := range tabs[curTab].views {
+ for _, v := range tabs[curTab].Views {
if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
tabs[curTab].CurView = v.Num
}
} else if e.Buttons() == tcell.WheelUp || e.Buttons() == tcell.WheelDown {
var view *View
x, y := e.Position()
- for _, v := range tabs[curTab].views {
+ for _, v := range tabs[curTab].Views {
if x >= v.x && x < v.x+v.Width && y >= v.y && y < v.y+v.Height {
- view = tabs[curTab].views[v.Num]
+ view = tabs[curTab].Views[v.Num]
}
}
if view != nil {