Skip to content

Commit

Permalink
setup theming
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Sep 22, 2021
1 parent fe80ae7 commit 95c0b46
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 91 deletions.
60 changes: 2 additions & 58 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"log"
"os"

"github.com/knipferrc/fm/internal/constants"

"github.com/spf13/viper"
)

Expand All @@ -17,46 +15,12 @@ type SettingsConfig struct {
EnableMouseWheel bool `mapstructure:"enable_mousewheel"`
PrettyMarkdown bool `mapstructure:"pretty_markdown"`
Borderless bool `mapstructure:"borderless"`
}

// DirTreeColors struct represents the colors for the dirtree.
type DirTreeColors struct {
SelectedItem string `mapstructure:"selected_item"`
UnselectedItem string `mapstructure:"unselected_item"`
}

// PaneColors represents the colors for a pane.
type PaneColors struct {
ActiveBorderColor string `mapstructure:"active_border_color"`
InactiveBorderColor string `mapstructure:"inactive_border_color"`
}

// ColorVariant struct represents a color.
type ColorVariant struct {
Foreground string `mapstructure:"foreground"`
Background string `mapstructure:"background"`
}

// StatusBarColors represents the colors for the status bar.
type StatusBarColors struct {
SelectedFile ColorVariant `mapstructure:"selected_file"`
Bar ColorVariant `mapstructure:"bar"`
TotalFiles ColorVariant `mapstructure:"total_files"`
Logo ColorVariant `mapstructure:"logo"`
}

// ColorsConfig struct represets the colors of the UI.
type ColorsConfig struct {
DirTree DirTreeColors `mapstructure:"dir_tree"`
Pane PaneColors `mapstructure:"pane"`
Spinner string `mapstructure:"spinner"`
StatusBar StatusBarColors `mapstructure:"status_bar"`
Theme string `mapstructure:"theme"`
}

// Config represents the main config for the application.
type Config struct {
Settings SettingsConfig `mapstructure:"settings"`
Colors ColorsConfig `mapstructure:"colors"`
}

// LoadConfig loads a users config and creates the config if it does not exist
Expand Down Expand Up @@ -100,25 +64,5 @@ func SetDefaults() {
viper.SetDefault("settings.enable_mousewheel", true)
viper.SetDefault("settings.pretty_markdown", true)
viper.SetDefault("settings.borderless", false)

// DirTree colors.
viper.SetDefault("colors.dir_tree.selected_item", constants.Colors.Pink)
viper.SetDefault("colors.dir_tree.unselected_item", constants.Colors.White)

// Pane colors.
viper.SetDefault("colors.pane.active_border_color", constants.Colors.Pink)
viper.SetDefault("colors.pane.inactive_border_color", constants.Colors.White)

// Spinner colors.
viper.SetDefault("colors.spinner", constants.Colors.Pink)

// StatusBar colors.
viper.SetDefault("colors.status_bar.selected_file.foreground", constants.Colors.White)
viper.SetDefault("colors.status_bar.selected_file.background", constants.Colors.Pink)
viper.SetDefault("colors.status_bar.bar.foreground", constants.Colors.White)
viper.SetDefault("colors.status_bar.bar.background", constants.Colors.DarkGray)
viper.SetDefault("colors.status_bar.total_files.foreground", constants.Colors.White)
viper.SetDefault("colors.status_bar.total_files.background", constants.Colors.LightPurple)
viper.SetDefault("colors.status_bar.logo.foreground", constants.Colors.White)
viper.SetDefault("colors.status_bar.logo.background", constants.Colors.DarkPurple)
viper.SetDefault("settings.theme", "default")
}
10 changes: 9 additions & 1 deletion internal/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ type ColorTypes struct {
DarkPurple string
DarkGray string
Red string
Green string
Blue string
Yellow string
Orange string
}

// Colors contains the different kinds of colors and their values.
Expand All @@ -41,5 +45,9 @@ var Colors = ColorTypes{
LightPurple: "#A550DF",
DarkPurple: "#6124DF",
DarkGray: "#353533",
Red: "#DC2626",
Red: "#cc241d",
Green: "#b8bb26",
Blue: "#458588",
Yellow: "#d79921",
Orange: "#d65d0e",
}
72 changes: 72 additions & 0 deletions internal/theme/theme.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package theme

