summaryrefslogtreecommitdiff
path: root/internal/client/ui/viminput/viminput.go
diff options
context:
space:
mode:
authorKyren223 <Kyren223@proton.me>2024-12-04 18:35:11 +0200
committerKyren223 <Kyren223@proton.me>2024-12-04 18:35:11 +0200
commit37cd043920aa92189d9ae19e7631968290e4d352 (patch)
tree62282034ca56a52bbe36634d77932beaefa5d0ef /internal/client/ui/viminput/viminput.go
parent567d569dd649cc0b82d6f8890e2bd77b052ebed6 (diff)
Started work on basic vim input box
Diffstat (limited to 'internal/client/ui/viminput/viminput.go')
-rw-r--r--internal/client/ui/viminput/viminput.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/internal/client/ui/viminput/viminput.go b/internal/client/ui/viminput/viminput.go
new file mode 100644
index 0000000..e2b65a8
--- /dev/null
+++ b/internal/client/ui/viminput/viminput.go
@@ -0,0 +1,89 @@
+package viminput
+
+import (
+ tea "github.com/charmbracelet/bubbletea"
+ "github.com/charmbracelet/lipgloss"
+)
+
+type (
+ Keymap struct{}
+ LineDecoration = func(lnum int, line string, cursorLnum int) string
+)
+
+type Line []byte
+
+type Model struct {
+ keymap Keymap
+
+ PlaceholderStyle lipgloss.Style
+ PromptStyle lipgloss.Style
+
+ Placeholder string
+ LineDecoration LineDecoration
+
+ lines []Line
+
+ width int
+ height int
+ focus bool
+}
+
+func New(width, height int) Model {
+ return Model{
+ keymap: Keymap{},
+ PlaceholderStyle: lipgloss.NewStyle(),
+ PromptStyle: lipgloss.NewStyle(),
+ Placeholder: "",
+ LineDecoration: EmptyLineDecoration,
+ width: width,
+ height: height,
+ focus: false,
+ }
+}
+
+func (m Model) Init() tea.Cmd {
+ return nil
+}
+
+func (m Model) View() string {
+ placeholder := m.PlaceholderStyle.Render(m.Placeholder)
+ lineDecoration := m.LineDecoration(1, "", 1)
+
+ result := lipgloss.JoinHorizontal(lipgloss.Top, lineDecoration, placeholder)
+
+ result = lipgloss.NewStyle().Width(m.width).Height(m.height).Render(result)
+
+ return result
+}
+
+func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
+ if !m.focus {
+ return m, nil
+ }
+
+ return m, nil
+}
+
+func (m *Model) SetWidth(width int) {
+ m.width = width
+}
+
+func (m Model) Width() int {
+ return m.width
+}
+
+func (m *Model) SetHeight(height int) {
+ m.height = height
+}
+
+func (m Model) Height() int {
+ return m.height
+}
+
+func (m *Model) Focus() {
+ m.focus = true
+}
+
+func (m *Model) Blur() {
+ m.focus = false
+}