working codeviewer

This commit is contained in:
2026-03-28 19:24:17 +01:00
parent d254d5cfd0
commit 387804dbd0
4 changed files with 143 additions and 67 deletions

View File

@@ -1,14 +1,9 @@
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"
)
@@ -30,39 +25,6 @@ func flattenDict(m map[string]interface{}, indent int) []string {
}
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 := " "
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 %s\n", i+1, breakpoint, executor, cursor, line)
}
m.codeViewer.SetContent(out.String())
hFrame, wFrame := panelStyle.GetFrameSize()
topPanel := panelStyle.
Height(m.codeViewer.Height - hFrame).