From a5733bdaed54e5976a449475668e4610d2253278 Mon Sep 17 00:00:00 2001 From: Robin Olsen Date: Tue, 17 Feb 2026 13:19:35 +0100 Subject: [PATCH] add feedback to tui --- pkg/tui/tui.go | 24 ++++++++++++-- pkg/tui/views/dashboard/model.go | 54 ++++++++++++++++++++----------- pkg/tui/views/dashboard/update.go | 13 +++++++- pkg/tui/views/dashboard/view.go | 19 ++++++++--- pkg/tui/views/views.go | 5 +-- 5 files changed, 87 insertions(+), 28 deletions(-) diff --git a/pkg/tui/tui.go b/pkg/tui/tui.go index f9a704d..2c8f501 100644 --- a/pkg/tui/tui.go +++ b/pkg/tui/tui.go @@ -4,13 +4,17 @@ import ( "context" "github.com/LazyBachelor/LazyPM/internal/service" + "github.com/LazyBachelor/LazyPM/pkg/task" "github.com/LazyBachelor/LazyPM/pkg/tui/views" tea "github.com/charmbracelet/bubbletea" ) type TUIConfig = service.Config -type Tui struct{} +type Tui struct { + feedbackChan chan task.ValidationFeedback + quitChan chan bool +} func NewTui() *Tui { return &Tui{} @@ -24,10 +28,24 @@ func (t *Tui) Run(ctx context.Context, config TUIConfig) error { defer cleanup() - if _, err := tea.NewProgram(views.NewDashboardView(svc), - tea.WithAltScreen(), tea.WithMouseAllMotion()).Run(); err != nil { + p := tea.NewProgram(views.NewDashboardView(svc, t.feedbackChan, t.quitChan), + tea.WithAltScreen(), tea.WithMouseAllMotion()) + + if t.quitChan != nil { + go func() { + <-t.quitChan + p.Quit() + }() + } + + if _, err := p.Run(); err != nil { return err } return nil } + +func (t *Tui) SetChannels(feedbackChan chan task.ValidationFeedback, quitChan chan bool) { + t.feedbackChan = feedbackChan + t.quitChan = quitChan +} diff --git a/pkg/tui/views/dashboard/model.go b/pkg/tui/views/dashboard/model.go index 702cb8f..7fbe776 100644 --- a/pkg/tui/views/dashboard/model.go +++ b/pkg/tui/views/dashboard/model.go @@ -2,29 +2,40 @@ package dashboard import ( "github.com/LazyBachelor/LazyPM/internal/service" + "github.com/LazyBachelor/LazyPM/pkg/task" tea "github.com/charmbracelet/bubbletea" ) -type Model struct { - header Header - issueList IssueList - issueDetail IssueDetail - helpBar HelpBar - keyMap DashboardKeyMap - svc *service.Services - width int - height int - focusedPane int // 0 = list, 1 = detail +type ValidationFeedbackMsg struct { + Feedback task.ValidationFeedback } -func NewDashboard(svc *service.Services) *Model { +type Model struct { + header Header + issueList IssueList + issueDetail IssueDetail + helpBar HelpBar + keyMap DashboardKeyMap + svc *service.Services + width int + height int + focusedPane int // 0 = list, 1 = detail + feedbackChan chan task.ValidationFeedback + quitChan chan bool + currentFeedback task.ValidationFeedback + showComplete bool +} + +func NewDashboard(svc *service.Services, feedbackChan chan task.ValidationFeedback, quitChan chan bool) *Model { m := &Model{ - header: NewHeader("Project Manager Dashboard"), - keyMap: defaultDashboardKeyMap, - svc: svc, - width: 80, - height: 24, - focusedPane: 0, + header: NewHeader("Project Manager Dashboard"), + keyMap: defaultDashboardKeyMap, + svc: svc, + width: 80, + height: 24, + focusedPane: 0, + feedbackChan: feedbackChan, + quitChan: quitChan, } m.issueList = NewIssueList(svc, 0, 0) @@ -39,7 +50,14 @@ func NewDashboard(svc *service.Services) *Model { } func (m *Model) Init() tea.Cmd { - return nil + return m.listenForValidation() +} + +func (m *Model) listenForValidation() tea.Cmd { + return func() tea.Msg { + feedback := <-m.feedbackChan + return ValidationFeedbackMsg{Feedback: feedback} + } } func (m *Model) IsFocusedOnList() bool { diff --git a/pkg/tui/views/dashboard/update.go b/pkg/tui/views/dashboard/update.go index 7fe15cc..47aaf13 100644 --- a/pkg/tui/views/dashboard/update.go +++ b/pkg/tui/views/dashboard/update.go @@ -1,8 +1,8 @@ package dashboard import ( - tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/bubbles/list" + tea "github.com/charmbracelet/bubbletea" ) func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { @@ -22,6 +22,17 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) { m.width = msg.Width m.height = msg.Height return m, nil + + case ValidationFeedbackMsg: + m.currentFeedback = msg.Feedback + if msg.Feedback.Success { + m.showComplete = true + if m.quitChan != nil { + close(m.quitChan) + } + return m, tea.Quit + } + return m, m.listenForValidation() } cmd, changed := m.issueList.Update(msg) diff --git a/pkg/tui/views/dashboard/view.go b/pkg/tui/views/dashboard/view.go index 18d207e..3c61759 100644 --- a/pkg/tui/views/dashboard/view.go +++ b/pkg/tui/views/dashboard/view.go @@ -15,10 +15,10 @@ func (m *Model) View() string { header := m.header.View(m.width) headerHeight := m.header.Height() - bottomView := m.helpBar.View() - bottomHeight := m.helpBar.Height() + footer := m.footer() + footerHeight := lipgloss.Height(footer) - contentHeight := m.height - headerHeight - bottomHeight + contentHeight := m.height - headerHeight - footerHeight totalContentWidth := m.width - 1 listWidth := totalContentWidth * styles.ListViewRatio / 100 @@ -32,5 +32,16 @@ func (m *Model) View() string { content := lipgloss.JoinHorizontal(lipgloss.Left, listView, detailView) - return lipgloss.JoinVertical(lipgloss.Left, header, content, bottomView) + return lipgloss.JoinVertical(lipgloss.Left, header, content, footer) +} + +func (m *Model) footer() string { + feedbackStatus := m.currentFeedback.Message + + if feedbackStatus == "" { + return m.helpBar.View() + } + + m.helpBar.SetWidth(m.width - lipgloss.Width(feedbackStatus)) + return lipgloss.JoinHorizontal(lipgloss.Left, m.helpBar.View(), feedbackStatus) } diff --git a/pkg/tui/views/views.go b/pkg/tui/views/views.go index c7bc138..04bbea6 100644 --- a/pkg/tui/views/views.go +++ b/pkg/tui/views/views.go @@ -2,9 +2,10 @@ package views import ( "github.com/LazyBachelor/LazyPM/internal/service" + "github.com/LazyBachelor/LazyPM/pkg/task" "github.com/LazyBachelor/LazyPM/pkg/tui/views/dashboard" ) -func NewDashboardView(svc *service.Services) *dashboard.Model { - return dashboard.NewDashboard(svc) +func NewDashboardView(svc *service.Services, feedbackChan chan task.ValidationFeedback, quitChan chan bool) *dashboard.Model { + return dashboard.NewDashboard(svc, feedbackChan, quitChan) }