diff --git a/cmd/convert.go b/cmd/convert.go index e8bffc2..c4534c5 100644 --- a/cmd/convert.go +++ b/cmd/convert.go @@ -5,6 +5,7 @@ package cmd import ( "fmt" + "strings" "github.com/Achno/gowall/internal/image" "github.com/Achno/gowall/utils" @@ -29,6 +30,18 @@ var convertCmd = &cobra.Command{ processor := &image.ThemeConverter{} expandedFiles := utils.ExpandHomeDirectory(batchFiles) image.ProcessBatchImgs(expandedFiles, theme, processor) + + case strings.HasSuffix(args[0],"#") : + fmt.Println("Processing directory...") + processor := &image.ThemeConverter{} + path := utils.DiscardLastCharacter(args[0]) + files ,err := utils.ExpandHashtag(path) + + if err != nil { + fmt.Printf("Error ExpandingHashTag: %s\n",err) + return + } + image.ProcessBatchImgs(files,theme,processor) case len(args) > 0: fmt.Println("Processing single image...") diff --git a/cmd/invert.go b/cmd/invert.go index baa7cf6..43bcf22 100644 --- a/cmd/invert.go +++ b/cmd/invert.go @@ -5,6 +5,7 @@ package cmd import ( "fmt" + "strings" "github.com/Achno/gowall/internal/image" "github.com/Achno/gowall/utils" @@ -28,6 +29,19 @@ var invertCmd = &cobra.Command{ expandedFiles := utils.ExpandHomeDirectory(batchFiles) image.ProcessBatchImgs(expandedFiles,theme,processor) + case strings.HasSuffix(args[0],"#") : + fmt.Println("Processing directory...") + processor := &image.Inverter{} + path := utils.DiscardLastCharacter(args[0]) + files ,err := utils.ExpandHashtag(path) + + if err != nil { + fmt.Printf("Error ExpandingHashTag: %s\n",err) + return + } + image.ProcessBatchImgs(files,theme,processor) + + case len(args) > 0: fmt.Println("Processing single image...") processor := &image.Inverter{} diff --git a/internal/image/themes.go b/internal/image/themes.go index 0165c52..e07ac52 100644 --- a/internal/image/themes.go +++ b/internal/image/themes.go @@ -46,6 +46,9 @@ var themes = map[string]Theme{ "sunset-aurant": SunsetAurant, "sunset-saffron": SunsetSaffron, "sunset-tangerine": SunsetTangerine, + "cyberpunk": Cyberpunk, + "night-owl": NightOwl, + "github-light": GitHubLight, } func init() { @@ -703,5 +706,87 @@ var ( }, } + Cyberpunk = Theme{ + Name: "Cyber-punk", + Colors: []color.Color{ + color.RGBA{R: 0, G: 0, B: 0, A: 255}, + color.RGBA{R: 255, G: 0, B: 255, A: 255}, + color.RGBA{R: 255, G: 255, B: 0, A: 255}, + color.RGBA{R: 0, G: 255, B: 255, A: 255}, + color.RGBA{R: 0, G: 255, B: 0, A: 255}, + color.RGBA{R: 255, G: 0, B: 0, A: 255}, + color.RGBA{R: 0, G: 0, B: 255, A: 255}, + color.RGBA{R: 255, G: 165, B: 0, A: 255}, + color.RGBA{R: 75, G: 0, B: 130, A: 255}, + color.RGBA{R: 238, G: 130, B: 238, A: 255}, + color.RGBA{R: 135, G: 206, B: 235, A: 255}, + color.RGBA{R: 255, G: 105, B: 180, A: 255}, + color.RGBA{R: 139, G: 0, B: 255, A: 255}, + color.RGBA{R: 255, G: 20, B: 147, A: 255}, + color.RGBA{R: 0, G: 128, B: 128, A: 255}, + color.RGBA{R: 255, G: 0, B: 255, A: 255}, + color.RGBA{R: 0, G: 0, B: 139, A: 255}, + color.RGBA{R: 255, G: 69, B: 0, A: 255}, + color.RGBA{R: 64, G: 224, B: 208, A: 255}, + color.RGBA{R: 186, G: 85, B: 211, A: 255}, + color.RGBA{R: 255, G: 182, B: 193, A: 255}, + }, + } + + + NightOwl = Theme{ + Name: "Night-owl", + Colors: []color.Color{ + color.RGBA{R: 0, G: 43, B: 54, A: 255}, + color.RGBA{R: 7, G: 54, B: 66, A: 255}, + color.RGBA{R: 88, G: 110, B: 117, A: 255}, + color.RGBA{R: 101, G: 123, B: 131, A: 255}, + color.RGBA{R: 147, G: 161, B: 161, A: 255}, + color.RGBA{R: 203, G: 75, B: 22, A: 255}, + color.RGBA{R: 88, G: 110, B: 117, A: 255}, + color.RGBA{R: 39, G: 150, B: 135, A: 255}, + color.RGBA{R: 0, G: 113, B: 133, A: 255}, + color.RGBA{R: 211, G: 54, B: 130, A: 255}, + color.RGBA{R: 131, G: 148, B: 150, A: 255}, + color.RGBA{R: 52, G: 101, B: 36, A: 255}, + color.RGBA{R: 229, G: 229, B: 229, A: 255}, + color.RGBA{R: 191, G: 97, B: 106, A: 255}, + color.RGBA{R: 236, G: 139, B: 67, A: 255}, + color.RGBA{R: 85, G: 139, B: 47, A: 255}, + color.RGBA{R: 102, G: 120, B: 105, A: 255}, + color.RGBA{R: 0, G: 128, B: 128, A: 255}, + color.RGBA{R: 240, G: 232, B: 196, A: 255}, + color.RGBA{R: 124, G: 45, B: 75, A: 255}, + }, + } + + GitHubLight = Theme{ + Name: "GitHub-Light", + Colors: []color.Color{ + color.RGBA{R: 255, G: 255, B: 255, A: 255}, + color.RGBA{R: 243, G: 243, B: 243, A: 255}, + color.RGBA{R: 235, G: 235, B: 235, A: 255}, + color.RGBA{R: 189, G: 189, B: 189, A: 255}, + color.RGBA{R: 102, G: 102, B: 102, A: 255}, + color.RGBA{R: 81, G: 81, B: 81, A: 255}, + color.RGBA{R: 0, G: 0, B: 0, A: 255}, + color.RGBA{R: 69, G: 69, B: 69, A: 255}, + color.RGBA{R: 238, G: 0, B: 0, A: 255}, + color.RGBA{R: 255, G: 153, B: 51, A: 255}, + color.RGBA{R: 34, G: 139, B: 34, A: 255}, + color.RGBA{R: 0, G: 0, B: 255, A: 255}, + color.RGBA{R: 148, G: 0, B: 211, A: 255}, + color.RGBA{R: 75, G: 0, B: 130, A: 255}, + color.RGBA{R: 102, G: 51, B: 153, A: 255}, + color.RGBA{R: 204, G: 204, B: 204, A: 255}, + color.RGBA{R: 170, G: 170, B: 170, A: 255}, + color.RGBA{R: 120, G: 120, B: 120, A: 255}, + color.RGBA{R: 170, G: 119, B: 204, A: 255}, + color.RGBA{R: 255, G: 69, B: 0, A: 255}, + color.RGBA{R: 255, G: 105, B: 180, A: 255}, + color.RGBA{R: 153, G: 204, B: 255, A: 255}, + }, + } + ) diff --git a/utils/expand.go b/utils/expand.go new file mode 100644 index 0000000..b76467c --- /dev/null +++ b/utils/expand.go @@ -0,0 +1,72 @@ +package utils + +import ( + "fmt" + "os" + "path/filepath" + "strings" +) + +// Function to expand the tilde (~) to the full home directory path +// @Example ~/Pictures/flowers.png --> /home/username/Pictures/flowers.png +func ExpandHomeDirectory(paths []string) []string { + var expandedPaths []string + homeDir, _ := os.UserHomeDir() + + for _, path := range paths { + if strings.HasPrefix(path, "~") { + path = filepath.Join(homeDir, path[1:]) + } + expandedPaths = append(expandedPaths, path) + } + return expandedPaths +} + +// Function to expand the delimeter '#' to every file under that directory +// Example "~/Pictures/#" -->["Pictures/img1.png","~/Pictures/img2.png","~/Pictures/img3.png"] +func ExpandHashtag(pathWithHashtag string) ([]string, error) { + + path := DiscardLastCharacter(pathWithHashtag) + + ImgPaths, err := expandToImgFiles(path) + + if err != nil{ + return nil,fmt.Errorf("error expanding to image files: %w",err) + } + + return ImgPaths,nil + +} + +// Expands a directory to only image files of type .png .jpeg .jpg .webp +// Example "~/Pictures/" -->["Pictures/img1.png","~/Pictures/img2.png","~/Pictures/img3.png"] +func expandToImgFiles(path string) ( []string, error){ + + filePaths , err := os.ReadDir(path) + + if err != nil{ + return nil,err + } + + images,err := filterImages(filePaths) + + if err != nil{ + return nil,err + } + + if len(images) == 0 { + return nil,fmt.Errorf("no image files in directory") + } + + contents := make([]string,len(images)) + + for i, img := range images{ + fullPath := filepath.Join(path,img) + contents[i] = fullPath + // fmt.Println(fullPath) debugging + } + + return contents,nil +} + + diff --git a/utils/expandToHomeDirectory.go b/utils/expandToHomeDirectory.go deleted file mode 100644 index 7273d88..0000000 --- a/utils/expandToHomeDirectory.go +++ /dev/null @@ -1,22 +0,0 @@ -package utils - -import ( - "os" - "path/filepath" - "strings" -) - -// Function to expand the tilde (~) to the full home directory path -// @Example ~/Pictures/flowers.png --> /home/username/Pictures/flowers.png -func ExpandHomeDirectory(paths []string) []string { - var expandedPaths []string - homeDir, _ := os.UserHomeDir() - - for _, path := range paths { - if strings.HasPrefix(path, "~") { - path = filepath.Join(homeDir, path[1:]) - } - expandedPaths = append(expandedPaths, path) - } - return expandedPaths -} \ No newline at end of file diff --git a/utils/filter.go b/utils/filter.go new file mode 100644 index 0000000..e94a751 --- /dev/null +++ b/utils/filter.go @@ -0,0 +1,48 @@ +package utils + +import ( + "fmt" + "io/fs" + "path/filepath" + "strings" + "unicode/utf8" +) + +// filters out all files other than .png .jpeg .jpg .webp in a directory +func filterImages(entries []fs.DirEntry) ([]string, error){ + + if len(entries) == 0{ + return nil,fmt.Errorf("directory is empty") + } + + var imageFiles []string + + supportedExtensions := map[string]bool{ + ".png": true, + ".jpeg": true, + ".jpg": true, + ".webp": true, + } + + for _ , entry := range entries{ + + if !entry.IsDir() && supportedExtensions[strings.ToLower(filepath.Ext(entry.Name()))]{ + imageFiles = append(imageFiles,entry.Name()) + } + } + + return imageFiles,nil + +} + +func DiscardLastCharacter(s string) string { + if len(s) == 0 { + return s + } + + // Decode the last rune + _, size := utf8.DecodeLastRuneInString(s) + + // exclude the last character + return s[:len(s)-size] +} \ No newline at end of file