Files
David Dollar c19b25f6e5 Fix up release process (#82)
* remove godeps

* remove dist for now

* add colortext

* godeps

* vendor

* remove unneeded fixture

* fix vendor

* switch to circle

* dont run example during tests

* no circle.yml

* circle release

* fix equinox download

* equinox release

* fix shell

* fix shell

* fix shell

* fix shell

* release from circle-release to test

* release from circle-release

* release from circle-release

* download key

* remove update for now

* back to var for key

* and back to url

* clean up makefile

* date versions

* badge

* only master branch releases
2016-04-13 14:29:46 -07:00

94 lines
1.5 KiB
Go

package main
import (
"bufio"
"bytes"
"fmt"
"io"
"os"
"sync"
ct "github.com/daviddengcn/go-colortext"
)
type OutletFactory struct {
Padding int
sync.Mutex
}
var colors = []ct.Color{
ct.Cyan,
ct.Yellow,
ct.Green,
ct.Magenta,
ct.Red,
ct.Blue,
}
func NewOutletFactory() (of *OutletFactory) {
return new(OutletFactory)
}
func (of *OutletFactory) LineReader(wg *sync.WaitGroup, name string, index int, r io.Reader, isError bool) {
defer wg.Done()
color := colors[index%len(colors)]
reader := bufio.NewReader(r)
var buffer bytes.Buffer
for {
buf := make([]byte, 1024)
if n, err := reader.Read(buf); err != nil {
return
} else {
buf = buf[:n]
}
for {
i := bytes.IndexByte(buf, '\n')
if i < 0 {
break
}
buffer.Write(buf[0:i])
of.WriteLine(name, buffer.String(), color, ct.None, isError)
buffer.Reset()
buf = buf[i+1:]
}
buffer.Write(buf)
}
}
func (of *OutletFactory) SystemOutput(str string) {
of.WriteLine("forego", str, ct.White, ct.None, false)
}
func (of *OutletFactory) ErrorOutput(str string) {
fmt.Printf("ERROR: %s\n", str)
os.Exit(1)
}
// Write out a single coloured line
func (of *OutletFactory) WriteLine(left, right string, leftC, rightC ct.Color, isError bool) {
of.Lock()
defer of.Unlock()
ct.ChangeColor(leftC, true, ct.None, false)
formatter := fmt.Sprintf("%%-%ds | ", of.Padding)
fmt.Printf(formatter, left)
if isError {
ct.ChangeColor(ct.Red, true, ct.None, true)
} else {
ct.ResetColor()
}
fmt.Println(right)
if isError {
ct.ResetColor()
}
}