Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/tui/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -53,4 +53,4 @@ func init() {
fmt.Fprintf(os.Stderr, "Failed to initialize config: %v\n", err)
os.Exit(1)
}
}
}
16 changes: 8 additions & 8 deletions internal/tui/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
Expand Down Expand Up @@ -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
}
}
Expand Down
41 changes: 20 additions & 21 deletions internal/tui/theme.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -244,7 +244,7 @@ func ThemeNames() []string {
return names
}

func load_config() (*themeConfig, error){
func load_config() (*themeConfig, error) {
cfgPath := ConfigFilePath

var cfg themeConfig
Expand All @@ -255,33 +255,32 @@ 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
}

// 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
Expand Down
98 changes: 98 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -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."