diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-12-05 14:11:28 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-12-05 14:11:28 +0200 |
| commit | 8087907b4b942c7d8c9296c3fd0e1f08d5d88694 (patch) | |
| tree | c0a58a78503443b11df7027b415b6406d3b8178b /internal/client/ui/viminput/viminput.go | |
| parent | 37cd043920aa92189d9ae19e7631968290e4d352 (diff) | |
Refactored how the core UI looks
Diffstat (limited to 'internal/client/ui/viminput/viminput.go')
| -rw-r--r-- | internal/client/ui/viminput/viminput.go | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go index e2b65a8..94c5413 100644 --- a/internal/client/ui/viminput/viminput.go +++ b/internal/client/ui/viminput/viminput.go @@ -1,13 +1,15 @@ package viminput import ( + "strings" + tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" ) type ( Keymap struct{} - LineDecoration = func(lnum int, line string, cursorLnum int) string + LineDecoration = func(lnum int, m Model) string ) type Line []byte @@ -21,7 +23,9 @@ type Model struct { Placeholder string LineDecoration LineDecoration - lines []Line + lines []Line + CursorLine int + CursorColumn int width int height int @@ -46,11 +50,23 @@ func (m Model) Init() tea.Cmd { } func (m Model) View() string { - placeholder := m.PlaceholderStyle.Render(m.Placeholder) - lineDecoration := m.LineDecoration(1, "", 1) + var lines []Line + if len(m.lines) == 0 { + placeholder := m.PlaceholderStyle.Render(m.Placeholder) + lines = append(lines, Line(placeholder)) + } else { + lines = m.lines + } - result := lipgloss.JoinHorizontal(lipgloss.Top, lineDecoration, placeholder) + var builder strings.Builder + for i, line := range lines { + lineDecoration := m.LineDecoration(i, m) + builder.WriteString(lineDecoration) + builder.Write(line) + builder.WriteByte('\n') + } + result := builder.String() result = lipgloss.NewStyle().Width(m.width).Height(m.height).Render(result) return result @@ -87,3 +103,15 @@ func (m *Model) Focus() { func (m *Model) Blur() { m.focus = false } + +func (m *Model) SetLines(lines ...Line) { + m.lines = lines +} + +func (m *Model) SetLine(lnum int, line Line) { + m.lines[lnum] = line +} + +func (m *Model) Line(lnum int) Line { + return m.lines[lnum] +} |
