Skip to content

Commit

Permalink
adding build tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Eduard-Voiculescu committed Aug 21, 2024
1 parent 3968498 commit 13b13ac
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 31 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ require (
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/bytecodealliance/wasmtime-go/v4 v4.0.0
github.com/charmbracelet/bubbles v0.18.0
github.com/charmbracelet/bubbletea v0.26.6
github.com/charmbracelet/bubbletea v0.27.0
github.com/charmbracelet/glamour v0.7.0
github.com/charmbracelet/huh v0.5.2
github.com/charmbracelet/huh/spinner v0.0.0-20240806005253-b7436a76999a
Expand Down Expand Up @@ -193,8 +193,8 @@ require (
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.24.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/api v0.172.0 // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ github.com/charmbracelet/bubbles v0.18.0 h1:PYv1A036luoBGroX6VWjQIE9Syf2Wby2oOl/
github.com/charmbracelet/bubbles v0.18.0/go.mod h1:08qhZhtIwzgrtBjAcJnij1t1H0ZRjwHyGsy6AL11PSw=
github.com/charmbracelet/bubbletea v0.26.6 h1:zTCWSuST+3yZYZnVSvbXwKOPRSNZceVeqpzOLN2zq1s=
github.com/charmbracelet/bubbletea v0.26.6/go.mod h1:dz8CWPlfCCGLFbBlTY4N7bjLiyOGDJEnd2Muu7pOWhk=
github.com/charmbracelet/bubbletea v0.27.0 h1:Mznj+vvYuYagD9Pn2mY7fuelGvP0HAXtZYGgRBCbHvU=
github.com/charmbracelet/bubbletea v0.27.0/go.mod h1:5MdP9XH6MbQkgGhnlxUqCNmBXf9I74KRQ8HIidRxV1Y=
github.com/charmbracelet/glamour v0.7.0 h1:2BtKGZ4iVJCDfMF229EzbeR1QRKLWztO9dMtjmqZSng=
github.com/charmbracelet/glamour v0.7.0/go.mod h1:jUMh5MeihljJPQbJ/wf4ldw2+yBP59+ctV36jASy7ps=
github.com/charmbracelet/huh v0.5.2 h1:ofeNkJ4iaFnzv46Njhx896DzLUe/j0L2QAf8znwzX4c=
Expand Down Expand Up @@ -786,6 +788,8 @@ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down Expand Up @@ -852,6 +856,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand Down
47 changes: 32 additions & 15 deletions tui2/buildoutput/buildoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ type BuildOutputMsg struct {
}

type BuildOutput struct {
Cmd *exec.Cmd
StdScanner *bufio.Scanner
ErrScanner *bufio.Scanner
Cmd *exec.Cmd
outputCh chan string
}

func New(cmd *exec.Cmd) *BuildOutput {
return &BuildOutput{
Cmd: cmd,
Cmd: cmd,
outputCh: make(chan string, 99999),
}
}

Expand All @@ -48,33 +48,50 @@ func (b *BuildOutput) Init() tea.Cmd {
}
}

stdScanner := bufio.NewScanner(stdout)
errScanner := bufio.NewScanner(stdErr)

go func() {
for stdScanner.Scan() {
b.outputCh <- stdScanner.Text()
}
}()

go func() {
for errScanner.Scan() {
b.outputCh <- errScanner.Text()
}
}()

if err := b.Cmd.Start(); err != nil {
return func() tea.Msg {
return fmt.Errorf("failed to start command: %w", err)
}
}

b.StdScanner = bufio.NewScanner(stdout)
b.ErrScanner = bufio.NewScanner(stdErr)
return func() tea.Msg {
return BuildStarted
}
}

func (b *BuildOutput) Update(msg tea.Msg) tea.Cmd {
switch msg {
case BuildDoneSuccess:
return func() tea.Msg {
return nil
}
case BuildDoneFailure:
return func() tea.Msg {
return nil
}
}
return b.readNextLine
}

func (b *BuildOutput) readNextLine() tea.Msg {
if b.StdScanner.Scan() {
return BuildOutputMsg{
Msg: b.StdScanner.Text(),
}
}
msg := <-b.outputCh

if b.StdScanner.Err() != nil {
return BuildDoneFailure
return BuildOutputMsg{
Msg: msg,
}

return BuildDoneSuccess
}
13 changes: 8 additions & 5 deletions tui2/pages/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (
type Build struct {
common.Common

ManifestPath string
BuildOutputMsgs []string
buildView viewport.Model
params map[string][]string
ManifestPath string
BuildOutputMsgs []string
BuildOutputErrMsgs []string
buildView viewport.Model
params map[string][]string
}

func New(c common.Common, manifestPath string) *Build {
Expand Down Expand Up @@ -48,6 +49,7 @@ func (b *Build) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
log.Println(msg)
case NewBuildInstance:
b.BuildOutputMsgs = []string{}
b.BuildOutputErrMsgs = []string{}
case buildoutput.BuildOutputMsg:
b.BuildOutputMsgs = append(b.BuildOutputMsgs, msg.Msg)
}
Expand All @@ -57,11 +59,12 @@ func (b *Build) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

func (b *Build) View() string {
outputMsgs := strings.Join(b.BuildOutputMsgs, "\n")
return lipgloss.NewStyle().
Border(lipgloss.NormalBorder(), true).
Width(b.Width - 2).
Height(b.buildView.Height + 2 /* for borders */).
Render(
strings.Join(b.BuildOutputMsgs, "\n"),
outputMsgs,
)
}
2 changes: 0 additions & 2 deletions tui2/pages/build/newbuildinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ type BuildInstance struct {
}

func NewBuild(manifestPath string) (*BuildInstance, error) {
// TODO: could we call the same code that is used in substreams build
// instead of starting a sub process?
cmd := exec.Command("substreams", "build", manifestPath)
buildOut := buildoutput.New(cmd)

Expand Down
6 changes: 0 additions & 6 deletions tui2/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,6 @@ func (ui *UI) update(msg tea.Msg) (tea.Model, tea.Cmd) {
case build.NewBuildInstance:
ui.buildOut = msg.BuildOut
cmds = append(cmds, ui.buildOut.Init())
// case buildoutput.BuildOutputMsg:
// if ui.buildOut != nil {
// cmds = append(cmds, ui.buildOut.Update(msg))
// }
case buildoutput.BuildOutput:
// cmds = append(cmds, tabs.SelectTabCmd(int(buildPage)))
case buildoutput.Msg:
switch msg {
case buildoutput.BuildStarted:
Expand Down

0 comments on commit 13b13ac

Please sign in to comment.