Bläddra i källkod

Adds new widget struct for issue creation tui

arianagiroux 3 veckor sedan
förälder
incheckning
f9b48760ee
3 ändrade filer med 50 tillägg och 1 borttagningar
  1. 1 0
      go.mod
  2. 2 0
      go.sum
  3. 47 1
      tui.go

+ 1 - 0
go.mod

@@ -10,6 +10,7 @@ require (
 )
 )
 
 
 require (
 require (
+	github.com/atotto/clipboard v0.1.4 // indirect
 	github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
 	github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
 	github.com/charmbracelet/colorprofile v0.4.1 // indirect
 	github.com/charmbracelet/colorprofile v0.4.1 // indirect
 	github.com/charmbracelet/x/ansi v0.11.6 // indirect
 	github.com/charmbracelet/x/ansi v0.11.6 // indirect

+ 2 - 0
go.sum

@@ -1,3 +1,5 @@
+github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
+github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
 github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
 github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
 github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
 github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
 github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5fXonfvc=
 github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5fXonfvc=

+ 47 - 1
tui.go

@@ -11,6 +11,7 @@ import (
 	"fmt"
 	"fmt"
 	"strings"
 	"strings"
 
 
+	"github.com/charmbracelet/bubbles/textinput"
 	tea "github.com/charmbracelet/bubbletea"
 	tea "github.com/charmbracelet/bubbletea"
 	"github.com/charmbracelet/lipgloss"
 	"github.com/charmbracelet/lipgloss"
 )
 )
@@ -130,6 +131,51 @@ func (m Model) View() string {
 	return output
 	return output
 }
 }
 
 
+type issueCreate struct {
+	focusedField int
+	inputs       []textinput.Model
+	issue        Issue
+}
+
+func (c issueCreate) init(i Issue) issueCreate {
+	c.issue = i
+	title := textinput.Model{Placeholder: "title", CharLimit: 64, Width: 45}
+	status := textinput.Model{Placeholder: "status", CharLimit: 64, Width: 45}
+	tags := textinput.Model{Placeholder: "tags", CharLimit: 64, Width: 45}
+	blockers := textinput.Model{Placeholder: "blockers", CharLimit: 64, Width: 45}
+	c.inputs = append(c.inputs, title, status, tags, blockers)
+	return c
+}
+
+func (c issueCreate) update(msg tea.Msg) (issueCreate, tea.Cmd) {
+	switch T := msg.(type) {
+	case issueCreate:
+		c.issue = T.issue
+		c.focusedField = T.focusedField
+		c.inputs = T.inputs
+
+		return c, nil
+	case tea.KeyMsg:
+		switch T.String() {
+		case "tab":
+			if c.focusedField < len(c.inputs)-1 {
+				c.focusedField++
+			} else {
+				c.focusedField = 0
+			}
+			return c, nil
+		default:
+			inputModel, inputCmd := c.inputs[c.focusedField].Update(msg)
+			c.inputs[c.focusedField] = inputModel
+			return c, inputCmd
+		}
+	}
+
+	return c, nil
+}
+
+func (c issueCreate) view() tea.Msg { return "testing" }
+
 // Handles load logic
 // Handles load logic
 func (m Model) load() tea.Msg {
 func (m Model) load() tea.Msg {
 	if IsIssue(m.Path) {
 	if IsIssue(m.Path) {
@@ -152,7 +198,7 @@ func (m Model) load() tea.Msg {
 		return collection
 		return collection
 	}
 	}
 
 
-	return nil
+	return issueCreate{issue: Issue{Path: m.Path}}
 }
 }
 
 
 // Handles all view logic for Issue structs
 // Handles all view logic for Issue structs