add exit mechanicm to each stage
remove types and moved struct to appropriate files
This commit is contained in:
@@ -11,8 +11,14 @@ func (t *Task) IntroduceTask() error {
|
||||
if t.aboutScreen == nil {
|
||||
return fmt.Errorf("aboutScreen is not set")
|
||||
}
|
||||
_, err := tea.NewProgram(t.aboutScreen, tea.WithAltScreen()).Run()
|
||||
return err
|
||||
model, err := tea.NewProgram(t.aboutScreen, tea.WithAltScreen()).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if m, ok := model.(interface{ GetUserQuit() bool }); ok && m.GetUserQuit() {
|
||||
return ErrUserQuit
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *Task) StartInterface(ctx context.Context, cfg TaskConfig) error {
|
||||
@@ -27,6 +33,12 @@ func (t *Task) StartQuestionnaire() error {
|
||||
if t.questionnaire == nil {
|
||||
return fmt.Errorf("questionnaire is not set")
|
||||
}
|
||||
_, err := tea.NewProgram(t.questionnaire, tea.WithAltScreen()).Run()
|
||||
return err
|
||||
model, err := tea.NewProgram(t.questionnaire, tea.WithAltScreen()).Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if m, ok := model.(interface{ GetUserQuit() bool }); ok && m.GetUserQuit() {
|
||||
return ErrUserQuit
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,10 +2,13 @@ package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
)
|
||||
|
||||
var ErrUserQuit = errors.New("user quit")
|
||||
|
||||
type TaskConfig = service.Config
|
||||
|
||||
type Interface interface {
|
||||
|
||||
@@ -7,6 +7,15 @@ import (
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
type Questions []*huh.Group
|
||||
|
||||
type QuestionnaireModel struct {
|
||||
Questions
|
||||
form *huh.Form
|
||||
width, height int
|
||||
userQuit bool
|
||||
}
|
||||
|
||||
func NewQuestionnaireModel(questions Questions) *QuestionnaireModel {
|
||||
form := huh.NewForm(questions...).
|
||||
WithTheme(style.HuhCenterTheme()).WithLayout(huh.LayoutGrid(1, 1))
|
||||
@@ -28,6 +37,7 @@ func (q *QuestionnaireModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case tea.KeyMsg:
|
||||
switch msg.String() {
|
||||
case "q", "ctrl+c":
|
||||
q.userQuit = true
|
||||
return q, tea.Quit
|
||||
}
|
||||
}
|
||||
@@ -52,3 +62,7 @@ func (q *QuestionnaireModel) View() string {
|
||||
func (q *QuestionnaireModel) SetSize(width, height int) {
|
||||
q.width, q.height = width, height
|
||||
}
|
||||
|
||||
func (q QuestionnaireModel) GetUserQuit() bool {
|
||||
return q.userQuit
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package taskui
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
@@ -9,6 +10,23 @@ import (
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
var ErrUserQuit = errors.New("user quit")
|
||||
|
||||
type TaskDetails struct {
|
||||
Title string
|
||||
Description string
|
||||
TimeToComplete string
|
||||
Difficulty string
|
||||
}
|
||||
|
||||
type TaskModel struct {
|
||||
TaskDetails
|
||||
keys TaskHelpKeys
|
||||
help help.Model
|
||||
width, height int
|
||||
userQuit bool
|
||||
}
|
||||
|
||||
func NewTaskModel(details TaskDetails) TaskModel {
|
||||
return TaskModel{
|
||||
TaskDetails: details,
|
||||
@@ -28,6 +46,7 @@ func (m TaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
case tea.KeyMsg:
|
||||
switch {
|
||||
case key.Matches(msg, m.keys.Quit):
|
||||
m.userQuit = true
|
||||
return m, tea.Quit
|
||||
case key.Matches(msg, m.keys.Continue):
|
||||
return m, tea.Quit
|
||||
@@ -70,3 +89,7 @@ func (m TaskModel) View() string {
|
||||
func (m *TaskModel) SetSize(width, height int) {
|
||||
m.width, m.height = width, height
|
||||
}
|
||||
|
||||
func (m TaskModel) GetUserQuit() bool {
|
||||
return m.userQuit
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package taskui
|
||||
|
||||
import (
|
||||
"github.com/charmbracelet/bubbles/help"
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
type TaskDetails struct {
|
||||
Title string
|
||||
Description string
|
||||
TimeToComplete string
|
||||
Difficulty string
|
||||
}
|
||||
|
||||
type TaskModel struct {
|
||||
TaskDetails
|
||||
keys TaskHelpKeys
|
||||
help help.Model
|
||||
width, height int
|
||||
}
|
||||
|
||||
type Questions []*huh.Group
|
||||
|
||||
type QuestionnaireModel struct {
|
||||
Questions
|
||||
form *huh.Form
|
||||
width, height int
|
||||
}
|
||||
Reference in New Issue
Block a user