develop #24

Merged
Fabel merged 2 commits from develop into main 2025-06-06 19:37:44 +00:00
5 changed files with 98 additions and 50 deletions
Showing only changes of commit cb126028cd - Show all commits

View File

@ -93,20 +93,20 @@ my_project/
```plaintext
Analyzing directory: .\my_project\
data/
└── sample_data.csv
docs/
└── README.md
requirements.txt
setup.py
src/
├── __init__.py
├── main.py
└── utils.py
tests/
├── __init__.py
├── test_main.py
└── test_utils.py
├── data/
└── sample_data.csv
├── docs/
└── README.md
├── requirements.txt
├── setup.py
├── src/
├── __init__.py
├── main.py
└── utils.py
└── tests/
├── __init__.py
├── test_main.py
└── test_utils.py
```
#### Commands

View File

@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "prodir"
version = "1.0.2"
version = "1.1.0"
description = "A module for analyzing and creating directory structures"
scripts = {prodir = "prodir.__main__:main"}
dependencies = []

View File

@ -20,7 +20,7 @@ tree_structurer_module = Extension(
setup(
name='prodir',
version='1.0.2',
version='1.1.0',
description='A module for analyzing directory structures',
ext_modules=[tree_structurer_module],
packages=find_packages(where="src"),

View File

@ -158,20 +158,68 @@ std::vector<std::string> TreeStructurer::get_directory_structure(const std::stri
is_last_per_level.push_back(false);
}
// Determine if this is the last item at its level
bool is_last = (i == paths.size() - 1) ||
(i + 1 < paths.size() &&
fs::relative(paths[i + 1], start).begin()->string() != components[0]);
is_last_per_level[level] = is_last;
// Build the line prefix
std::string line;
for (size_t j = 0; j < level; ++j) {
if (j == level - 1) {
line += is_last ? "└── " : "├── ";
for (size_t j = 0; j <= level; ++j) {
if (j == level) {
// This is the connector for the current item
bool is_last_sibling = true;
// Look ahead to find next sibling at the same level
for (size_t k = i + 1; k < paths.size(); ++k) {
fs::path next_relative = fs::relative(paths[k], start);
std::vector<std::string> next_components;
for (const auto& comp : next_relative) {
next_components.push_back(comp.string());
}
// Check if it's a sibling (same parent, same level)
if (next_components.size() == components.size()) {
bool same_parent = true;
for (size_t l = 0; l < level; ++l) {
if (l >= next_components.size() || components[l] != next_components[l]) {
same_parent = false;
break;
}
}
if (same_parent) {
is_last_sibling = false;
break;
}
}
}
line += is_last_sibling ? "└── " : "├── ";
} else {
line += is_last_per_level[j] ? " " : "";
// This is a vertical line for parent levels
bool needs_vertical_line = false;
// Check if there are future items that share this ancestor
for (size_t k = i + 1; k < paths.size(); ++k) {
fs::path next_relative = fs::relative(paths[k], start);
std::vector<std::string> next_components;
for (const auto& comp : next_relative) {
next_components.push_back(comp.string());
}
// If next item shares the same path up to level j
if (next_components.size() > j) {
bool shares_ancestor = true;
for (size_t l = 0; l <= j; ++l) {
if (l >= next_components.size() || l >= components.size() ||
components[l] != next_components[l]) {
shares_ancestor = false;
break;
}
}
if (shares_ancestor) {
needs_vertical_line = true;
break;
}
}
}
line += needs_vertical_line ? "" : " ";
}
}

View File

@ -138,17 +138,17 @@ project/
# Define expected structure with proper tree markers
expected_structure = [
"LICENSE",
"README.md",
"config/",
"└── config.yaml",
"pyproject.toml",
"setup.py",
"src/",
"├── __init__.py",
"├── main.py",
"├── module1.py",
"└── module2.py"
"├── LICENSE",
"├── README.md",
"├── config/",
" └── config.yaml",
"├── pyproject.toml",
"├── setup.py",
"└── src/",
"├── __init__.py",
"├── main.py",
"├── module1.py",
" └── module2.py"
]
# Get actual structure