import "github.com/knipferrc/fm/internal/constants"

type Theme struct {
SelectedTreeItemColor string
UnselectedTreeItemColor string
ActivePaneBorderColor string
InactivePaneBorderColor string
SpinnerColor string
StatusBarSelectedFileForegroundColor string
StatusBarSelectedFileBackgroundColor string
StatusBarBarForegroundColor string
StatusBarBarBackgroundColor string
StatusBarTotalFilesForegroundColor string
StatusBarTotalFilesBackgroundColor string
StatusBarLogoForegroundColor string
StatusBarLogoBackgroundColor string
}

func GetCurrentTheme(theme string) Theme {
switch theme {
case "default":
return Theme{
SelectedTreeItemColor: constants.Colors.Pink,
UnselectedTreeItemColor: constants.Colors.White,
ActivePaneBorderColor: constants.Colors.Pink,
InactivePaneBorderColor: constants.Colors.White,
SpinnerColor: constants.Colors.Pink,
StatusBarSelectedFileForegroundColor: constants.Colors.White,
StatusBarSelectedFileBackgroundColor: constants.Colors.Pink,
StatusBarBarForegroundColor: constants.Colors.White,
StatusBarBarBackgroundColor: constants.Colors.DarkGray,
StatusBarTotalFilesForegroundColor: constants.Colors.White,
StatusBarTotalFilesBackgroundColor: constants.Colors.LightPurple,
StatusBarLogoForegroundColor: constants.Colors.White,
StatusBarLogoBackgroundColor: constants.Colors.DarkPurple,
}
case "gruvbox":
return Theme{
SelectedTreeItemColor: constants.Colors.Orange,
UnselectedTreeItemColor: constants.Colors.White,
ActivePaneBorderColor: constants.Colors.Green,
InactivePaneBorderColor: constants.Colors.White,
SpinnerColor: constants.Colors.Red,
StatusBarSelectedFileForegroundColor: constants.Colors.White,
StatusBarSelectedFileBackgroundColor: constants.Colors.Red,
StatusBarBarForegroundColor: constants.Colors.White,
StatusBarBarBackgroundColor: constants.Colors.DarkGray,
StatusBarTotalFilesForegroundColor: constants.Colors.White,
StatusBarTotalFilesBackgroundColor: constants.Colors.Yellow,
StatusBarLogoForegroundColor: constants.Colors.White,
StatusBarLogoBackgroundColor: constants.Colors.Blue,
}
default:
return Theme{
SelectedTreeItemColor: constants.Colors.Pink,
UnselectedTreeItemColor: constants.Colors.White,
ActivePaneBorderColor: constants.Colors.Pink,
InactivePaneBorderColor: constants.Colors.White,
SpinnerColor: constants.Colors.Pink,
StatusBarSelectedFileForegroundColor: constants.Colors.White,
StatusBarSelectedFileBackgroundColor: constants.Colors.Pink,
StatusBarBarForegroundColor: constants.Colors.White,
StatusBarBarBackgroundColor: constants.Colors.DarkGray,
StatusBarTotalFilesForegroundColor: constants.Colors.White,
StatusBarTotalFilesBackgroundColor: constants.Colors.LightPurple,
StatusBarLogoForegroundColor: constants.Colors.White,
StatusBarLogoBackgroundColor: constants.Colors.DarkPurple,
}
}
}
69 changes: 37 additions & 32 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/knipferrc/fm/internal/pane"
"github.com/knipferrc/fm/internal/statusbar"
"github.com/knipferrc/fm/internal/text"
"github.com/knipferrc/fm/internal/theme"

"github.com/charmbracelet/bubbles/help"
"github.com/charmbracelet/bubbles/spinner"
Expand Down Expand Up @@ -39,23 +40,26 @@ type Model struct {
previousKey tea.KeyMsg
itemToMove fs.DirEntry
appConfig config.Config
directoryItemSizeCtx *directoryItemSizeCtx
theme theme.Theme
previousDirectory string
initialMoveDirectory string
showCommandBar bool
inMoveMode bool
ready bool
directoryItemSizeCtx *directoryItemSizeCtx
}

