mirror of
https://github.com/felixangell/phi.git
synced 2024-09-11 15:55:25 +03:00
create and load an empty temp file if no files to open
This commit is contained in:
parent
aa8bf6901f
commit
9b2dbebcd6
12
main.go
12
main.go
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
@ -27,9 +28,20 @@ func (n *PhiEditor) init(cfg *cfg.TomlConfig) {
|
|||||||
|
|
||||||
args := os.Args
|
args := os.Args
|
||||||
if len(args) > 1 {
|
if len(args) > 1 {
|
||||||
|
// TODO check these are files
|
||||||
|
// that actually exist here?
|
||||||
for _, arg := range args[1:] {
|
for _, arg := range args[1:] {
|
||||||
mainView.AddBuffer().OpenFile(arg)
|
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)
|
n.AddComponent(mainView)
|
||||||
|
BIN
phi-editor
BIN
phi-editor
Binary file not shown.
Loading…
Reference in New Issue
Block a user