Skip to content

Commit 1835394

Browse files
authored
TUI: add light/dark theme support (#393)
* tui: add light/dark theme support with --theme flag Replace hardcoded dark-theme colors with a switchable palette via styles.SetDarkTheme(). The light palette uses darker color variants (dark gold, dark green, dark teal, black text) optimized for light terminal backgrounds. Add --theme CLI flag and KUBEFWD_THEME env var to override the default dark theme. Priority: flag > env var > default (dark). Usage: sudo -E kubefwd svc -n ns --tui --theme light KUBEFWD_THEME=light sudo -E kubefwd svc -n ns --tui * Remove FOSSA license verification config FOSSA's JS dependency scanning requires a paid account for exclusions and consistently fails on documentation build dependencies.
1 parent c08d613 commit 1835394

File tree

4 files changed

+349
-283
lines changed

4 files changed

+349
-283
lines changed

.fossa.yml

Lines changed: 0 additions & 29 deletions
This file was deleted.

cmd/kubefwd/services/services.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"os"
88
"os/signal"
99
"runtime"
10+
"strings"
1011
"sync"
1112
"syscall"
1213
"time"
@@ -22,6 +23,7 @@ import (
2223
"github.com/txn2/kubefwd/pkg/fwdtui"
2324
"github.com/txn2/kubefwd/pkg/fwdtui/events"
2425
"github.com/txn2/kubefwd/pkg/fwdtui/state"
26+
"github.com/txn2/kubefwd/pkg/fwdtui/styles"
2527
"github.com/txn2/kubefwd/pkg/utils"
2628
"github.com/txn2/txeh"
2729

@@ -54,6 +56,7 @@ var retryInterval time.Duration
5456
var tuiMode bool
5557
var apiMode bool
5658
var autoReconnect bool
59+
var themeOverride string
5760

5861
// Version is set by the main package
5962
var Version string
@@ -93,6 +96,7 @@ func init() {
9396
Cmd.Flags().BoolVar(&tuiMode, "tui", false, "Enable terminal user interface mode for interactive service monitoring")
9497
Cmd.Flags().BoolVar(&apiMode, "api", false, "Enable REST API server on http://kubefwd.internal/api for automation and monitoring")
9598
Cmd.Flags().BoolVarP(&autoReconnect, "auto-reconnect", "a", false, "Automatically reconnect when port forwards are lost (exponential backoff: 1s to 5min). Defaults to true in TUI/API mode.")
99+
Cmd.Flags().StringVar(&themeOverride, "theme", "", "Color theme for TUI: 'light' or 'dark' (auto-detected if not set, env: KUBEFWD_THEME)")
96100
}
97101

98102
var Cmd = &cobra.Command{
@@ -615,6 +619,29 @@ func startAPIServer(apiManager *fwdapi.Manager) {
615619
}()
616620
}
617621

622+
// configureTheme sets the terminal color scheme for lipgloss AdaptiveColor.
623+
// Priority: --theme flag > KUBEFWD_THEME env var > auto-detect.
624+
func configureTheme() {
625+
theme := themeOverride
626+
if theme == "" {
627+
theme = os.Getenv("KUBEFWD_THEME")
628+
}
629+
theme = strings.ToLower(strings.TrimSpace(theme))
630+
631+
switch theme {
632+
case "light":
633+
styles.SetDarkTheme(false)
634+
log.Printf("Theme: light (text colors optimized for light terminal backgrounds)")
635+
case "dark":
636+
styles.SetDarkTheme(true)
637+
log.Printf("Theme: dark")
638+
case "":
639+
// default dark theme (no change needed)
640+
default:
641+
log.Warnf("Unknown theme %q, using auto-detect. Valid values: light, dark", theme)
642+
}
643+
}
644+
618645
func runCmd(cmd *cobra.Command, _ []string) {
619646
if verbose {
620647
log.SetLevel(log.DebugLevel)
@@ -624,6 +651,8 @@ func runCmd(cmd *cobra.Command, _ []string) {
624651
return
625652
}
626653

654+
configureTheme()
655+
627656
idleMode := detectAndConfigureIdleMode(cmd)
628657
initializeTUIMode(cmd)
629658
initializeAPIMode(cmd)

0 commit comments

Comments
 (0)