feat: introduce theme management and performance improvements (#7)

This commit is contained in:
Karol Broda
2025-12-24 10:49:03 +01:00
committed by GitHub
parent ec5a4ee046
commit 1021ba13aa
20 changed files with 877 additions and 172 deletions

View File

@@ -3,11 +3,12 @@ package cmd
import (
"fmt"
"os"
"github.com/karol-broda/snitch/internal/config"
"github.com/karol-broda/snitch/internal/config"
"github.com/spf13/cobra"
)
var (
cfgFile string
)
@@ -42,7 +43,7 @@ func init() {
// add top's flags to root so `snitch -l` works (defaults to top command)
cfg := config.Get()
rootCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (dark, light, mono, auto)")
rootCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (see 'snitch themes')")
rootCmd.Flags().DurationVarP(&topInterval, "interval", "i", 0, "Refresh interval (default 1s)")
rootCmd.Flags().BoolVar(&topResolveAddrs, "resolve-addrs", !cfg.Defaults.Numeric, "Resolve IP addresses to hostnames")
rootCmd.Flags().BoolVar(&topResolvePorts, "resolve-ports", false, "Resolve port numbers to service names")

24
cmd/themes.go Normal file
View File

@@ -0,0 +1,24 @@
package cmd
import (
"fmt"
"github.com/karol-broda/snitch/internal/theme"
"github.com/spf13/cobra"
)
var themesCmd = &cobra.Command{
Use: "themes",
Short: "List available themes",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Available themes (default: %s):\n\n", theme.DefaultTheme)
for _, name := range theme.ListThemes() {
fmt.Printf(" %s\n", name)
}
},
}
func init() {
rootCmd.AddCommand(themesCmd)
}

View File

@@ -2,11 +2,11 @@ package cmd
import (
"log"
"github.com/karol-broda/snitch/internal/config"
"github.com/karol-broda/snitch/internal/tui"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/karol-broda/snitch/internal/config"
"github.com/karol-broda/snitch/internal/tui"
"github.com/spf13/cobra"
)
@@ -60,7 +60,7 @@ func init() {
cfg := config.Get()
// top-specific flags
topCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (dark, light, mono, auto)")
topCmd.Flags().StringVar(&topTheme, "theme", cfg.Defaults.Theme, "Theme for TUI (see 'snitch themes')")
topCmd.Flags().DurationVarP(&topInterval, "interval", "i", time.Second, "Refresh interval")
topCmd.Flags().BoolVar(&topResolveAddrs, "resolve-addrs", !cfg.Defaults.Numeric, "Resolve IP addresses to hostnames")
topCmd.Flags().BoolVar(&topResolvePorts, "resolve-ports", false, "Resolve port numbers to service names")