Skip to content

Commit

Permalink
remove constants and setup theming
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Sep 22, 2021
1 parent 4b1583d commit 44c48b9
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 133 deletions.
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"os"

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

tea "github.com/charmbracelet/bubbletea"
Expand All @@ -16,7 +15,7 @@ import (
var rootCmd = &cobra.Command{
Use: "fm",
Short: "FM is a simple, configurable, and fun to use file manager",
Version: constants.Versions.AppVersion,
Version: "0.4.0",
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
config.SetDefaults()
Expand Down
9 changes: 9 additions & 0 deletions directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import (
"time"
)

// CurrentDirectory represents the current directory.
const CurrentDirectory = "."

// PreviousDirectory represents the previous directory.
const PreviousDirectory = ".."

// HomeDirectory represents the home directory.
const HomeDirectory = "~"

// RenameDirOrFile renames a directory or files given a source and destination.
func RenameDirOrFile(src, dst string) error {
err := os.Rename(src, dst)
Expand Down
53 changes: 0 additions & 53 deletions internal/constants/constants.go

This file was deleted.

10 changes: 4 additions & 6 deletions internal/statusbar/statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

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

"github.com/charmbracelet/bubbles/spinner"
"github.com/charmbracelet/bubbles/textinput"
Expand Down Expand Up @@ -43,7 +42,7 @@ type Model struct {
}

// NewModel creates an instance of a statusbar.
func NewModel(firstColumnColors, secondColumnColors, thirdColumnColors, fourthColumnColors Color) Model {
func NewModel(firstColumnColors, secondColumnColors, thirdColumnColors, fourthColumnColors Color, showIcons bool) Model {
input := textinput.NewModel()
input.Prompt = "❯ "
input.CharLimit = 250
Expand All @@ -56,7 +55,7 @@ func NewModel(firstColumnColors, secondColumnColors, thirdColumnColors, fourthCo
Height: 1,
TotalFiles: 0,
Cursor: 0,
ShowIcons: true,
ShowIcons: showIcons,
ShowCommandBar: false,
InMoveMode: false,
ItemSize: "",
Expand Down Expand Up @@ -128,10 +127,9 @@ func (m *Model) FocusCommandBar() {
}

// SetContent sets the content of the statusbar.
func (m *Model) SetContent(totalFiles, cursor int, showIcons, showCommandBar, inMoveMode bool, selectedFile, itemToMove fs.DirEntry) {
func (m *Model) SetContent(totalFiles, cursor int, showCommandBar, inMoveMode bool, selectedFile, itemToMove fs.DirEntry) {
m.TotalFiles = totalFiles
m.Cursor = cursor
m.ShowIcons = showIcons
m.ShowCommandBar = showCommandBar
m.InMoveMode = inMoveMode
m.SelectedFile = selectedFile
Expand Down Expand Up @@ -180,7 +178,7 @@ func (m Model) View() string {

currentPath, err := directory.GetWorkingDirectory()
if err != nil {
currentPath = constants.Directories.CurrentDirectory
currentPath = directory.CurrentDirectory
}

fileInfo, err := m.SelectedFile.Info()
Expand Down
116 changes: 69 additions & 47 deletions internal/theme/theme.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package theme

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

type Theme struct {
SelectedTreeItemColor string
UnselectedTreeItemColor string
Expand All @@ -16,57 +14,81 @@ type Theme struct {
StatusBarTotalFilesBackgroundColor string
StatusBarLogoForegroundColor string
StatusBarLogoBackgroundColor string
ErrorColor string
DefaultTextColor string
}

// appColors contains the different types of colors.
type appColors struct {
White string
Pink string
LightPurple string
DarkPurple string
DarkGray string
Red string
Green string
Blue string
Yellow string
Orange string
}

// Colors contains the different kinds of colors and their values.
var colors = appColors{
White: "#FFFDF5",
Pink: "#F25D94",
LightPurple: "#A550DF",
DarkPurple: "#6124DF",
DarkGray: "#3c3836",
Red: "#cc241d",
Green: "#b8bb26",
Blue: "#458588",
Yellow: "#d79921",
Orange: "#d65d0e",
}

var defaultTheme = Theme{
SelectedTreeItemColor: colors.Pink,
UnselectedTreeItemColor: colors.White,
ActivePaneBorderColor: colors.Pink,
InactivePaneBorderColor: colors.White,
SpinnerColor: colors.Pink,
StatusBarSelectedFileForegroundColor: colors.White,
StatusBarSelectedFileBackgroundColor: colors.Pink,
StatusBarBarForegroundColor: colors.White,
StatusBarBarBackgroundColor: colors.DarkGray,
StatusBarTotalFilesForegroundColor: colors.White,
StatusBarTotalFilesBackgroundColor: colors.LightPurple,
StatusBarLogoForegroundColor: colors.White,
StatusBarLogoBackgroundColor: colors.DarkPurple,
ErrorColor: colors.Red,
DefaultTextColor: colors.White,
}

var gruvboxTheme = Theme{
SelectedTreeItemColor: colors.Orange,
UnselectedTreeItemColor: colors.White,
ActivePaneBorderColor: colors.Green,
InactivePaneBorderColor: colors.White,
SpinnerColor: colors.Red,
StatusBarSelectedFileForegroundColor: colors.White,
StatusBarSelectedFileBackgroundColor: colors.Red,
StatusBarBarForegroundColor: colors.White,
StatusBarBarBackgroundColor: colors.DarkGray,
StatusBarTotalFilesForegroundColor: colors.White,
StatusBarTotalFilesBackgroundColor: colors.Yellow,
StatusBarLogoForegroundColor: colors.White,
StatusBarLogoBackgroundColor: colors.Blue,
ErrorColor: colors.Red,
DefaultTextColor: colors.White,
}

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,
}
return defaultTheme
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,
}
return gruvboxTheme
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,
}
return defaultTheme
}
}
3 changes: 1 addition & 2 deletions internal/ui/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"os"

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

"github.com/charmbracelet/bubbles/spinner"
tea "github.com/charmbracelet/bubbletea"
Expand All @@ -24,7 +23,7 @@ func (m Model) Init() tea.Cmd {
// Get the initial directory listing to be displayed
if _, err := os.Stat(startDir); err == nil {
cmds = append(cmds, m.updateDirectoryListing(startDir))
} else if m.appConfig.Settings.StartDir == constants.Directories.HomeDirectory {
} else if m.appConfig.Settings.StartDir == directory.HomeDirectory {
homeDir, err := directory.GetHomeDirectory()
if err != nil {
log.Fatal(err)
Expand Down
7 changes: 3 additions & 4 deletions internal/ui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"github.com/knipferrc/fm/internal/colorimage"
"github.com/knipferrc/fm/internal/config"
"github.com/knipferrc/fm/internal/constants"
"github.com/knipferrc/fm/internal/dirtree"
"github.com/knipferrc/fm/internal/markdown"
"github.com/knipferrc/fm/internal/pane"
Expand Down Expand Up @@ -53,7 +52,6 @@ type Model struct {
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.
Expand All @@ -63,8 +61,8 @@ func NewModel() Model {

// Create a new help view.
h := help.NewModel()
h.Styles.FullKey.Foreground(lipgloss.Color(constants.Colors.White))
h.Styles.FullDesc.Foreground(lipgloss.Color(constants.Colors.White))
h.Styles.FullKey.Foreground(lipgloss.Color(theme.DefaultTextColor))
h.Styles.FullDesc.Foreground(lipgloss.Color(theme.DefaultTextColor))
h.ShowAll = true

// Create a new dirtree.
Expand Down Expand Up @@ -111,6 +109,7 @@ func NewModel() Model {
Background: theme.StatusBarLogoBackgroundColor,
Foreground: theme.StatusBarLogoForegroundColor,
},
cfg.Settings.ShowIcons,
)

return Model{
Expand Down
Loading

0 comments on commit 44c48b9

Please sign in to comment.