| 73 | } |
| 74 | |
| 75 | func (e *Editor) EditContent() (content string, err error) { |
| 76 | b, err := e.openAndEdit() |
| 77 | if err != nil { |
| 78 | return |
| 79 | } |
| 80 | |
| 81 | b = bytes.TrimSpace(b) |
| 82 | reader := bytes.NewReader(b) |
| 83 | scanner := bufio.NewScanner(reader) |
| 84 | unquotedLines := []string{} |
| 85 | |
| 86 | scissorsLine := e.CS + " " + Scissors |
| 87 | for scanner.Scan() { |
| 88 | line := scanner.Text() |
| 89 | if line == scissorsLine { |
| 90 | break |
| 91 | } |
| 92 | unquotedLines = append(unquotedLines, line) |
| 93 | } |
| 94 | if err = scanner.Err(); err != nil { |
| 95 | return |
| 96 | } |
| 97 | |
| 98 | content = strings.Join(unquotedLines, "\n") |
| 99 | return |
| 100 | } |
| 101 | |
| 102 | func (e *Editor) openAndEdit() (content []byte, err error) { |
| 103 | err = e.writeContent() |