diff --git a/.gitignore b/.gitignore index 2a0d8ca..b1d9016 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ *.iml *.ipr *.playground +*.swp vendor/ code-playground \ No newline at end of file diff --git a/editor.go b/editor.go index d8fb28d..14d0e24 100644 --- a/editor.go +++ b/editor.go @@ -11,12 +11,14 @@ const DefaultEditor = "vim" type Editor struct { File string + Type string Content string } -func NewEditor(file, content string) *Editor { +func NewEditor(file, t, content string) *Editor { return &Editor{ File: file, + Type: t, Content: content, } } @@ -55,7 +57,7 @@ func (e *Editor) Open() (string, error) { if len(e.File) > 0 { - e.File = e.File + ".playground" + e.File = e.File + ".playground" + e.Type file, err = os.Open(e.File) @@ -85,7 +87,7 @@ func (e *Editor) Open() (string, error) { } else { - file, err = ioutil.TempFile(os.TempDir(), "play-*.playground") + file, err = ioutil.TempFile(os.TempDir(), "play-*.playground"+e.Type) if err != nil { return "", err diff --git a/go.go b/go.go index 5848471..e8420dd 100644 --- a/go.go +++ b/go.go @@ -41,6 +41,10 @@ type Go struct { Code string } +func (r *Go) Type() string { + return ".go" +} + func (g *Go) Init(code string) { g.Code = code } diff --git a/main.go b/main.go index c6c0b24..f52bc92 100644 --- a/main.go +++ b/main.go @@ -23,7 +23,7 @@ func main() { init = playground.Import(path) } - editor := NewEditor(file, init) + editor := NewEditor(file, playground.Type(), init) code, err := editor.Open() diff --git a/playground.go b/playground.go index b7b830b..3f6ec6d 100644 --- a/playground.go +++ b/playground.go @@ -6,4 +6,5 @@ type IPlayground interface { Evaluate() Share() Default() string + Type() string } diff --git a/rust.go b/rust.go index beb0d05..25a1d5f 100644 --- a/rust.go +++ b/rust.go @@ -42,6 +42,10 @@ type Rust struct { Code string } +func (r *Rust) Type() string { + return ".rs" +} + func (r *Rust) Init(code string) { r.Code = code }