Monorepo for Tangled
tangled.org
1package ssh
2
3import (
4 "time"
5
6 tea "github.com/charmbracelet/bubbletea"
7 "github.com/gorilla/websocket"
8 "tangled.org/core/appview/pipelines"
9 spindlemodel "tangled.org/core/spindle/models"
10)
11
12type step struct {
13 id int
14 name string
15 command string
16 kind spindlemodel.StepKind
17 lines []string
18 startTime time.Time
19 endTime time.Time
20 finished bool
21}
22
23type logDoneMsg struct {
24 workflow string
25 err error
26}
27
28type logEventMsg struct {
29 workflow string
30 ev pipelines.LogEvent
31 conn *websocket.Conn
32 ch chan pipelines.LogEvent
33}
34
35func readNextCmd(workflow string, conn *websocket.Conn, ch chan pipelines.LogEvent) tea.Cmd {
36 return func() tea.Msg {
37 return readNextLogEvent(workflow, conn, ch)
38 }
39}
40
41func readNextLogEvent(workflow string, conn *websocket.Conn, ch chan pipelines.LogEvent) tea.Msg {
42 ev, ok := <-ch
43 if !ok {
44 return logDoneMsg{workflow: workflow}
45 }
46 return logEventMsg{workflow: workflow, ev: ev, conn: conn, ch: ch}
47}