|
|
@@ -15,6 +15,40 @@ import (
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
|
)
|
|
|
|
|
|
+// [lipgloss] style definitions, stores the currently displayed "widget"
|
|
|
+var (
|
|
|
+ titleStyle = lipgloss.NewStyle().
|
|
|
+ Bold(true).
|
|
|
+ Underline(true)
|
|
|
+
|
|
|
+ statusStyle = lipgloss.NewStyle().
|
|
|
+ Faint(true).
|
|
|
+ Italic(true)
|
|
|
+
|
|
|
+ variadicTitleStyle = lipgloss.NewStyle().
|
|
|
+ Align(lipgloss.Left).
|
|
|
+ Italic(true)
|
|
|
+
|
|
|
+ variadicDataStyle = lipgloss.NewStyle().
|
|
|
+ Width(40).
|
|
|
+ BorderStyle(lipgloss.ASCIIBorder())
|
|
|
+
|
|
|
+ borderStyle = lipgloss.NewStyle().
|
|
|
+ Padding(1, 2).
|
|
|
+ Margin(1).
|
|
|
+ BorderStyle(lipgloss.NormalBorder())
|
|
|
+
|
|
|
+ indexStyle = lipgloss.NewStyle().
|
|
|
+ Italic(true)
|
|
|
+
|
|
|
+ pointerStyle = lipgloss.NewStyle().
|
|
|
+ Faint(true)
|
|
|
+
|
|
|
+ collectionStyleLeft = lipgloss.NewStyle().
|
|
|
+ Align(lipgloss.Left)
|
|
|
+)
|
|
|
+
|
|
|
+// interface for renderable structs
|
|
|
type widget interface {
|
|
|
view() tea.Msg
|
|
|
}
|
|
|
@@ -27,6 +61,7 @@ type Model struct {
|
|
|
// viewport viewport.Model
|
|
|
}
|
|
|
|
|
|
+// The bubbletea init function
|
|
|
func (m Model) Init() tea.Cmd { return m.load }
|
|
|
|
|
|
// Handles quit logic and viewport scroll and size updates
|
|
|
@@ -36,7 +71,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
switch msg.String() {
|
|
|
case "q":
|
|
|
return m, tea.Quit
|
|
|
- case "k":
|
|
|
+ case "j":
|
|
|
if collection, ok := m.widget.(IssueCollection); ok {
|
|
|
if collection.selection+1 < len(collection.Collection) {
|
|
|
collection.selection = collection.selection + 1
|
|
|
@@ -47,7 +82,7 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
return m, collection.view
|
|
|
}
|
|
|
return m, nil
|
|
|
- case "j":
|
|
|
+ case "k":
|
|
|
// do something only if widget is collection
|
|
|
if collection, ok := m.widget.(IssueCollection); ok {
|
|
|
if collection.selection != 0 {
|
|
|
@@ -80,6 +115,18 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|
|
return m, nil
|
|
|
}
|
|
|
|
|
|
+// Handles top level view functionality
|
|
|
+func (m Model) View() string {
|
|
|
+ var output string
|
|
|
+ if len(m.content) == 0 {
|
|
|
+ return "loading..."
|
|
|
+ } else {
|
|
|
+ output = output + m.content
|
|
|
+ }
|
|
|
+ output = output + "\nj/k: down/up\tenter: select\tq: quit"
|
|
|
+ return output
|
|
|
+}
|
|
|
+
|
|
|
// Handles load logic
|
|
|
func (m Model) load() tea.Msg {
|
|
|
if IsIssue(m.Path) {
|
|
|
@@ -105,39 +152,6 @@ func (m Model) load() tea.Msg {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-// [lipgloss] style definitions
|
|
|
-var (
|
|
|
- titleStyle = lipgloss.NewStyle().
|
|
|
- Bold(true).
|
|
|
- Underline(true)
|
|
|
-
|
|
|
- statusStyle = lipgloss.NewStyle().
|
|
|
- Faint(true).
|
|
|
- Italic(true)
|
|
|
-
|
|
|
- variadicTitleStyle = lipgloss.NewStyle().
|
|
|
- Align(lipgloss.Left).
|
|
|
- Italic(true)
|
|
|
-
|
|
|
- variadicDataStyle = lipgloss.NewStyle().
|
|
|
- Width(40).
|
|
|
- BorderStyle(lipgloss.ASCIIBorder())
|
|
|
-
|
|
|
- borderStyle = lipgloss.NewStyle().
|
|
|
- Padding(1, 2).
|
|
|
- Margin(1).
|
|
|
- BorderStyle(lipgloss.NormalBorder())
|
|
|
-
|
|
|
- indexStyle = lipgloss.NewStyle().
|
|
|
- Italic(true)
|
|
|
-
|
|
|
- pointerStyle = lipgloss.NewStyle().
|
|
|
- Faint(true)
|
|
|
-
|
|
|
- collectionStyleLeft = lipgloss.NewStyle().
|
|
|
- Align(lipgloss.Left)
|
|
|
-)
|
|
|
-
|
|
|
// Handles all view logic for Issue structs
|
|
|
func (i Issue) view() tea.Msg {
|
|
|
var output string
|
|
|
@@ -197,14 +211,5 @@ func (ic IssueCollection) view() tea.Msg {
|
|
|
}
|
|
|
|
|
|
output = output + collectionStyleLeft.Render(left)
|
|
|
- output = output + "\nj/k: down/up\tenter: select\tq: quit"
|
|
|
return output
|
|
|
}
|
|
|
-
|
|
|
-// Wraps [issue.Model.renderIssue] in a viewport
|
|
|
-func (m Model) View() string {
|
|
|
- if len(m.content) == 0 {
|
|
|
- return "loading..."
|
|
|
- }
|
|
|
- return m.content
|
|
|
-}
|