Skip to content

Commit

Permalink
feat: highlight code block output errors
Browse files Browse the repository at this point in the history
  • Loading branch information
daulet committed Sep 2, 2024
1 parent 164e84c commit c7bdc01
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 5 deletions.
17 changes: 17 additions & 0 deletions cmd/color.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package main

import (
"io"

"github.com/fatih/color"
)

type colorWriter struct {
io.Writer
*color.Color
}

func (c *colorWriter) Write(p []byte) (n int, err error) {
c.Color.Fprint(c.Writer, string(p))
return len(p), nil
}
11 changes: 8 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/daulet/cmd/config"
"github.com/daulet/cmd/parser"
"github.com/daulet/cmd/provider"

"github.com/fatih/color"
)

const (
Expand Down Expand Up @@ -148,7 +150,10 @@ func runBlock(block *parser.CodeBlock) error {
func runCmd(prog string, args ...string) error {
cmd := exec.Command(prog, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stderr = &colorWriter{
Writer: os.Stderr,
Color: color.New(color.FgHiRed),
}
return cmd.Run()
}

Expand Down Expand Up @@ -254,7 +259,7 @@ func cmd(ctx context.Context) error {
go func() {
defer close(done)
for block := range blockCh {
runBlock(block)
_ = runBlock(block)
}
}()
// no output to the user, we just execute the code
Expand Down Expand Up @@ -376,7 +381,7 @@ func main() {
}

if err := cmd(ctx); err != nil {
fmt.Println(err)
color.Yellow("error: %v", err)
os.Exit(1)
}
}
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ go 1.23.0

require (
github.com/cohere-ai/cohere-go/v2 v2.7.0
github.com/fatih/color v1.17.0
github.com/sashabaranov/go-openai v1.29.0
)

require github.com/google/uuid v1.4.0 // indirect
require (
github.com/google/uuid v1.4.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/sys v0.18.0 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,24 @@ github.com/cohere-ai/cohere-go/v2 v2.7.0 h1:O9XYYTtMvDdREbw3UzLgDXt+pWhdwHOTLyPt
github.com/cohere-ai/cohere-go/v2 v2.7.0/go.mod h1:dlDCT66i8BqZDuuskFvYzsrc+O0M4l5J9Ibckoflvt4=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/google/uuid v1.4.0 h1:MtMxsa51/r9yyhkyLsVeVt0B+BGQZzpQiTQ4eHZ8bc4=
github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sashabaranov/go-openai v1.29.0 h1:eBH6LSjtX4md5ImDCX8hNhHQvaRf22zujiERoQpsvLo=
github.com/sashabaranov/go-openai v1.29.0/go.mod h1:lj5b/K+zjTSFxVLijLSTDZuP7adOgerWeFyZLUhAKRg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
4 changes: 3 additions & 1 deletion provider/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func NewCacheProvider(p Provider, cachePath string) (ProviderCloser, error) {
}
return nil, err
}
cache := &cache{}
cache := &cache{
AudioSegments: make(map[string][]*AudioSegment),
}
if err := json.Unmarshal(data, cache); err != nil {
return nil, err
}
Expand Down

0 comments on commit c7bdc01

Please sign in to comment.