lots of changes and reducing dependency imports
This commit is contained in:
@@ -5,10 +5,23 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
taskui "github.com/LazyBachelor/LazyPM/pkg/task/ui"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type Config = models.Config
|
||||
|
||||
type Tasker = models.Tasker
|
||||
|
||||
type Interface = models.Interface
|
||||
type InterfaceType = models.InterfaceType
|
||||
|
||||
type ValidatedInterface = models.ValidatedInterface
|
||||
type ValidationFeedback = models.ValidationFeedback
|
||||
|
||||
var ErrUserQuit = models.ErrUserQuit
|
||||
|
||||
// RunTask orchestrates the complete task execution flow:
|
||||
// 1. Setup the task
|
||||
// 2. Show task intro screen
|
||||
@@ -85,21 +98,15 @@ func startValidationLoop(ctx context.Context, t Tasker, feedbackChan chan Valida
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
ok, err := t.Validate(ctx)
|
||||
feedback := ValidationFeedback{
|
||||
Success: ok,
|
||||
}
|
||||
if ok {
|
||||
feedback := t.Validate(ctx)
|
||||
if feedback.Success {
|
||||
feedback.Message = "Task completed successfully!"
|
||||
feedbackChan <- feedback
|
||||
time.Sleep(4 * time.Second)
|
||||
doneChan <- true
|
||||
return
|
||||
}
|
||||
if err != nil {
|
||||
feedback.Message = err.Error()
|
||||
} else {
|
||||
feedback.Message = "Task not yet complete"
|
||||
}
|
||||
feedback.Message = "Task not completed!"
|
||||
feedbackChan <- feedback
|
||||
case <-quitChan:
|
||||
return
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package task
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/LazyBachelor/LazyPM/internal/service"
|
||||
taskui "github.com/LazyBachelor/LazyPM/pkg/task/ui"
|
||||
)
|
||||
|
||||
type Config = service.Config
|
||||
type InterfaceType string
|
||||
|
||||
type Interface interface {
|
||||
Run(context.Context, Config) error
|
||||
}
|
||||
|
||||
type Tasker interface {
|
||||
Config() Config
|
||||
Details() taskui.TaskDetails
|
||||
Questions(InterfaceType) taskui.Questions
|
||||
Setup(context.Context) error
|
||||
Validate(context.Context) (bool, error)
|
||||
}
|
||||
|
||||
type ValidationFeedback struct {
|
||||
Success bool
|
||||
Message string
|
||||
}
|
||||
|
||||
type ValidatedInterface interface {
|
||||
Interface
|
||||
SetChannels(feedbackChan chan ValidationFeedback, quitChan chan bool)
|
||||
}
|
||||
|
||||
var ErrUserQuit = fmt.Errorf("user quit")
|
||||
@@ -2,11 +2,14 @@ package taskui
|
||||
|
||||
import (
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/style"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
"github.com/charmbracelet/huh"
|
||||
)
|
||||
|
||||
type Questions = models.Questions
|
||||
|
||||
type QuestionnaireModel struct {
|
||||
Questions
|
||||
form *huh.Form
|
||||
|
||||
@@ -5,11 +5,14 @@ import (
|
||||
"strings"
|
||||
|
||||
"charm.land/lipgloss/v2"
|
||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||
"github.com/LazyBachelor/LazyPM/internal/style"
|
||||
"github.com/charmbracelet/bubbles/key"
|
||||
tea "github.com/charmbracelet/bubbletea"
|
||||
)
|
||||
|
||||
type TaskDetails = models.TaskDetails
|
||||
|
||||
type TaskModel struct {
|
||||
TaskDetails
|
||||
keys TaskHelpKeys
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
package taskui
|
||||
|
||||
import "github.com/charmbracelet/huh"
|
||||
|
||||
type TaskDetails struct {
|
||||
Title string
|
||||
Description string
|
||||
TimeToComplete string
|
||||
Difficulty string
|
||||
}
|
||||
|
||||
func (td TaskDetails) WithTitle(title string) TaskDetails {
|
||||
td.Title = title
|
||||
return td
|
||||
}
|
||||
|
||||
func (td TaskDetails) WithDescription(description string) TaskDetails {
|
||||
td.Description = description
|
||||
return td
|
||||
}
|
||||
|
||||
func (td TaskDetails) WithTimeToComplete(time string) TaskDetails {
|
||||
td.TimeToComplete = time
|
||||
return td
|
||||
}
|
||||
|
||||
func (td TaskDetails) WithDifficulty(difficulty string) TaskDetails {
|
||||
td.Difficulty = difficulty
|
||||
return td
|
||||
}
|
||||
|
||||
type Questions []*huh.Group
|
||||
|
||||
func (q Questions) With(group *huh.Group) Questions {
|
||||
if group == nil {
|
||||
return q
|
||||
}
|
||||
return append(q, group)
|
||||
}
|
||||
Reference in New Issue
Block a user