works now

This commit is contained in:
Robin Olsen
2026-03-18 11:58:31 +01:00
parent 40d25cc716
commit 3e9a903506
24 changed files with 154 additions and 99 deletions

View File

@@ -5,6 +5,7 @@ import (
"os"
"charm.land/huh/v2"
"github.com/LazyBachelor/LazyPM/internal/style"
)
type Initializer interface {
@@ -30,7 +31,7 @@ func (i InteractiveInitializer) Init(path string) error {
Title("PM is not initialized in this directory!").
Description("Do you want to initialize it here?").
Value(&initialize),
)).WithTheme(huh.ThemeBase16()).WithAccessible(true).Run()
)).WithTheme(style.Base16Theme{}).WithAccessible(true).Run()
if err != nil {
return err

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"charm.land/huh/v2"
"github.com/LazyBachelor/LazyPM/internal/style"
"github.com/spf13/cobra"
)
@@ -47,13 +48,13 @@ func runCloseCmd(cmd *cobra.Command, args []string) error {
huh.NewOption("Won't fix", "Won't fix"),
huh.NewOption("Obsolete", "Obsolete"),
huh.NewOption("Other", "Other"),
).WithTheme(huh.ThemeBase()).Run(); err != nil {
).WithTheme(style.BaseTheme{}).Run(); err != nil {
return fmt.Errorf("error getting close reason: %w", err)
}
if closeReason == "Other" {
if err = huh.NewInput().Value(&closeReason).
Title("Enter closing reason:").WithTheme(huh.ThemeBase()).Run(); err != nil {
Title("Enter closing reason:").WithTheme(style.BaseTheme{}).Run(); err != nil {
return fmt.Errorf("error getting close reason: %w", err)
}
if closeReason == "" {

View File

@@ -7,6 +7,7 @@ import (
"charm.land/huh/v2"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/style"
"github.com/spf13/cobra"
)
@@ -62,7 +63,7 @@ func runDeleteCmd(cmd *cobra.Command, args []string) error {
if !cmd.Flags().Changed("yes") {
huh.NewConfirm().Value(&confirmDelete).
Title("You want to delete this issue?").
Inline(true).WithTheme(huh.ThemeBase()).Run()
Inline(true).WithTheme(style.BaseTheme{}).Run()
}
// If user did not confirm, cancel deletion.
@@ -102,7 +103,7 @@ func runDeleteInteractive(ctx context.Context) error {
huh.NewGroup(
huh.NewMultiSelect[string]().
Options(options...).Value(&deleteIDs).
Title("Select issues to delete"))).WithTheme(huh.ThemeBase())
Title("Select issues to delete"))).WithTheme(style.BaseTheme{})
if err := form.Run(); err != nil {
return fmt.Errorf("error running interactive form: %w", err)

View File

@@ -9,6 +9,7 @@ import (
"charm.land/huh/v2"
"github.com/LazyBachelor/LazyPM/internal/models"
"github.com/LazyBachelor/LazyPM/internal/style"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
"go.mongodb.org/mongo-driver/v2/mongo/options"
@@ -24,7 +25,7 @@ func NewMongoStorage(ctx context.Context, uri, username, password string) (*Mong
Password: password,
}
client, err := mongo.Connect(ctx,
client, err := mongo.Connect(
options.Client().ApplyURI(uri).SetAuth(credentials))
if err != nil {
@@ -44,7 +45,7 @@ func NewMongoStorageInteractive(ctx context.Context, uri string) (*MongoStorage,
if err := huh.NewInput().
Title("Enter the Database Username").
Value(&username).
WithTheme(huh.ThemeBase16()).Run(); err != nil {
WithTheme(style.Base16Theme{}).Run(); err != nil {
return nil, fmt.Errorf("failed to read username: %w", err)
}
} else {
@@ -60,7 +61,7 @@ func NewMongoStorageInteractive(ctx context.Context, uri string) (*MongoStorage,
Title("Enter the Survey Password").
EchoMode(huh.EchoModePassword).
Value(&password).
WithTheme(huh.ThemeBase16()).Run(); err != nil {
WithTheme(style.Base16Theme{}).Run(); err != nil {
return nil, fmt.Errorf("failed to read password: %w", err)
}
} else {
@@ -110,7 +111,7 @@ func (s *MongoStorage) SubmitSurveyResponsesCmd(ctx context.Context, dir string)
_, err = userStatscollection.UpdateOne(ctx,
bson.M{"_id": stats.ID},
bson.M{"$set": stats},
options.Update().SetUpsert(true))
options.UpdateOne().SetUpsert(true))
if err != nil {
return fmt.Errorf("Failed to insert stats into database: %v", err)
@@ -140,7 +141,7 @@ func (s *MongoStorage) SubmitSurveyResponsesCmd(ctx context.Context, dir string)
}
_, err = taskMetricsCollection.UpdateOne(ctx, bson.M{"_id": metrics.ID}, bson.M{"$set": metrics},
options.Update().SetUpsert(true))
options.UpdateOne().SetUpsert(true))
if err != nil {
fmt.Printf("failed to insert metrics from %s: %v", file, err)

View File

@@ -5,10 +5,44 @@ import (
"charm.land/lipgloss/v2"
)
func HuhCenterTheme() *huh.Styles {
theme := huh.ThemeBase16(true)
// BaseTheme wraps huh.ThemeBase for use as a huh.Theme
type BaseTheme struct{}
theme.Focused.Base = lipgloss.NewStyle().Align(lipgloss.Center)
func (t BaseTheme) Theme(isDark bool) *huh.Styles {
return huh.ThemeBase(isDark)
}
// Base16Theme wraps huh.ThemeBase16 for use as a huh.Theme
type Base16Theme struct{}
func (t Base16Theme) Theme(isDark bool) *huh.Styles {
return huh.ThemeBase16(isDark)
}
// CenterTheme is a theme that centers form content while preserving ThemeBase16 styling
type CenterTheme struct{}
func (t CenterTheme) Theme(isDark bool) *huh.Styles {
theme := huh.ThemeBase16(isDark)
// Center the field content
theme.Focused.Base = theme.Focused.Base.Align(lipgloss.Center)
theme.Focused.Card = lipgloss.NewStyle() // Remove card border
theme.Group.Base = lipgloss.NewStyle() // Remove group padding
return theme
}
// HuhCenterTheme returns a center-aligned theme for questionnaires
func HuhCenterTheme() huh.Theme {
return CenterTheme{}
}
// HuhBaseTheme returns a base theme
func HuhBaseTheme() huh.Theme {
return BaseTheme{}
}
// HuhBase16Theme returns a base16 theme
func HuhBase16Theme() huh.Theme {
return Base16Theme{}
}