From adf4c62992dcc54753d32819ccc838bc1101ebfc Mon Sep 17 00:00:00 2001 From: Oussama Makhlouk Date: Sun, 7 Apr 2024 03:40:02 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Added=20icons=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/colors.go | 19 ++++++++++++++++++ module/const.go | 15 -------------- module/extension.go | 19 ++++++++++++++++++ module/icons.go | 15 ++++++++++++++ service/service.go | 1 + service/util.go | 49 +++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 module/colors.go delete mode 100644 module/const.go create mode 100644 module/extension.go create mode 100644 module/icons.go diff --git a/module/colors.go b/module/colors.go new file mode 100644 index 0000000..d43c4e0 --- /dev/null +++ b/module/colors.go @@ -0,0 +1,19 @@ +// Package module - module/colors.go +package module + +const ( + // Bold format + Bold string = "\033[1m" + // Reset format color code + Reset string = "\033[0m" + // LightPurple color + LightPurple string = "\033[1;35m" + // LightBlue color + LightBlue string = "\033[1;36m" + // Grey color + Grey string = "\033[90m" + // Pink color + Pink string = "\033[38;5;206m" + // Orange color + Orange string = "\033[38;5;208m" +) diff --git a/module/const.go b/module/const.go deleted file mode 100644 index 6384e76..0000000 --- a/module/const.go +++ /dev/null @@ -1,15 +0,0 @@ -// Package module - module/const.go -package module - -const ( - // File icon - File string = "\uf15b" - // Folder icon - Folder string = "\ue5ff" - // Bold ANSI escape code for bold text - Bold string = "\033[1m" - // Reset ANSI escape code - Reset string = "\033[0m" - // LightPurple light purple color - LightPurple = "\033[1;35m" -) diff --git a/module/extension.go b/module/extension.go new file mode 100644 index 0000000..cf45ba1 --- /dev/null +++ b/module/extension.go @@ -0,0 +1,19 @@ +// Package module - module/extension .go +package module + +const ( + // Go extension + Go string = ".go" + // Mod extension + Mod string = ".mod" + // Sum extension + Sum string = ".sum" + // Md Markdown extension + Md string = ".md" + // Gitignore file + Gitignore string = ".gitignore" + // GitFolder folder + GitFolder string = ".git" + // Github folder + Github string = ".github" +) diff --git a/module/icons.go b/module/icons.go new file mode 100644 index 0000000..996a95d --- /dev/null +++ b/module/icons.go @@ -0,0 +1,15 @@ +// Package module - module/icons.go +package module + +const ( + // File icon + File string = "\uf15b" + // Folder icon + Folder string = "\ue5ff" + // GoLang icon + GoLang string = "\ue65e" + // Markdown icon + Markdown string = "\uf48a" + // Git icon + Git string = "\uf1d3" +) diff --git a/service/service.go b/service/service.go index 10945e6..33f83a3 100644 --- a/service/service.go +++ b/service/service.go @@ -20,6 +20,7 @@ const ( // Dispatcher func - executes function based on flags func Dispatcher(options module.Options) { + fmt.Println(".") if options.Flags.ShowTreeView { treeDirectory(options, "", true) } else { diff --git a/service/util.go b/service/util.go index f72c6e7..4de5718 100644 --- a/service/util.go +++ b/service/util.go @@ -6,6 +6,7 @@ import ( "github.com/oussamaM1/treels/module" "log" "os" + "strings" ) // CheckDefaultDirectory func - returns current working directory if no directory is specified @@ -51,10 +52,54 @@ func isHidden(name string) bool { // printWithIconAndPrefix func - prints files and folder with icons and prefix func printWithIconAndPrefix(prefix string, file os.FileInfo) string { var format string + // Directory icon logic if file.IsDir() { - format = fmt.Sprintf("%s%s%s%s %s%s", prefix, module.LightPurple, module.Bold, module.Folder, file.Name(), module.Reset) - } else { + switch { + case strings.HasSuffix(file.Name(), module.Github), strings.HasSuffix(file.Name(), module.GitFolder): + format = printIconFolders(prefix, file, module.GitFolder) + default: + format = printIconFolders(prefix, file, module.Folder) + } + return format + } + + // File icon logic + switch { + case strings.HasSuffix(file.Name(), module.Go), strings.HasSuffix(file.Name(), module.Mod), strings.HasSuffix(file.Name(), module.Sum): + format = printIconFiles(prefix, file, module.Go) + case strings.HasSuffix(file.Name(), module.Md): + format = printIconFiles(prefix, file, module.Md) + case strings.HasSuffix(file.Name(), module.Gitignore): + format = printIconFiles(prefix, file, module.Gitignore) + default: + // Default file icon + format = printIconFiles(prefix, file, module.File) + } + return format +} + +func printIconFiles(prefix string, file os.FileInfo, extension string) string { + var format string + switch extension { + case module.Go, module.Mod, module.Sum: + format = fmt.Sprintf("%s%s%s %s%s", prefix, module.LightBlue, module.GoLang, module.Reset, file.Name()) + case module.Md: + format = fmt.Sprintf("%s%s%s %s%s", prefix, module.Grey, module.Markdown, module.Reset, file.Name()) + case module.Gitignore: + format = fmt.Sprintf("%s%s%s %s%s", prefix, module.Orange, module.Git, module.Reset, file.Name()) + default: format = fmt.Sprintf("%s%s %s", prefix, module.File, file.Name()) } return format } + +func printIconFolders(prefix string, file os.FileInfo, extension string) string { + var format string + switch extension { + case module.Github, module.GitFolder: + format = fmt.Sprintf("%s%s%s%s %s%s", prefix, module.Bold, module.Orange, module.Git, file.Name(), module.Reset) + default: + format = fmt.Sprintf("%s%s%s%s %s%s", prefix, module.Bold, module.Pink, module.Folder, file.Name(), module.Reset) + } + return format +}