var filename string
var input []byte
var err error
- var buffers []*Buffer
+ args := flag.Args()
+ buffers := make([]*Buffer, 0, len(args))
- if len(flag.Args()) > 0 {
+ if len(args) > 0 {
// Option 1
// We go through each file and load it
- for i := 0; i < len(flag.Args()); i++ {
- filename = flag.Args()[i]
+ for i := 0; i < len(args); i++ {
+ filename = args[i]
// Check that the file exists
var input *os.File
}
// 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, filename))
+ buffers = append(buffers, NewBuffer(input, FSize(input), filename))
} else {
- buffers = append(buffers, NewBuffer(strings.NewReader(""), filename))
+ buffers = append(buffers, NewBufferFromString("", filename))
}
}
} else if !isatty.IsTerminal(os.Stdin.Fd()) {
TermMessage("Error reading from stdin: ", err)
input = []byte{}
}
- buffers = append(buffers, NewBuffer(strings.NewReader(string(input)), filename))
+ buffers = append(buffers, NewBufferFromString(string(input), filename))
} else {
// Option 3, just open an empty buffer
- buffers = append(buffers, NewBuffer(strings.NewReader(string(input)), filename))
+ buffers = append(buffers, NewBufferFromString(string(input), filename))
}
return buffers
// RedrawAll redraws everything -- all the views and the messenger
func RedrawAll() {
messenger.Clear()
- screen.Clear()
+
+ w, h := screen.Size()
+ for x := 0; x < w; x++ {
+ for y := 0; y < h; y++ {
+ screen.SetContent(x, y, ' ', nil, defStyle)
+ }
+ }
+
for _, v := range tabs[curTab].views {
v.Display()
}
InitCommands()
InitBindings()
- LoadSyntaxFiles()
+ InitColorscheme()
for _, tab := range tabs {
for _, v := range tab.views {
v.Buf.UpdateRules()
- if v.Buf.Settings["syntax"].(bool) {
- v.matches = Match(v)
- }
}
}
}
// This is used for sending the user messages in the bottom of the editor
messenger = new(Messenger)
messenger.history = make(map[string][]string)
+ InitColorscheme()
// Now we load the input
buffers := LoadInput()
screen.Fini()
os.Exit(1)
}
+
for _, buf := range buffers {
// For each buffer we create a new tab and place the view in that tab
tab := NewTabFromView(NewView(buf))
L.SetGlobal("ListRuntimeFiles", luar.New(L, PluginListRuntimeFiles))
L.SetGlobal("AddRuntimeFile", luar.New(L, PluginAddRuntimeFile))
L.SetGlobal("AddRuntimeFilesFromDirectory", luar.New(L, PluginAddRuntimeFilesFromDirectory))
+ L.SetGlobal("AddRuntimeFileFromMemory", luar.New(L, PluginAddRuntimeFileFromMemory))
jobs = make(chan JobFunction, 100)
events = make(chan tcell.Event, 100)
LoadPlugins()
- // Load the syntax files, including the colorscheme
- LoadSyntaxFiles()
-
for _, t := range tabs {
for _, v := range t.views {
- v.Buf.FindFileType()
- v.Buf.UpdateRules()
for pl := range loadedPlugins {
_, err := Call(pl+".onViewOpen", v)
if err != nil && !strings.HasPrefix(err.Error(), "function does not exist") {
continue
}
}
- if v.Buf.Settings["syntax"].(bool) {
- v.matches = Match(v)
- }
}
}
default:
event = nil
}
-
}
}
}