Looking better and working now

This commit is contained in:
2026-03-28 16:43:09 +01:00
parent 7d94dee26b
commit 41d0dd3b14
3 changed files with 66 additions and 39 deletions

View File

@@ -1,6 +1,8 @@
package ui
import (
"strings"
tea "github.com/charmbracelet/bubbletea"
)
@@ -9,31 +11,54 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case tea.KeyMsg:
return m.HandleKeyMsg(msg)
case tea.WindowSizeMsg:
m.width = msg.Width
m.height = msg.Height
return m.UpdateWindowSize(msg)
case StdoutMsg:
m.messages = append(m.messages, string(msg))
m.stdoutOutput.SetContent(strings.Join(m.messages, ""))
m.stdoutOutput.GotoBottom()
return m, ListenBridge(m.listenBridge)
}
return m, nil
}
func (m Model) UpdateWindowSize(msg tea.WindowSizeMsg) (tea.Model, tea.Cmd) {
m.width = msg.Width
m.height = msg.Height
editorHeight := msg.Height * 70 / 100
outputHeight := msg.Height - editorHeight - 4
m.codeViewer.Width = msg.Width
m.codeViewer.Height = editorHeight
m.stdoutOutput.Width = msg.Width
m.stdoutOutput.Height = outputHeight
m.stdoutOutput.SetContent(strings.Join(m.messages, ""))
return m, nil
}
func (m Model) HandleKeyMsg(key tea.KeyMsg) (tea.Model, tea.Cmd) {
switch key.String() {
case "q", "ctrl+c":
return m, tea.Quit
case "k":
m.cursor = clamp(0, m.height, m.cursor-1)
m.codeViewer.ScrollUp(1)
m.cursor = max(0, m.cursor-1)
case "j":
m.cursor = clamp(0, min(m.height, m.lineCount-1), m.cursor+1)
m.codeViewer.ScrollUp(1)
m.cursor = min(m.textLines-1, m.cursor+1)
case "b":
m.bridge.Breakpoint(m.currentFile, m.cursor)
lineNumber := m.cursor + 1
m.bridge.Breakpoint(m.currentFile, lineNumber)
if file, ok := m.breakpoints[m.currentFile]; ok {
m.breakpoints[m.currentFile] = append(file, m.cursor+1)
m.breakpoints[m.currentFile] = append(file, lineNumber)
} else {
m.breakpoints[m.currentFile] = []int{
m.cursor + 1,
lineNumber,
}
}
case "c":
@@ -42,9 +67,3 @@ func (m Model) HandleKeyMsg(key tea.KeyMsg) (tea.Model, tea.Cmd) {
return m, nil
}
func clamp(minimum, maximum, val int) int {
val = max(minimum, val)
val = min(maximum, val)
return val
}