Compare commits

..

4 Commits

@ -157,7 +157,7 @@ func stringToRGB(rgbString string) (*RGB, error) {
func loadColorsFromFile(filepath string) error { func loadColorsFromFile(filepath string) error {
data, err := os.ReadFile(filepath) data, err := os.ReadFile(filepath)
if err != nil { if err != nil {
panic(err) return err
} }
// Read color config file into a MapSlice // Read color config file into a MapSlice
tempMapSlice := yaml.MapSlice{} tempMapSlice := yaml.MapSlice{}

@ -3,6 +3,7 @@ package main
import ( import (
"embed" "embed"
"errors" "errors"
"fmt"
"io/fs" "io/fs"
"os" "os"
"path/filepath" "path/filepath"
@ -88,7 +89,10 @@ func loadConfig(configFilename string) (stack.Stack[regColor], error) {
// returned. // returned.
regColorStack := stack.NewStack[regColor](len(strings.Split(string(configFile), "\n"))) // The stack will have the same size as the number of lines in the file regColorStack := stack.NewStack[regColor](len(strings.Split(string(configFile), "\n"))) // The stack will have the same size as the number of lines in the file
for _, item := range tempMapSlice { for _, item := range tempMapSlice {
re := regex.MustCompile(item.Key.(string), regex.RE_MULTILINE, regex.RE_SINGLE_LINE) re, err := regex.Compile(item.Key.(string), regex.RE_MULTILINE, regex.RE_SINGLE_LINE)
if err != nil {
return *stack.NewStack[regColor](0), fmt.Errorf("%v: '%s'", err, item.Key.(string))
}
clr, err := newColor(item.Value.(string)) clr, err := newColor(item.Value.(string))
if err != nil { if err != nil {
return *stack.NewStack[regColor](0), err return *stack.NewStack[regColor](0), err

@ -79,7 +79,7 @@ func main() {
// Check if config exists. If it doesn't, generate the config files. // Check if config exists. If it doesn't, generate the config files.
userHomeDir, err := os.UserHomeDir() // Get current user's home directory, to construct config path userHomeDir, err := os.UserHomeDir() // Get current user's home directory, to construct config path
if err != nil { if err != nil {
panic(err) printErrAndExit("Unable to retrieve user home directory")
} }
configPath := filepath.Join(userHomeDir + "/.config/ccat/") configPath := filepath.Join(userHomeDir + "/.config/ccat/")
if _, err := os.Stat(configPath); os.IsNotExist(err) { if _, err := os.Stat(configPath); os.IsNotExist(err) {
@ -107,7 +107,7 @@ func main() {
// the program. // the program.
finfo, err := os.Stat(fileName) finfo, err := os.Stat(fileName)
if err != nil { if err != nil {
panic(err) printErrAndExit("Unable to read file")
} }
if finfo.Size() == 0 { if finfo.Size() == 0 {
os.Exit(0) os.Exit(0)

Loading…
Cancel
Save