]> git.lizzy.rs Git - micro.git/blobdiff - cmd/micro/command.go
Fix crash
[micro.git] / cmd / micro / command.go
index 028493c9bf524006c7635258917b095a1af1a763..dac6ed58a7bbf7d03f1f63e7d82f2adfb60370e2 100644 (file)
@@ -16,8 +16,8 @@ func RunShellCommand(input string) (string, error) {
 
        cmd := exec.Command(inputCmd, args...)
        outputBytes := &bytes.Buffer{}
-
-       cmd.Stdout = outputBytes // send output to buffer
+       cmd.Stdout = outputBytes
+       cmd.Stderr = outputBytes
        cmd.Start()
        err := cmd.Wait() // wait for command to finish
        outstring := outputBytes.String()
@@ -37,7 +37,7 @@ func HandleShellCommand(input string, view *View, openTerm bool) {
                                if err == nil {
                                        messenger.Message(inputCmd, " exited without error")
                                } else {
-                                       messenger.Message(inputCmd, " exited with error: ", err)
+                                       messenger.Message(inputCmd, " exited with error: ", err, ": ", output)
                                }
                        } else {
                                messenger.Message(output)
@@ -46,6 +46,7 @@ func HandleShellCommand(input string, view *View, openTerm bool) {
                }()
        } else {
                screen.Fini()
+               screen = nil
 
                args := strings.Split(input, " ")[1:]
 
@@ -140,20 +141,41 @@ func HandleCommand(input string, view *View) {
 
                found := false
                for {
-                       match := regex.FindStringIndex(view.buf.text)
+                       match := regex.FindStringIndex(view.Buf.String())
                        if match == nil {
                                break
                        }
                        found = true
                        if strings.Contains(flags, "c") {
-                               //      // The 'check' flag was used
-                               //      if messenger.YesNoPrompt("Perform replacement?") {
-                               //              view.eh.Replace(match[0], match[1], replace)
-                               //      } else {
-                               //              continue
-                               //      }
+                               // The 'check' flag was used
+                               Search(search, view, true)
+                               view.Relocate()
+                               Redraw(view)
+                               choice, canceled := messenger.YesNoPrompt("Perform replacement? (y,n)")
+                               if canceled {
+                                       if view.Cursor.HasSelection() {
+                                               view.Cursor.SetLoc(view.Cursor.curSelection[0])
+                                               view.Cursor.ResetSelection()
+                                       }
+                                       messenger.Reset()
+                                       return
+                               }
+                               if choice {
+                                       view.Cursor.DeleteSelection()
+                                       view.Buf.Insert(match[0], replace)
+                                       view.Cursor.ResetSelection()
+                                       messenger.Reset()
+                               } else {
+                                       if view.Cursor.HasSelection() {
+                                               searchStart = view.Cursor.curSelection[1]
+                                       } else {
+                                               searchStart = ToCharPos(view.Cursor.x, view.Cursor.y, view.Buf)
+                                       }
+                                       continue
+                               }
+                       } else {
+                               view.Buf.Replace(match[0], match[1], replace)
                        }
-                       view.eh.Replace(match[0], match[1], replace)
                }
                if !found {
                        messenger.Message("Nothing matched " + search)