Initial, working but only with viewport height adjusted a little bit

This commit is contained in:
2026-03-28 16:12:33 +01:00
commit 7d94dee26b
16 changed files with 857 additions and 0 deletions

56
ui/view.go Normal file
View File

@@ -0,0 +1,56 @@
package ui
import (
"bytes"
"fmt"
"slices"
"strings"
"github.com/alecthomas/chroma/v2/formatters"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/charmbracelet/lipgloss"
)
var panelStyle = lipgloss.NewStyle().Border(lipgloss.NormalBorder())
func (m Model) View() string {
var buf bytes.Buffer
lexer := lexers.Get("python")
style := styles.Get("monokai")
formatter := formatters.Get("terminal16m")
iterator, _ := lexer.Tokenise(nil, m.text)
formatter.Format(&buf, style, iterator)
var out strings.Builder
lines := strings.Split(buf.String(), "\n")
breakpoints := m.breakpoints[m.currentFile]
for i, line := range lines {
breakpoint := " "
cursor := " "
if slices.Contains(breakpoints, i+1) {
breakpoint = "O"
}
if i == m.cursor {
cursor = ">"
}
fmt.Fprintf(&out, "%-4d%s%s %s\n", i+1, breakpoint, cursor, line)
}
frameW, frameH := panelStyle.GetFrameSize()
topHeight := m.height * 70 / 100
code := panelStyle.Width(m.width - frameW).Height(topHeight - frameH).Render(out.String())
m.viewport.Height = m.height - (topHeight + frameH)
m.viewport.Width = m.width - frameW
m.viewport.SetContent(strings.Join(m.messages, ""))
m.viewport.GotoBottom()
output := panelStyle.Width(m.viewport.Width).Height(m.viewport.Height).Render(m.viewport.View())
return lipgloss.JoinVertical(lipgloss.Top, code, output)
}