separete into fucntion and use charm dependency instead

This commit is contained in:
Robin Olsen
2026-03-24 21:04:05 +01:00
parent effc0a8f99
commit 9b06557455
4 changed files with 29 additions and 22 deletions

View File

@@ -151,21 +151,10 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
return returnIfUserQuit(err, "task loop failed")
}
fmt.Println("\033[H\033[2J")
width, height, err := term.GetSize(os.Stdin.Fd())
if err != nil {
return fmt.Errorf("failed to get terminal size: %w", err)
if err := endingMessage(); err != nil {
return fmt.Errorf("failed to display ending message: %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
}
@@ -216,6 +205,25 @@ func taskLoop(ctx context.Context, application *task.App, surveyTasks map[string
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 {
if errors.Is(err, task.ErrUserQuit) {
return nil