Bläddra i källkod

Added a func to render keyhelp to widget interface

arianagiroux 2 veckor sedan
förälder
incheckning
174a22f6c3
3 ändrade filer med 25 tillägg och 8 borttagningar
  1. 0 1
      Readme.md
  2. 22 6
      tui.go
  3. 3 1
      tui_test.go

+ 0 - 1
Readme.md

@@ -20,7 +20,6 @@ go install cmd/issues.go
 - `tui.go:// TODO enable collection recursing (i.e, embeded collections)`
 - `tui.go:// TODO enable scroll/viewport logic`
 - `tui.go:	case IssueCollection: // TODO handle updates to IssueCollection widgets in its own update func`
-- `tui.go:// TODO add keyhelp func to widget interface`
 - `tui.go:// TODO invoke editor for descriptions`
 - `tui.go:// TODO handle reset on esc`
 - `tui.go:// TODO implement description field in createIssue.create cmd`

+ 22 - 6
tui.go

@@ -142,21 +142,19 @@ 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"
+	output = output + m.content
+	output = output + lipgloss.NewStyle().Faint(true).Margin(1).Render(m.widget.keyhelp())
 	return output
 }
 
 // WIDGET DEFINITIONS ---------------------------------------------------------
 // ----------------------------------------------------------------------------
 
-// TODO add keyhelp func to widget interface
-
 // interface definition for widgets
 type widget interface {
-	render() tea.Msg
+	render() tea.Msg // renders content
+	keyhelp() string // renders key usage
 }
 
 // -------- creatIssue definitions --------------------------------------------
@@ -340,6 +338,12 @@ func (c create) render() tea.Msg {
 	return output
 }
 
+func (c create) keyhelp() string {
+	var output string
+	output = output + "\ntab/shift+tab: down/up\t\tenter: input value\t\tctrl+c: quit"
+	return output
+}
+
 // -------- Issue widget definitions ------------------------------------------
 // ----------------------------------------------------------------------------
 
@@ -382,6 +386,12 @@ func (i Issue) render() tea.Msg {
 	return borderStyle.Render(output)
 }
 
+func (i Issue) keyhelp() string {
+	var output string
+	output = output + "\nj/k: down/up\t\tq: quit"
+	return output
+}
+
 // -------- IssueCollection widget definitions --------------------------------
 // ----------------------------------------------------------------------------
 
@@ -408,6 +418,12 @@ func (ic IssueCollection) render() tea.Msg {
 	return output
 }
 
+func (ic IssueCollection) keyhelp() string {
+	var output string
+	output = output + "\nj/k: down/up\t\tenter: select\t\tq: quit"
+	return output
+}
+
 // tea.Cmd definitions --------------------------------------------------------
 // ----------------------------------------------------------------------------
 

+ 3 - 1
tui_test.go

@@ -6,6 +6,7 @@ import (
 	"testing"
 
 	tea "github.com/charmbracelet/bubbletea"
+	"github.com/charmbracelet/lipgloss"
 	"github.com/stretchr/testify/assert"
 )
 
@@ -191,7 +192,8 @@ func Test_Model_View(t *testing.T) {
 		assert.Fail(t, "should not return cmd")
 	}
 
-	testView := testIssue.render().(string) + "\nj/k: down/up\tenter: select\tq: quit"
+	testView := testIssue.render().(string)
+	testView = testView + lipgloss.NewStyle().Faint(true).Margin(1).Render(testIssue.keyhelp())
 	assert.Equal(t, testView, model.(Model).View())
 
 	render2 := Model{}.View()