Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Added icons implementation #25

Merged
merged 1 commit into from
Apr 7, 2024
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
19 changes: 19 additions & 0 deletions module/colors.go
Original file line number Diff line number Diff line change
@@ -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"
)
15 changes: 0 additions & 15 deletions module/const.go

This file was deleted.

19 changes: 19 additions & 0 deletions module/extension.go
Original file line number Diff line number Diff line change
@@ -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"
)
15 changes: 15 additions & 0 deletions module/icons.go
Original file line number Diff line number Diff line change
@@ -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"
)
1 change: 1 addition & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
49 changes: 47 additions & 2 deletions service/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/oussamaM1/treels/module"
"log"
"os"
"strings"
)

// CheckDefaultDirectory func - returns current working directory if no directory is specified
Expand Down Expand Up @@ -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
}
Loading