func (rf readerFrom) ReadFrom(r io.Reader) (int64, error) { cr := newCountingRuneReader(r) err := rf.ed.do(func() (addr, error) { at, err := rf.a.where(rf.ed) if err != nil { return addr{}, err } return at, pend(rf.ed, at, runes.RunesReader(cr)) }) return cr.n, err }
func (e pipe) do(ed *Editor, w io.Writer) (addr, error) { at, err := e.a.where(ed) if err != nil { return addr{}, err } cmd := exec.Command(shell(), "-c", e.cmd) cmd.Stderr = w if e.to { r := ed.buf.runes.Reader(at.from) r = runes.LimitReader(r, at.size()) cmd.Stdin = runes.UTF8Reader(r) } if !e.from { cmd.Stdout = w if err := cmd.Run(); err != nil { return addr{}, err } return at, nil } r, err := cmd.StdoutPipe() if err != nil { return addr{}, err } if err := cmd.Start(); err != nil { return addr{}, err } pendErr := pend(ed, at, runes.RunesReader(bufio.NewReader(r))) if err = cmd.Wait(); err != nil { return addr{}, err } if pendErr != nil { return addr{}, pendErr } return at, nil }