LoadInput determines which files should be loaded into buffers based on the input stored in flag.Args()
(args []string)
| 147 | // LoadInput determines which files should be loaded into buffers |
| 148 | // based on the input stored in flag.Args() |
| 149 | func LoadInput(args []string) []*buffer.Buffer { |
| 150 | // There are a number of ways micro should start given its input |
| 151 | |
| 152 | // 1. If it is given a files in flag.Args(), it should open those |
| 153 | |
| 154 | // 2. If there is no input file and the input is not a terminal, that means |
| 155 | // something is being piped in and the stdin should be opened in an |
| 156 | // empty buffer |
| 157 | |
| 158 | // 3. If there is no input file and the input is a terminal, an empty buffer |
| 159 | // should be opened |
| 160 | |
| 161 | buffers := make([]*buffer.Buffer, 0, len(args)) |
| 162 | |
| 163 | files := make([]string, 0, len(args)) |
| 164 | |
| 165 | flagStartPos := buffer.Loc{-1, -1} |
| 166 | posFlagr := regexp.MustCompile(`^\+(\d+)(?::(\d+))?$`) |
| 167 | posIndex := -1 |
| 168 | |
| 169 | searchText := "" |
| 170 | searchFlagr := regexp.MustCompile(`^\+\/(.+)$`) |
| 171 | searchIndex := -1 |
| 172 | |
| 173 | for i, a := range args { |
| 174 | posMatch := posFlagr.FindStringSubmatch(a) |
| 175 | if len(posMatch) == 3 && posMatch[2] != "" { |
| 176 | line, err := strconv.Atoi(posMatch[1]) |
| 177 | if err != nil { |
| 178 | screen.TermMessage(err) |
| 179 | continue |
| 180 | } |
| 181 | col, err := strconv.Atoi(posMatch[2]) |
| 182 | if err != nil { |
| 183 | screen.TermMessage(err) |
| 184 | continue |
| 185 | } |
| 186 | flagStartPos = buffer.Loc{col - 1, line - 1} |
| 187 | posIndex = i |
| 188 | } else if len(posMatch) == 3 && posMatch[2] == "" { |
| 189 | line, err := strconv.Atoi(posMatch[1]) |
| 190 | if err != nil { |
| 191 | screen.TermMessage(err) |
| 192 | continue |
| 193 | } |
| 194 | flagStartPos = buffer.Loc{0, line - 1} |
| 195 | posIndex = i |
| 196 | } else { |
| 197 | searchMatch := searchFlagr.FindStringSubmatch(a) |
| 198 | if len(searchMatch) == 2 { |
| 199 | searchText = searchMatch[1] |
| 200 | searchIndex = i |
| 201 | } else { |
| 202 | files = append(files, a) |
| 203 | } |
| 204 | } |
| 205 | } |
| 206 |