@@ -57,7 +57,7 @@ func packOutput(input io.Reader, output func(string)) {
5757 }
5858}
5959
60- func runImpl (base string , datapath string , done chan struct {} ) (* os.File , func ()) {
60+ func runImpl (base string , datapath string , done chan bool ) (* os.File , func ()) {
6161 abs , err := filepath .Abs (base )
6262 if err != nil {
6363 panic (err )
@@ -69,13 +69,17 @@ func runImpl(base string, datapath string, done chan struct{}) (*os.File, func()
6969 if err != nil {
7070 panic (err )
7171 }
72+ status := true
73+ selfLock := make (chan struct {}, 1 )
7274 go func () {
7375 cmd .Wait ()
74- done <- struct {}{}
76+ selfLock <- struct {}{}
77+ done <- status
7578 }()
7679 return f , func () {
80+ status = false
7781 cmd .Process .Signal (os .Interrupt )
78- cmd . Wait ()
82+ <- selfLock
7983 }
8084}
8185
@@ -86,7 +90,7 @@ func run(base, datapath, logfile string, prompt *fasttemplate.Template) bool {
8690 return false
8791 }
8892 defer log .Close ()
89- proc := make (chan struct {} , 1 )
93+ proc := make (chan bool , 1 )
9094 f , stop := runImpl (base , datapath , proc )
9195 defer f .Close ()
9296 defer stop ()
@@ -149,38 +153,29 @@ func run(base, datapath, logfile string, prompt *fasttemplate.Template) bool {
149153 }
150154 }
151155 })
152- rlock := make (chan struct {}, 1 )
153- go func () {
154- for {
155- line , err := rl .Readline ()
156- if err == readline .ErrInterrupt {
157- if len (line ) == 0 {
158- break
159- } else {
160- continue
161- }
162- } else if err == io .EOF {
156+ for {
157+ line , err := rl .Readline ()
158+ if err == readline .ErrInterrupt {
159+ if len (line ) == 0 {
163160 break
161+ } else {
162+ continue
164163 }
165- line = strings . TrimSpace ( line )
166- switch {
167- case strings . HasPrefix ( line , ":restart" ):
168- status = true
169- fallthrough
170- case strings .HasPrefix (line , ":quit " ):
171- rlock <- struct {}{}
172- return
173- default :
174- cache ++
175- execFn ( "console" , line )
176- }
164+ } else if err == io . EOF {
165+ break
166+ }
167+ line = strings . TrimSpace ( line )
168+ switch {
169+ case strings .HasPrefix (line , ":restart " ):
170+ return true
171+ case strings . HasPrefix ( line , ":quit" ):
172+ return status
173+ default :
174+ cache ++
175+ execFn ( "console" , line )
177176 }
178- }()
179- select {
180- case <- proc :
181- case <- rlock :
182177 }
183- return status
178+ return false
184179}
185180
186181func prepare (data , link string ) {
0 commit comments