diff options
author | Mateusz Czapliński <czapkofan@gmail.com> | 2018-03-10 21:21:43 +0100 |
---|---|---|
committer | Mateusz Czapliński <czapkofan@gmail.com> | 2018-03-10 21:21:43 +0100 |
commit | ea178bcade42f17c5806b5b02f005a1c5d8a0f66 (patch) | |
tree | 78b407b6a2e666f6ec2fdc04808c68483fc4b52d /up.go | |
parent | 45c25f262a53bb5c09de31b1d009eabb6f9cc8f4 (diff) |
fix to compile
Diffstat (limited to 'up.go')
-rw-r--r-- | up.go | 30 |
1 files changed, 25 insertions, 5 deletions
@@ -50,7 +50,7 @@ main_loop: lastCommand = command subprocess.Kill() subprocess = StartSubprocess(inputBuf, command) - buf = subprocess.Buf() + buf = subprocess.Buf } // Draw command input line @@ -174,6 +174,25 @@ func (b *Buf) putch(x, y int, ch rune) { termbox.SetCell(x, y, ch, termbox.ColorDefault, termbox.ColorDefault) } +func (b *Buf) NewReader() io.Reader { + // TODO: return EOF if input is fully buffered? + i := 0 + return funcReader(func(p []byte) (n int, err error) { + b.nLock.Lock() + end := b.n + b.nLock.Unlock() + // TODO: don't return (0,nil), instead wait until at least 1 available, + // or return EOF on completion? + n = copy(p, b.bytes[i:end]) + i += n + return n, nil + }) +} + +type funcReader func([]byte) (int, error) + +func (f funcReader) Read(p []byte) (int, error) { return f(p) } + type Editor struct { prompt []rune // TODO: make editor multiline. Reuse gocui or something for this? @@ -257,18 +276,18 @@ func (e *Editor) delete(dx int) { } type Subprocess struct { - buf *Buf + Buf *Buf cancel context.CancelFunc } func StartSubprocess(inputBuf *Buf, command string) *Subprocess { ctx, cancel := context.WithCancel(context.TODO()) - s := Subprocess{ - buf: NewBuf(), + s := &Subprocess{ + Buf: NewBuf(), cancel: cancel, } r, w := io.Pipe() - go s.buf.Collect(r) + go s.Buf.Collect(r) cmd := exec.CommandContext(ctx, "bash", "-c", command) cmd.Stdout = w @@ -280,6 +299,7 @@ func StartSubprocess(inputBuf *Buf, command string) *Subprocess { return s } go cmd.Wait() + return s } func (s *Subprocess) Kill() { |