Skip to content

Commit

Permalink
go-tty.Close() on exit. Should fix #21
Browse files Browse the repository at this point in the history
  • Loading branch information
d4l3k committed Jul 14, 2017
1 parent 133b2b1 commit 517e05b
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions pry/pry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ var (
tty *gotty.TTY
)

func init() {
// Pry does nothing. It only exists so running code without go-pry doesn't throw an error.
func Pry(v ...interface{}) {
}

// Apply drops into a pry shell in the location required.
func Apply(scope *Scope) {
if runtime.GOOS == "windows" {
out = colorable.NewColorableStdout()
}
Expand All @@ -30,23 +35,16 @@ func init() {
if err != nil {
panic(err)
}
}
defer tty.Close()

// Pry does nothing. It only exists so running code without go-pry doesn't throw an error.
func Pry(v ...interface{}) {
}

// Apply drops into a pry shell in the location required.
func Apply(scope *Scope) {
if scope.Files == nil {
scope.Files = map[string]*ast.File{}
}

_, filePathRaw, lineNum, _ := runtime.Caller(1)
filePath := filepath.Dir(filePathRaw) + "/." + filepath.Base(filePathRaw) + "pry"

err := scope.ConfigureTypes(filePath, lineNum)
if err != nil {
if err := scope.ConfigureTypes(filePath, lineNum); err != nil {
panic(err)
}

Expand Down Expand Up @@ -189,7 +187,7 @@ func Apply(scope *Scope) {
index = 0
case 4: // Ctrl-D
fmt.Fprintln(out)
os.Exit(0)
return
}
}
}
Expand Down

0 comments on commit 517e05b

Please sign in to comment.