make sure repl works with new system
This commit is contained in:
@@ -137,7 +137,10 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func taskLoop(ctx context.Context, application *task.App, surveyTasks map[string]task.Tasker, interfaces map[string]task.Interface) error {
|
func taskLoop(ctx context.Context, application *task.App, surveyTasks map[string]task.Tasker, interfaces map[string]task.Interface) error {
|
||||||
iNames := task.ListInterfaces()
|
var iNames []string
|
||||||
|
for name := range interfaces {
|
||||||
|
iNames = append(iNames, name)
|
||||||
|
}
|
||||||
|
|
||||||
if len(iNames) == 0 {
|
if len(iNames) == 0 {
|
||||||
return fmt.Errorf("no interfaces are available")
|
return fmt.Errorf("no interfaces are available")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
package repl
|
package repl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@@ -12,7 +13,6 @@ import (
|
|||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/style"
|
"github.com/LazyBachelor/LazyPM/internal/style"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/task"
|
"github.com/LazyBachelor/LazyPM/pkg/task"
|
||||||
"github.com/LazyBachelor/LazyPM/pkg/tui/styles"
|
|
||||||
"github.com/c-bata/go-prompt"
|
"github.com/c-bata/go-prompt"
|
||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
@@ -36,6 +36,7 @@ type REPL struct {
|
|||||||
|
|
||||||
currentFeedback ValidationFeedback
|
currentFeedback ValidationFeedback
|
||||||
exitRequested bool
|
exitRequested bool
|
||||||
|
taskCompleted bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() *REPL {
|
func New() *REPL {
|
||||||
@@ -44,6 +45,11 @@ func New() *REPL {
|
|||||||
|
|
||||||
// Run starts the interactive Read-Eval-Print Loop for the PM CLI.
|
// Run starts the interactive Read-Eval-Print Loop for the PM CLI.
|
||||||
func (r *REPL) Run(ctx context.Context, config app.Config) error {
|
func (r *REPL) Run(ctx context.Context, config app.Config) error {
|
||||||
|
// Reset state for new task run
|
||||||
|
r.taskCompleted = false
|
||||||
|
r.exitRequested = false
|
||||||
|
r.currentFeedback = ValidationFeedback{}
|
||||||
|
|
||||||
// Set terminal to raw mode to capture input properly in the REPL.
|
// Set terminal to raw mode to capture input properly in the REPL.
|
||||||
// This allows us to handle input character by character and provide a better user experience.
|
// This allows us to handle input character by character and provide a better user experience.
|
||||||
// We also ensure that the terminal state is restored when the REPL exits, even if an error occurs.
|
// We also ensure that the terminal state is restored when the REPL exits, even if an error occurs.
|
||||||
@@ -82,7 +88,18 @@ func (r *REPL) Run(ctx context.Context, config app.Config) error {
|
|||||||
var history []string
|
var history []string
|
||||||
|
|
||||||
// Start the REPL loop, which continues until the user types "exit" or "quit" or task completes.
|
// Start the REPL loop, which continues until the user types "exit" or "quit" or task completes.
|
||||||
|
reader := bufio.NewReader(os.Stdin)
|
||||||
for !r.exitRequested {
|
for !r.exitRequested {
|
||||||
|
// Check if task completed - wait for Enter before exiting
|
||||||
|
if r.taskCompleted {
|
||||||
|
fmt.Println(style.TitleStyle.Render("Task completed successfully!"))
|
||||||
|
fmt.Print("Press Enter to exit...")
|
||||||
|
// Restore terminal to normal mode for input
|
||||||
|
term.Restore(int(os.Stdin.Fd()), oldState)
|
||||||
|
reader.ReadString('\n')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we should exit before prompting (non-blocking check)
|
// Check if we should exit before prompting (non-blocking check)
|
||||||
if r.exitRequested {
|
if r.exitRequested {
|
||||||
break
|
break
|
||||||
@@ -100,6 +117,16 @@ func (r *REPL) Run(ctx context.Context, config app.Config) error {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if task completed while waiting at prompt
|
||||||
|
if r.taskCompleted {
|
||||||
|
fmt.Println(style.TitleStyle.Render("Task completed successfully!"))
|
||||||
|
fmt.Print("Press Enter to exit...")
|
||||||
|
// Restore terminal to normal mode for input
|
||||||
|
term.Restore(int(os.Stdin.Fd()), oldState)
|
||||||
|
reader.ReadString('\n')
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
// Trim whitespace from the input to ensure consistent command processing.
|
// Trim whitespace from the input to ensure consistent command processing.
|
||||||
input = strings.TrimSpace(input)
|
input = strings.TrimSpace(input)
|
||||||
|
|
||||||
@@ -138,9 +165,7 @@ func (r *REPL) watchValidation() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if feedback.Success {
|
if feedback.Success {
|
||||||
fmt.Printf("\n%s\n", styles.TitleStyle.Render("Task completed successfully!"))
|
r.taskCompleted = true
|
||||||
fmt.Println("Press Enter to exit...")
|
|
||||||
r.exitRequested = true
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case <-r.quitChan:
|
case <-r.quitChan:
|
||||||
|
|||||||
Reference in New Issue
Block a user