diff --git a/internal/tui/config.go b/internal/tui/config.go index 4042b77..2be2cc3 100644 --- a/internal/tui/config.go +++ b/internal/tui/config.go @@ -7,10 +7,10 @@ import ( ) var ( - ConfigDirName = ".config/gitx" - ConfigFileName = "config.toml" - ConfigDirPath string - ConfigFilePath string + ConfigDirName = ".config/gitx" + ConfigFileName = "config.toml" + ConfigDirPath string + ConfigFilePath string ConfigThemesDirPath string ) @@ -53,4 +53,4 @@ func init() { fmt.Fprintf(os.Stderr, "Failed to initialize config: %v\n", err) os.Exit(1) } -} \ No newline at end of file +} diff --git a/internal/tui/model.go b/internal/tui/model.go index 084df2f..5f176f5 100644 --- a/internal/tui/model.go +++ b/internal/tui/model.go @@ -57,13 +57,13 @@ func initialModel() Model { cfg, _ := load_config() var selectedThemeName string - if t, ok := Themes[cfg.Theme]; ok{ + if t, ok := Themes[cfg.Theme]; ok { selectedThemeName = cfg.Theme _ = t // to avoid unused variable warning - } else{ - if _, err := load_custom_theme(cfg.Theme); err == nil{ - selectedThemeName = cfg.Theme - } else{ + } else { + if _, err := load_custom_theme(cfg.Theme); err == nil { + selectedThemeName = cfg.Theme + } else { //fallback selectedThemeName = themeNames[0] } @@ -118,9 +118,9 @@ func initialModel() Model { } } -func indexOf(arr []string, val string) int{ - for i, s := range arr{ - if s == val{ +func indexOf(arr []string, val string) int { + for i, s := range arr { + if s == val { return i } } diff --git a/internal/tui/theme.go b/internal/tui/theme.go index 953b4fa..b8564b3 100644 --- a/internal/tui/theme.go +++ b/internal/tui/theme.go @@ -151,18 +151,18 @@ type TreeStyle struct { Connector, ConnectorLast, Prefix, PrefixLast string } -//config.toml -type themeConfig struct{ - Theme string `toml:"theme"` +// config.toml +type themeConfig struct { + Theme string `toml:"theme"` } // custom_theme.toml -type ThemeFile struct{ - Fg string `toml:"fg"` - Bg string `toml:"bg"` +type ThemeFile struct { + Fg string `toml:"fg"` + Bg string `toml:"bg"` Normal map[string]string `toml:"normal"` Bright map[string]string `toml:"bright"` - Dark map[string]string `toml:"dark"` + Dark map[string]string `toml:"dark"` } // Themes holds all the available themes, generated from palettes. @@ -244,7 +244,7 @@ func ThemeNames() []string { return names } -func load_config() (*themeConfig, error){ +func load_config() (*themeConfig, error) { cfgPath := ConfigFilePath var cfg themeConfig @@ -255,12 +255,12 @@ func load_config() (*themeConfig, error){ return &cfg, nil } -func load_custom_theme(name string) (*Palette, error){ - themePath := filepath.Join(ConfigThemesDirPath, name + ".toml") - if _,err := os.Stat(themePath); os.IsNotExist(err) { +func load_custom_theme(name string) (*Palette, error) { + themePath := filepath.Join(ConfigThemesDirPath, name+".toml") + if _, err := os.Stat(themePath); os.IsNotExist(err) { return nil, fmt.Errorf("theme not found: %s", name) } - + var tf ThemeFile if _, err := toml.DecodeFile(themePath, &tf); err != nil { return nil, err @@ -268,20 +268,19 @@ func load_custom_theme(name string) (*Palette, error){ // Create a Palette from the ThemeFile p := Palette{ - Fg: tf.Fg, - Bg: tf.Bg, + Fg: tf.Fg, + Bg: tf.Bg, Black: tf.Normal["Black"], Red: tf.Normal["Red"], Green: tf.Normal["Green"], Yellow: tf.Normal["Yellow"], - Blue: tf.Normal["Blue"], Magenta: tf.Normal["Magenta"], Cyan: tf.Normal["Cyan"], White: tf.Normal["White"], - - BrightBlack: tf.Bright["Black"], BrightRed: tf.Bright["Red"], BrightGreen: tf.Bright["Green"], BrightYellow: tf.Bright["Yellow"], - BrightBlue: tf.Bright["Blue"], BrightMagenta: tf.Bright["Magenta"], BrightCyan: tf.Bright["Cyan"], BrightWhite: tf.Bright["White"], + Blue: tf.Normal["Blue"], Magenta: tf.Normal["Magenta"], Cyan: tf.Normal["Cyan"], White: tf.Normal["White"], - DarkBlack: tf.Dark["Black"], DarkRed: tf.Dark["Red"], DarkGreen: tf.Dark["Green"], DarkYellow: tf.Dark["Yellow"], - DarkBlue: tf.Dark["Blue"], DarkMagenta: tf.Dark["Magenta"], DarkCyan: tf.Dark["Cyan"], DarkWhite: tf.Dark["White"], + BrightBlack: tf.Bright["Black"], BrightRed: tf.Bright["Red"], BrightGreen: tf.Bright["Green"], BrightYellow: tf.Bright["Yellow"], + BrightBlue: tf.Bright["Blue"], BrightMagenta: tf.Bright["Magenta"], BrightCyan: tf.Bright["Cyan"], BrightWhite: tf.Bright["White"], + DarkBlack: tf.Dark["Black"], DarkRed: tf.Dark["Red"], DarkGreen: tf.Dark["Green"], DarkYellow: tf.Dark["Yellow"], + DarkBlue: tf.Dark["Blue"], DarkMagenta: tf.Dark["Magenta"], DarkCyan: tf.Dark["Cyan"], DarkWhite: tf.Dark["White"], } - Palettes[name] = p // Add to Palettes map for future use + Palettes[name] = p // Add to Palettes map for future use Themes[name] = NewThemeFromPalette(p) // Add to Themes map return &p, nil diff --git a/justfile b/justfile new file mode 100644 index 0000000..38d6d39 --- /dev/null +++ b/justfile @@ -0,0 +1,98 @@ +binary_name := "gitx" +cmd_path := "./cmd/gitx" +build_path := "./build" +app_version := `git describe --tags --abbrev=0 2>/dev/null || echo "dev"` +ldflags := "-X main.version=" + app_version + +default: build + +# Syncs dependencies +[group('core')] +sync: + @echo "Syncing dependencies..." + @go mod tidy + @echo "Dependencies synced." + +# Builds the binary, runs sync first +[group('core')] +build: sync + @echo "Building the application..." + @mkdir -p {{ build_path }} + @go build -ldflags "{{ ldflags }}" -o {{ build_path }}/{{ binary_name }} {{ cmd_path }} + @echo "Binary available at {{ build_path }}/{{ binary_name }}" + +# Runs the application, runs build first +[group('core')] +run: build + @echo "Running {{ binary_name }}..." + @{{ build_path }}/{{ binary_name }} + +# Installs the binary to GOPATH/bin, runs build first +[group('core')] +install: build + @echo "Installing {{ binary_name }}..." + @go install {{ ldflags }} {{ cmd_path }} + @echo "{{ binary_name }} installed successfully" + +# Print help message, runs build first +[group('core')] +help: build + @{{ build_path }}/{{ binary_name }} --help + +# Runs all tests +[group('dev')] +test: + @echo "Running tests..." + @go test -v ./... + +# Runs golangci-lint +[group('dev')] +ci: + @echo "Running golangci-lint..." + @golangci-lint run + +# Format Go code +[group('dev')] +fmt: + @echo "Formatting Go code..." + @go fmt ./... + +# Static analysis +[group('dev')] +vet: + @echo "Running go vet..." + @go vet ./... + +# Test for any race conditions +[group('dev')] +test-race: + @echo "Running race tests..." + @go test -race ./... + +# Coverage summary + artifact +[group('dev')] +cover: + @echo "Running coverage..." + @go test -coverprofile=coverage.out ./... + @go tool cover -func=coverage.out + +# Run all checks: fmt, vet, test, ci +[group('dev')] +check: fmt vet test ci + @echo "All checks passed." + +# Print binary version, runs build first +[group('dev')] +version: + @{{ build_path }}/{{ binary_name }} --version + +# Clean and rebuild the binary +[group('maintenance')] +rebuild: clean build + +# Cleans the build directory +[group('maintenance')] +clean: + @echo "Cleaning up..." + @rm -rf {{ build_path }} + @echo "Cleanup complete."