package main

import (
	"io"
	"os"
	"bufio"
	"github.com/chrisseto/pty"
	"os/exec"
)

type Cmd struct {
	*exec.Cmd
	Pty    *os.File
	output io.Reader
	Output chan []byte
}

func Command(prog string, args ...string) *Cmd {
	return &Cmd{exec.Command(prog, args...), nil, nil, nil}
}

func (c *Cmd) Start(width, height int) error {
	pterm, err := pty.Start(c.Cmd)
	if err != nil {
		return err
	}
  if err = pty.Setsize(pterm, uint16(width), uint16(height)); err != nil {
    panic(err)
  }
	c.Pty = pterm
	c.Output = make(chan []byte, 20)
	c.output = bufio.NewReader(c.Pty)
	go c.outputPipe()
	return nil
}

func (c *Cmd) Close() error {
	return c.Process.Kill()
}

func (c *Cmd) outputPipe() {
	buf := make([]byte, 32*1024)
	for {
		nr, err := c.output.Read(buf)
		if nr > 0 {
			c.Output <- buf[0:nr]
		}
		if err != nil {
			if err == io.EOF {
				break
			}
			panic(err)
		}

	}
	close(c.Output)
}

package main

import (
	"bufio"
	"github.com/kr/pty"
	"io"
	"os"
	"os/exec"
)

type Cmd struct {
	*exec.Cmd
	Pty    *os.File
	output io.Reader
	Output chan []byte
}

func Command(prog string, args ...string) *Cmd {
	return &Cmd{exec.Command(prog, args...), nil, nil, nil}
}

func (c *Cmd) Start() error {
	pterm, err := pty.Start(c.Cmd)
	if err != nil {
		return err
	}
	c.Pty = pterm
	c.Output = make(chan []byte, 20)
	c.output = bufio.NewReader(c.Pty)
	go c.outputPipe()
	return nil
}

func (c *Cmd) Close() error {
	return c.Process.Kill()
}

func (c *Cmd) outputPipe() {
	buf := make([]byte, 32*1024)
	for {
		nr, err := c.output.Read(buf)
		if nr > 0 {
			c.Output <- buf[0:nr]
		}
		if err != nil {
			if err == io.EOF {
				break
			}
			panic(err)
		}

	}
	close(c.Output)
}

--- 
+++ 
@@ -1,10 +1,10 @@
 package main
 
 import (
-	"bufio"
-	"github.com/kr/pty"
 	"io"
 	"os"
+	"bufio"
+	"github.com/chrisseto/pty"
 	"os/exec"
 )
 
@@ -19,11 +19,14 @@
 	return &Cmd{exec.Command(prog, args...), nil, nil, nil}
 }
 
-func (c *Cmd) Start() error {
+func (c *Cmd) Start(width, height int) error {
 	pterm, err := pty.Start(c.Cmd)
 	if err != nil {
 		return err
 	}
+  if err = pty.Setsize(pterm, uint16(width), uint16(height)); err != nil {
+    panic(err)
+  }
 	c.Pty = pterm
 	c.Output = make(chan []byte, 20)
 	c.output = bufio.NewReader(c.Pty)
Switch to my fork of pty which supports SetSize
