Skip to content

Commit

Permalink
add displaying of the users file tree:
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwrossiter committed Dec 5, 2024
1 parent c000320 commit 96b6b81
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmd/mordecai/fileManagement.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/go-git/go-git/v5/plumbing/format/gitignore"
"os"
"path/filepath"
Expand Down Expand Up @@ -94,6 +95,40 @@ func readDir(dirPath string) ([]string, error) {
return files, nil
}

func printFileTree(paths []string) {
// Create styles
dirStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("#36FFFF")). // Changed to cyan color
Bold(true)

fileStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("#FAFAFA"))

treeStyle := lipgloss.NewStyle().
Foreground(lipgloss.Color("#383838"))

tree := make(map[string][]string)

for _, path := range paths {
dir := filepath.Dir(path)
base := filepath.Base(path)
tree[dir] = append(tree[dir], base)
}

// Print the tree with styling
for dir, files := range tree {
fmt.Printf("%s\n", dirStyle.Render("📁 "+dir))

for i, file := range files {
prefix := treeStyle.Render(" ├── ")
if i == len(files)-1 {
prefix = treeStyle.Render(" └── ")
}
fmt.Printf("%s%s\n", prefix, fileStyle.Render(file))
}
}
}

type FileContent struct {
FilePath string `json:"file_path"`
FileExtension string `json:"file_extension"`
Expand Down
3 changes: 3 additions & 0 deletions cmd/mordecai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ func linkCommand() {
fmt.Printf("\033[1;32m✓ Syncing local repository \033[1;36m%s\033[1;32m to remote space \033[1;36m%s\033[0m\n", repoName, workspaceName)
fmt.Println("\033[1;33m⚠ ALERT: Please leave this open while programming\033[0m")

fmt.Println("\n\033[1;32m✓ The files listed below are being synced")

printFileTree(dir)
// Add a watcher to the directory
err = watchDirectory(currentDir, workspaceId, repoName, repoId, token)
if err != nil {
Expand Down

0 comments on commit 96b6b81

Please sign in to comment.