create and load an empty temp file if no files to open

This commit is contained in:
Felix Angell 2018-04-13 18:28:17 +01:00
parent aa8bf6901f
commit 9b2dbebcd6
2 changed files with 12 additions and 0 deletions

12
main.go
View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"io/ioutil"
"log"
"os"
"runtime"
@ -27,9 +28,20 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
args := os.Args
if len(args) > 1 {
// TODO check these are files
// that actually exist here?
for _, arg := range args[1:] {
mainView.AddBuffer().OpenFile(arg)
}
} else {
// we have no args, open up a scratch file
tempFile, err := ioutil.TempFile("/var/tmp/", "phi-editor-")
if err != nil {
log.Println("Failed to create temp file", err.Error())
os.Exit(1)
}
mainView.AddBuffer().OpenFile(tempFile.Name())
}
n.AddComponent(mainView)

Binary file not shown.