This commit is contained in:
2026-03-28 17:41:54 +01:00
parent 587c8f9396
commit 1171fe28e7
4 changed files with 142 additions and 9 deletions

View File

@@ -20,11 +20,13 @@ type Model struct {
listenBridge chan string
listenBridgeExecutionsStopped chan bridge.ExecutionPoint
currLocals map[string]any
currExecutionPoint bridge.ExecutionPoint
messages []string
stdoutOutput viewport.Model
codeViewer viewport.Model
localsViewer viewport.Model
cursor int
breakpoints map[string][]int
@@ -36,6 +38,7 @@ func NewModel(b *bridge.Bridge, file string, text string) Model {
stdoutOutput := viewport.New(0, 0)
codeViewer := viewport.New(0, 0)
localsViewer := viewport.New(0, 0)
return Model{
currentFile: file,
@@ -46,6 +49,7 @@ func NewModel(b *bridge.Bridge, file string, text string) Model {
listenBridge: c,
listenBridgeExecutionsStopped: c2,
currLocals: make(map[string]any),
currExecutionPoint: bridge.ExecutionPoint{
File: file,
Line: 0,
@@ -56,6 +60,7 @@ func NewModel(b *bridge.Bridge, file string, text string) Model {
cursor: 0,
codeViewer: codeViewer,
stdoutOutput: stdoutOutput,
localsViewer: localsViewer,
}
}
@@ -73,6 +78,7 @@ func ListenBridgeExecutionsStopped(ch <-chan bridge.ExecutionPoint) tea.Cmd {
}
}
type LocalsMsg map[string]any
type ExecutionStoppedMsg bridge.ExecutionPoint
type StdoutMsg string

View File

@@ -21,12 +21,27 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
return m, ListenBridge(m.listenBridge)
case ExecutionStoppedMsg:
m.currExecutionPoint = bridge.ExecutionPoint(msg)
return m, ListenBridgeExecutionsStopped(m.listenBridgeExecutionsStopped)
return m, tea.Batch(ListenBridgeExecutionsStopped(m.listenBridgeExecutionsStopped), m.GetLocals())
case LocalsMsg:
m.currLocals = map[string]any(msg)
m.localsViewer.SetContent(strings.Join(flattenDict(m.currLocals, 0), "\n"))
}
return m, nil
}
func (m Model) GetLocals() tea.Cmd {
return func() tea.Msg {
vars, err := m.bridge.Locals()
if err != nil {
slog.Error("couldnt get vars", "error", err)
return nil
}
return LocalsMsg(vars)
}
}
func (m Model) UpdateWindowSize(msg tea.WindowSizeMsg) (tea.Model, tea.Cmd) {
m.width = msg.Width
m.height = msg.Height
@@ -37,9 +52,12 @@ func (m Model) UpdateWindowSize(msg tea.WindowSizeMsg) (tea.Model, tea.Cmd) {
m.codeViewer.Width = msg.Width
m.codeViewer.Height = editorHeight
m.stdoutOutput.Width = msg.Width
m.stdoutOutput.Width = msg.Width / 2
m.stdoutOutput.Height = outputHeight
m.localsViewer.Width = msg.Width / 2
m.localsViewer.Height = outputHeight
m.stdoutOutput.SetContent(strings.Join(m.messages, ""))
return m, nil
@@ -53,7 +71,7 @@ func (m Model) HandleKeyMsg(key tea.KeyMsg) (tea.Model, tea.Cmd) {
m.codeViewer.ScrollUp(1)
m.cursor = max(0, m.cursor-1)
case "j":
m.codeViewer.ScrollUp(1)
m.codeViewer.ScrollDown(1)
m.cursor = min(m.textLines-1, m.cursor+1)
case "b":
lineNumber := m.cursor + 1

View File

@@ -14,6 +14,21 @@ import (
var panelStyle = lipgloss.NewStyle().Border(lipgloss.NormalBorder()).Padding(0, 1)
func flattenDict(m map[string]interface{}, indent int) []string {
lines := []string{}
prefix := strings.Repeat(" ", indent)
for k, v := range m {
switch val := v.(type) {
case map[string]interface{}:
lines = append(lines, fmt.Sprintf("%s%s:", prefix, k))
lines = append(lines, flattenDict(val, indent+1)...)
default:
lines = append(lines, fmt.Sprintf("%s%s: %v", prefix, k, val))
}
}
return lines
}
func (m Model) View() string {
var buf bytes.Buffer
lexer := lexers.Get("python")
@@ -54,9 +69,15 @@ func (m Model) View() string {
Width(m.codeViewer.Width - wFrame).
Render(m.codeViewer.View())
bottomPanel := panelStyle.Height(m.stdoutOutput.Height - hFrame).
bottomLeftPanel := panelStyle.Height(m.stdoutOutput.Height - hFrame).
Width(m.stdoutOutput.Width - wFrame).
Render(m.stdoutOutput.View())
bottomRightPanel := panelStyle.Height(m.stdoutOutput.Height - hFrame).
Width(m.stdoutOutput.Width - wFrame).
Render(m.localsViewer.View())
bottomPanel := lipgloss.JoinHorizontal(lipgloss.Top, bottomLeftPanel, bottomRightPanel)
return lipgloss.JoinVertical(lipgloss.Top, topPanel, bottomPanel)
}