Skip to content

Commit 8609aa0

Browse files
committed
feat: colorful console output
1 parent cafe2ce commit 8609aa0

File tree

4 files changed

+7
-15
lines changed

4 files changed

+7
-15
lines changed

lib/runner.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,24 +97,16 @@ func (r *runner) Exited() bool {
9797

9898
func (r *runner) runBin() error {
9999
r.command = exec.Command(r.bin, r.args...)
100-
stdout, err := r.command.StdoutPipe()
101-
if err != nil {
102-
return err
103-
}
104-
stderr, err := r.command.StderrPipe()
105-
if err != nil {
106-
return err
107-
}
100+
r.command.Stdout = r.writer // Eascaped ansi color code output
101+
r.command.Stderr = r.writer
108102

109-
err = r.command.Start()
103+
err := r.command.Start()
110104
if err != nil {
111105
return err
112106
}
113107

114108
r.starttime = time.Now()
115109

116-
go io.Copy(r.writer, stdout)
117-
go io.Copy(r.writer, stderr)
118110
go r.command.Wait()
119111

120112
return nil

lib/runner_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ func Test_Runner_SetWriter(t *testing.T) {
8585
expect(t, err, nil)
8686

8787
if runtime.GOOS == "windows" {
88-
expect(t, buff.String(), "Hello world\r\n")
88+
expect(t, buff.String(), "\\x1B[01;94mHello world\\x1B[0m\r\n")
8989
} else {
90-
expect(t, buff.String(), "Hello world\n")
90+
expect(t, buff.String(), "\\x1B[01;94mHello world\\x1B[0m\n")
9191
}
9292
}

lib/test_fixtures/writing_output

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/usr/bin/env bash
22
sleep 0.05
3-
echo "Hello world"
3+
echo -e "\x1B[01;94mHello world\x1B[0m"

lib/test_fixtures/writing_output.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@echo Hello world
1+
@echo \x1B[01;94mHello world\x1B[0m

0 commit comments

Comments
 (0)