Browse Source

Added additional stylistic comments to tui for clarity

arianagiroux 2 tuần trước cách đây
mục cha
commit
8d43a64b5e
1 tập tin đã thay đổi với 40 bổ sung33 xóa
  1. 40 33
      tui.go

+ 40 - 33
tui.go

@@ -52,10 +52,8 @@ var (
 				Align(lipgloss.Left)
 )
 
-// interface for renderable structs
-type widget interface {
-	render() tea.Msg
-}
+// MAIN MODEL DEFINITIONS -----------------------------------------------------
+// ----------------------------------------------------------------------------
 
 // The main bubbletea Model
 type Model struct {
@@ -65,9 +63,6 @@ type Model struct {
 	// viewport viewport.Model
 }
 
-// Main model definitions -----------------------------------------------------
-// ----------------------------------------------------------------------------
-
 // The bubbletea init function
 func (m Model) Init() tea.Cmd { return m.load }
 
@@ -155,6 +150,12 @@ func (m Model) View() string {
 
 // WIDGET DEFINITIONS ---------------------------------------------------------
 // ----------------------------------------------------------------------------
+
+// interface definition for widgets
+type widget interface {
+	render() tea.Msg
+}
+
 // -------- creatIssue definitions --------------------------------------------
 // ----------------------------------------------------------------------------
 
@@ -307,34 +308,9 @@ func (ci createIssue) render() tea.Msg {
 	return output
 }
 
-// tea.Cmd definitions --------------------------------------------------------
+// -------- Issue widget definitions ------------------------------------------
 // ----------------------------------------------------------------------------
 
-// Handles load logic
-func (m Model) load() tea.Msg {
-	if IsIssue(m.Path) {
-		issue, err := Issue{}.NewFromPath(m.Path)
-
-		if err != nil {
-			return nil
-		}
-
-		return issue
-	}
-
-	if IsIssueCollection(m.Path) {
-		collection, err := IssueCollection{}.NewFromPath(m.Path)
-
-		if err != nil {
-			return nil
-		}
-
-		return collection
-	}
-
-	return initialInputModel(m.Path, "lorem ipsum")
-}
-
 // Handles all render logic for Issue structs
 func (i Issue) render() tea.Msg {
 	var output string
@@ -374,6 +350,9 @@ func (i Issue) render() tea.Msg {
 	return borderStyle.Render(output)
 }
 
+// -------- IssueCollection widget definitions --------------------------------
+// ----------------------------------------------------------------------------
+
 // Handles all render logic for IssueCollection structs.
 func (ic IssueCollection) render() tea.Msg {
 	var output string
@@ -396,3 +375,31 @@ func (ic IssueCollection) render() tea.Msg {
 	output = output + collectionStyleLeft.Render(left)
 	return output
 }
+
+// tea.Cmd definitions --------------------------------------------------------
+// ----------------------------------------------------------------------------
+
+// Handles load logic
+func (m Model) load() tea.Msg {
+	if IsIssue(m.Path) {
+		issue, err := Issue{}.NewFromPath(m.Path)
+
+		if err != nil {
+			return nil
+		}
+
+		return issue
+	}
+
+	if IsIssueCollection(m.Path) {
+		collection, err := IssueCollection{}.NewFromPath(m.Path)
+
+		if err != nil {
+			return nil
+		}
+
+		return collection
+	}
+
+	return initialInputModel(m.Path, "lorem ipsum")
+}