Stepping and showing execution point now work
This commit is contained in:
30
ui/model.go
30
ui/model.go
@@ -16,8 +16,11 @@ type Model struct {
|
||||
width int
|
||||
height int
|
||||
|
||||
bridge *bridge.Bridge
|
||||
listenBridge chan string
|
||||
bridge *bridge.Bridge
|
||||
listenBridge chan string
|
||||
listenBridgeExecutionsStopped chan bridge.ExecutionPoint
|
||||
|
||||
currExecutionPoint bridge.ExecutionPoint
|
||||
|
||||
messages []string
|
||||
stdoutOutput viewport.Model
|
||||
@@ -29,6 +32,7 @@ type Model struct {
|
||||
|
||||
func NewModel(b *bridge.Bridge, file string, text string) Model {
|
||||
c := b.Subscribe()
|
||||
c2 := b.SubscribeStopped()
|
||||
|
||||
stdoutOutput := viewport.New(0, 0)
|
||||
codeViewer := viewport.New(0, 0)
|
||||
@@ -38,9 +42,14 @@ func NewModel(b *bridge.Bridge, file string, text string) Model {
|
||||
text: text,
|
||||
textLines: len(strings.Split(text, "\n")),
|
||||
|
||||
bridge: b,
|
||||
listenBridge: c,
|
||||
bridge: b,
|
||||
listenBridge: c,
|
||||
listenBridgeExecutionsStopped: c2,
|
||||
|
||||
currExecutionPoint: bridge.ExecutionPoint{
|
||||
File: file,
|
||||
Line: 0,
|
||||
},
|
||||
breakpoints: make(map[string][]int),
|
||||
messages: make([]string, 0),
|
||||
|
||||
@@ -57,8 +66,19 @@ func ListenBridge(ch <-chan string) tea.Cmd {
|
||||
}
|
||||
}
|
||||
|
||||
func ListenBridgeExecutionsStopped(ch <-chan bridge.ExecutionPoint) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
msg := <-ch
|
||||
return ExecutionStoppedMsg(msg)
|
||||
}
|
||||
}
|
||||
|
||||
type ExecutionStoppedMsg bridge.ExecutionPoint
|
||||
type StdoutMsg string
|
||||
|
||||
func (m Model) Init() tea.Cmd {
|
||||
return ListenBridge(m.listenBridge)
|
||||
return tea.Batch(
|
||||
ListenBridge(m.listenBridge),
|
||||
ListenBridgeExecutionsStopped(m.listenBridgeExecutionsStopped),
|
||||
)
|
||||
}
|
||||
|
||||
14
ui/update.go
14
ui/update.go
@@ -1,8 +1,10 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"strings"
|
||||
|
||||
"git.pablu.de/pablu/pybug/internal/bridge"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
@@ -17,6 +19,9 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.stdoutOutput.SetContent(strings.Join(m.messages, ""))
|
||||
m.stdoutOutput.GotoBottom()
|
||||
return m, ListenBridge(m.listenBridge)
|
||||
case ExecutionStoppedMsg:
|
||||
m.currExecutionPoint = bridge.ExecutionPoint(msg)
|
||||
return m, ListenBridgeExecutionsStopped(m.listenBridgeExecutionsStopped)
|
||||
}
|
||||
|
||||
return m, nil
|
||||
@@ -61,8 +66,17 @@ func (m Model) HandleKeyMsg(key tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
lineNumber,
|
||||
}
|
||||
}
|
||||
case "s":
|
||||
m.bridge.Step()
|
||||
case "c":
|
||||
m.bridge.Continue()
|
||||
case "r":
|
||||
m.messages = make([]string, 0)
|
||||
m.stdoutOutput.SetContent("")
|
||||
err := m.bridge.Start()
|
||||
if err != nil {
|
||||
slog.Error("could not start brige", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
return m, nil
|
||||
|
||||
@@ -30,15 +30,20 @@ func (m Model) View() string {
|
||||
for i, line := range lines {
|
||||
breakpoint := " "
|
||||
cursor := " "
|
||||
executor := " "
|
||||
|
||||
if slices.Contains(breakpoints, i+1) {
|
||||
breakpoint = "O"
|
||||
}
|
||||
|
||||
if i+1 == m.currExecutionPoint.Line {
|
||||
executor = "!"
|
||||
}
|
||||
|
||||
if i == m.cursor {
|
||||
cursor = ">"
|
||||
}
|
||||
fmt.Fprintf(&out, "%-4d%s%s %s\n", i+1, breakpoint, cursor, line)
|
||||
fmt.Fprintf(&out, "%-4d%s%s%s %s\n", i+1, breakpoint, executor, cursor, line)
|
||||
}
|
||||
|
||||
m.codeViewer.SetContent(out.String())
|
||||
|
||||
Reference in New Issue
Block a user