Create nonexistent file arguments on launch

Fixes #23.
This commit is contained in:
Chris Lee 2018-04-16 01:39:46 -06:00
parent 49e7bce3ea
commit 4706740b0f
No known key found for this signature in database
GPG Key ID: 7A6BDC1FF1DD2862

View File

@ -3,6 +3,7 @@ package gui
import (
"io/ioutil"
"log"
"os"
"path"
"regexp"
"runtime"
@ -79,6 +80,15 @@ func (b *Buffer) OpenFile(filePath string) {
b.languageInfo = lang
}
// if the file doesn't exist, try to create it before reading it
if _, err := os.Stat(filePath); os.IsNotExist(err) {
if f, err = os.Create(filePath); err != nil {
panic(err)
} else {
f.Close()
}
}
contents, err := ioutil.ReadFile(filePath)
if err != nil {
panic(err)