Skip to content

Commit

Permalink
feat: colorful console output
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-h committed Feb 28, 2018
1 parent cafe2ce commit 84b795b
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
14 changes: 3 additions & 11 deletions lib/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,16 @@ func (r *runner) Exited() bool {

func (r *runner) runBin() error {
r.command = exec.Command(r.bin, r.args...)
stdout, err := r.command.StdoutPipe()
if err != nil {
return err
}
stderr, err := r.command.StderrPipe()
if err != nil {
return err
}
r.command.Stdout = r.writer // Eascaped ansi color code output
r.command.Stderr = r.writer

err = r.command.Start()
err := r.command.Start()
if err != nil {
return err
}

r.starttime = time.Now()

go io.Copy(r.writer, stdout)
go io.Copy(r.writer, stderr)
go r.command.Wait()

return nil
Expand Down
2 changes: 1 addition & 1 deletion lib/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func Test_Runner_SetWriter(t *testing.T) {
expect(t, err, nil)

if runtime.GOOS == "windows" {
expect(t, buff.String(), "Hello world\r\n")
expect(t, buff.String(), "\\x1B[01;94mHello world\\x1B[0m\r\n")
} else {
expect(t, buff.String(), "Hello world\n")
}
Expand Down
2 changes: 1 addition & 1 deletion lib/test_fixtures/writing_output
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash
sleep 0.05
echo "Hello world"
echo -e "\x1B[01;94mHello world\x1B[0m"
2 changes: 1 addition & 1 deletion lib/test_fixtures/writing_output.bat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
@echo Hello world
@echo \x1B[01;94mHello world\x1B[0m

0 comments on commit 84b795b

Please sign in to comment.