// NewModel create an instance of the entire application model.
func NewModel() Model {
cfg := config.GetConfig()
keys := getDefaultKeyMap()

theme := theme.GetCurrentTheme(cfg.Settings.Theme)

// Create a new spinner with some styling based on the config.
l := spinner.NewModel()
l.Spinner = spinner.Dot
l.Style = lipgloss.NewStyle().Foreground(lipgloss.Color(cfg.Colors.Spinner))
l.Style = lipgloss.NewStyle().Foreground(lipgloss.Color(theme.SpinnerColor))

// Create a new help view.
h := help.NewModel()
Expand All @@ -66,24 +70,24 @@ func NewModel() Model {
// Create a new dirtree.
dirTree := dirtree.NewModel(
cfg.Settings.ShowIcons,
cfg.Colors.DirTree.SelectedItem,
cfg.Colors.DirTree.UnselectedItem,
theme.SelectedTreeItemColor,
theme.UnselectedTreeItemColor,
)

// Initialize the primary pane as active and pass in some config values.
primaryPane := pane.NewModel(
true,
cfg.Settings.Borderless,
cfg.Colors.Pane.ActiveBorderColor,
cfg.Colors.Pane.InactiveBorderColor,
theme.ActivePaneBorderColor,
theme.InactivePaneBorderColor,
)

// Initialize the secondary pane as inactive and pass in some config values.
secondaryPane := pane.NewModel(
false,
cfg.Settings.Borderless,
cfg.Colors.Pane.ActiveBorderColor,
cfg.Colors.Pane.InactiveBorderColor,
theme.ActivePaneBorderColor,
theme.InactivePaneBorderColor,
)

// Set secondary panes initial content to the introText.
Expand All @@ -92,44 +96,45 @@ func NewModel() Model {
// Initialize a status bar passing in config values.
statusBar := statusbar.NewModel(
statusbar.Color{
Background: cfg.Colors.StatusBar.SelectedFile.Background,
Foreground: cfg.Colors.StatusBar.SelectedFile.Foreground,
Background: theme.StatusBarSelectedFileBackgroundColor,
Foreground: theme.StatusBarSelectedFileForegroundColor,
},
statusbar.Color{
Background: cfg.Colors.StatusBar.Bar.Background,
Foreground: cfg.Colors.StatusBar.Bar.Foreground,
Background: theme.StatusBarBarBackgroundColor,
Foreground: theme.StatusBarBarForegroundColor,
},
statusbar.Color{
Background: cfg.Colors.StatusBar.TotalFiles.Background,
Foreground: cfg.Colors.StatusBar.TotalFiles.Foreground,
Background: theme.StatusBarTotalFilesBackgroundColor,
Foreground: theme.StatusBarTotalFilesForegroundColor,
},
statusbar.Color{
Background: cfg.Colors.StatusBar.Logo.Background,
Foreground: cfg.Colors.StatusBar.Logo.Foreground,
Background: theme.StatusBarLogoBackgroundColor,
Foreground: theme.StatusBarLogoForegroundColor,
},
)

return Model{
keys: keys,
help: h,
primaryPane: primaryPane,
secondaryPane: secondaryPane,
loader: l,
dirTree: dirTree,
statusBar: statusBar,
colorimage: colorimage.Model{},
markdown: markdown.Model{},
text: text.Model{},
previousKey: tea.KeyMsg{},
itemToMove: nil,
appConfig: cfg,
keys: keys,
help: h,
primaryPane: primaryPane,
secondaryPane: secondaryPane,
loader: l,
dirTree: dirTree,
statusBar: statusBar,
colorimage: colorimage.Model{},
markdown: markdown.Model{},
text: text.Model{},
previousKey: tea.KeyMsg{},
itemToMove: nil,
appConfig: cfg,
directoryItemSizeCtx: &directoryItemSizeCtx{
ctx: context.Background(),
},
theme: theme,
previousDirectory: "",
initialMoveDirectory: "",
showCommandBar: false,
inMoveMode: false,
ready: false,
directoryItemSizeCtx: &directoryItemSizeCtx{
ctx: context.Background(),
},
}
}

0 comments on commit 95c0b46

Please sign in to comment.