@@ -3,7 +3,6 @@ package scrolls
33import (
44 "bufio"
55 "bytes"
6- "errors"
76 "fmt"
87 "log"
98 "os"
@@ -69,7 +68,7 @@ func (c *StorageClient) New(name string, useTemplate bool, fromFile string) (*li
6968 if fromFile != "" {
7069 ffbyte , err := os .ReadFile (fromFile )
7170 if err != nil {
72- return nil , errors . New ("failed to read the content of \" %s \" ; is the path correct?" )
71+ return nil , fmt . Errorf ("failed to read the content of %q ; is the path correct?" , fromFile )
7372 }
7473
7574 templateContent = ffbyte
@@ -166,7 +165,7 @@ func (c *StorageClient) editFile(f *FileHandler, scroll *library.Scroll) (*FileH
166165 cmd .Stdout = os .Stdout
167166 cmd .Stderr = os .Stderr
168167
169- log .Printf ("opening in: %s, waiting to editor to close before proceeding..\n " , bin )
168+ log .Printf ("opening in: %s, waiting for editor to close before proceeding..\n " , bin )
170169
171170 now := time .Now ().Add (time .Second * time .Duration (2 )).Unix ()
172171 err := cmd .Run ()
@@ -176,27 +175,28 @@ func (c *StorageClient) editFile(f *FileHandler, scroll *library.Scroll) (*FileH
176175 }
177176
178177 end := time .Now ().Unix ()
179-
178+ isQuick := end <= now
180179 if flags .Debug () {
181- fmt .Printf ("opening in external editor \" %s \" : %t\n " , bin , now > end )
180+ fmt .Printf ("editor %q exited quickly : %t\n " , bin , isQuick )
182181 }
183182
184- if now > end {
183+ if isQuick {
185184 fmt .Println ("When you are done, Press Enter to continue.." )
186- bufio .NewReader (os .Stdin ).ReadString ('\n' )
185+ _ , _ = bufio .NewReader (os .Stdin ).ReadString ('\n' )
187186 }
188187
189188 _ , err = f .Read ()
190189 if err != nil {
191190 return f , err
192191 }
193192
193+ defer f .Delete ()
194+
194195 if scroll != nil {
195196 if bytes .Equal (f .Body (), scroll .Body ()) {
196197 return f , nil
197198 }
198199 }
199200
200- f .Delete ()
201201 return f , nil
202202}
0 commit comments