separete into fucntion and use charm dependency instead
This commit is contained in:
@@ -151,21 +151,10 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
|
|||||||
return returnIfUserQuit(err, "task loop failed")
|
return returnIfUserQuit(err, "task loop failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("\033[H\033[2J")
|
if err := endingMessage(); err != nil {
|
||||||
|
return fmt.Errorf("failed to display ending message: %w", err)
|
||||||
width, height, err := term.GetSize(os.Stdin.Fd())
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to get terminal size: %w", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
content := lipgloss.NewStyle().Align(lipgloss.Center).Bold(true).
|
|
||||||
Render("You have completed all the tasks!\nThank you for participating in the survey.")
|
|
||||||
|
|
||||||
centered := lipgloss.Place(width, height, lipgloss.Center, lipgloss.Center, content)
|
|
||||||
v := tea.NewView(centered)
|
|
||||||
fmt.Println(v.Content)
|
|
||||||
_, _ = fmt.Fscanf(os.Stdin, "%s")
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,6 +205,25 @@ func taskLoop(ctx context.Context, application *task.App, surveyTasks map[string
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func endingMessage() error {
|
||||||
|
fmt.Println("\033[H\033[2J")
|
||||||
|
|
||||||
|
width, height, err := term.GetSize(os.Stdin.Fd())
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to get terminal size: %v\n", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
content := lipgloss.NewStyle().Align(lipgloss.Center).Bold(true).
|
||||||
|
Render("You have completed all the tasks!\nThank you for participating in the survey.")
|
||||||
|
|
||||||
|
centered := lipgloss.Place(width, height, lipgloss.Center, lipgloss.Center, content)
|
||||||
|
v := tea.NewView(centered)
|
||||||
|
fmt.Println(v.Content)
|
||||||
|
_, _ = fmt.Fscanf(os.Stdin, "%s")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func returnIfUserQuit(err error, msg string) error {
|
func returnIfUserQuit(err error, msg string) error {
|
||||||
if errors.Is(err, task.ErrUserQuit) {
|
if errors.Is(err, task.ErrUserQuit) {
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
3
go.mod
3
go.mod
@@ -4,13 +4,13 @@ go 1.26.1
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/c-bata/go-prompt v0.2.7-0.20250812090649-d000795a4f93
|
github.com/c-bata/go-prompt v0.2.7-0.20250812090649-d000795a4f93
|
||||||
|
github.com/charmbracelet/x/term v0.2.2
|
||||||
github.com/go-git/go-git/v6 v6.0.0-20260317113930-fb0d09929504
|
github.com/go-git/go-git/v6 v6.0.0-20260317113930-fb0d09929504
|
||||||
github.com/joho/godotenv v1.5.1
|
github.com/joho/godotenv v1.5.1
|
||||||
github.com/muesli/reflow v0.3.0
|
github.com/muesli/reflow v0.3.0
|
||||||
github.com/spf13/pflag v1.0.10
|
github.com/spf13/pflag v1.0.10
|
||||||
github.com/steveyegge/beads v0.49.6
|
github.com/steveyegge/beads v0.49.6
|
||||||
go.mongodb.org/mongo-driver/v2 v2.5.0
|
go.mongodb.org/mongo-driver/v2 v2.5.0
|
||||||
golang.org/x/term v0.41.0
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Terminal dependencies
|
// Terminal dependencies
|
||||||
@@ -48,7 +48,6 @@ require (
|
|||||||
github.com/charmbracelet/x/exp/charmtone v0.0.0-20260316093931-f2fb44ab3145 // indirect
|
github.com/charmbracelet/x/exp/charmtone v0.0.0-20260316093931-f2fb44ab3145 // indirect
|
||||||
github.com/charmbracelet/x/exp/ordered v0.1.0 // indirect
|
github.com/charmbracelet/x/exp/ordered v0.1.0 // indirect
|
||||||
github.com/charmbracelet/x/exp/strings v0.1.0 // indirect
|
github.com/charmbracelet/x/exp/strings v0.1.0 // indirect
|
||||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
|
||||||
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
github.com/charmbracelet/x/termios v0.1.1 // indirect
|
||||||
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
github.com/charmbracelet/x/windows v0.2.2 // indirect
|
||||||
github.com/cli/browser v1.3.0 // indirect
|
github.com/cli/browser v1.3.0 // indirect
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import (
|
|||||||
"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/c-bata/go-prompt"
|
"github.com/c-bata/go-prompt"
|
||||||
"golang.org/x/term"
|
"github.com/charmbracelet/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
type App = models.App
|
type App = models.App
|
||||||
@@ -50,9 +50,9 @@ func (r *REPL) Run(ctx context.Context, config app.Config) error {
|
|||||||
r.currentFeedback = ValidationFeedback{}
|
r.currentFeedback = ValidationFeedback{}
|
||||||
|
|
||||||
// Save terminal state to restore on exit
|
// Save terminal state to restore on exit
|
||||||
oldState, err := term.GetState(int(os.Stdin.Fd()))
|
oldState, err := term.GetState(uintptr(os.Stdin.Fd()))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer term.Restore(int(os.Stdin.Fd()), oldState)
|
defer term.Restore(uintptr(os.Stdin.Fd()), oldState)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize services for beads, config and stats.
|
// Initialize services for beads, config and stats.
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ import (
|
|||||||
"log/slog"
|
"log/slog"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"charm.land/bubbletea/v2"
|
tea "charm.land/bubbletea/v2"
|
||||||
"github.com/LazyBachelor/LazyPM/internal/models"
|
"github.com/LazyBachelor/LazyPM/internal/models"
|
||||||
"golang.org/x/term"
|
"github.com/charmbracelet/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
type App = models.App
|
type App = models.App
|
||||||
@@ -125,8 +125,8 @@ func (r *TaskRunner) Run(ctx context.Context, t Tasker, i Interface, iType Inter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldState, err := term.GetState(int(os.Stdin.Fd())); err == nil {
|
if oldState, err := term.GetState(uintptr(os.Stdin.Fd())); err == nil {
|
||||||
term.Restore(int(os.Stdin.Fd()), oldState)
|
term.Restore(uintptr(os.Stdin.Fd()), oldState)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Print("\033[0m\033[?25h")
|
fmt.Print("\033[0m\033[?25h")
|
||||||
|
|||||||
Reference in New Issue
Block a user